用于Tesseract OCR的带有眩光的OpenCV预处理图像

时间:2019-09-06 14:51:38

标签: python opencv image-processing ocr tesseract

我正在尝试使用OpenCV和Tesseract从所附图像中读取数字。

Altimeter Data

由于显示屏上的眩光变化,这是一个挑战。我已经尝试过对图像进行多次操作,但是仍然没有找到最佳解决方案。各种尝试的代码都很草率,但我最近的尝试涉及到了

imggray = cv2.imread('image.png',0) #Loads grayscale
imgcolor = cv2.imread('image.png',1) #Loads color 

altimgcrop = imgcolor

hsv = cv2.cvtColor(altimgcrop,cv2.COLOR_BGR2HSV)

#multiply by factors to change the saturation/brightness

hsv[...,1] = hsv[...,1]*10
hsv[...,2] = hsv[...,2]*0.6

#HSV = hue sat value

lower_yellow = np.array([20,0,0])
upper_yellow = np.array([100,255,255])

mask = cv2.inRange(hsv, lower_yellow, upper_yellow)
output = cv2.bitwise_and(altimgcrop, altimgcrop, mask = mask)

threshAlt = output

#Found resizing would sometimes provide better OCR results

img4 = cv2.resize(threshAlt, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)

#----------------------------------------------------------#
#The following passes the image into OCR and returns text

alttext = pytesseract.image_to_string(img4, lang = 'eng', config='digits')
print(alttext)

任何帮助,将不胜感激。

0 个答案:

没有答案