[英]Performing OCR of Seven Segment Display images
我嘗試將 tesseract-ocr 與letsgodigital訓練數據一起使用。 但是性能很差。
我對這個話題相當陌生,這就是我所做的:
import numpy as np
import cv2
import imutils
from skimage import exposure
from pytesseract import image_to_string
import PIL
def process_image(orig_image_arr):
gry_disp_arr = cv2.cvtColor(orig_image_arr, cv2.COLOR_BGR2GRAY)
gry_disp_arr = exposure.rescale_intensity(gry_disp_arr, out_range= (0,255))
#thresholding
ret, thresh = cv2.threshold(gry_disp_arr,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
return thresh
def ocr_image(orig_image_arr):
otsu_thresh_image = process_image(orig_image_arr)
cv2_imshow(otsu_thresh_image)
return image_to_string(otsu_thresh_image, lang="letsgodigital", config="--psm 8 -c tessedit_char_whitelist=.0123456789")
img1 = cv2.imread('test2.jpg')
cnv = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
text = ocr_image(cnv)
這給示例圖像帶來了非常糟糕的結果。 我有一些問題:
如何識別顯示屏的四個角? (邊緣檢測似乎不太好用)
我可以做任何進一步的預處理來提高性能嗎?
謝謝你的幫助。
注意您的功率計如何使用藍色或綠色 LED 來點亮顯示屏; 我建議您使用這種彩色顯示器來發揮自己的優勢。 我要做的是 select 只有一個基於 LED 顏色的 RGB 通道。 然后我可以根據某種算法或假設對其進行閾值處理。 之后,您可以進行裁剪/調整大小/轉換/OCR等下游步驟。
例如,使用您的示例圖像 1 ,在此處查看其直方圖。 注意在 150 標記的右側有一個小的綠色峰值。
我利用了這一點,並將低於 150 的任何值設置為零。 我的假設是綠色峰值是圖像中的亮綠色 LED。
img = cv2.imread('example_1.jpg', 1)
# Get only green channel
img_g = img[:,:,1]
# Set threshold for green value, anything less than 150 becomes zero
img_g[img_g < 150] = 0
這就是我得到的。 這對於下游 OCR 現在應該容易得多。
# You should also set anything >= 150 to max value as well, but I didn't in this example
img_g[img_g >= 150] = 255
以上步驟應替換此步驟
_ret, thresh = cv2.threshold(img_g, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.