几天前我开始了一个ocr项目。输入图像是一个带有白色字母的真正有噪声的灰色图像。使用EAST文本检测器,可以识别文本并在其周围绘制边框。 之后,我裁剪矩形并进行一些图像处理。之后,我将处理过的部分传递给pytesseract,但结果不好。图片和源视频点播如下。也许有些人对更好的图像处理和/或pytesseract设置有好主意
图像
Input image
Rectangles after Recognition
First part
Second part
Third part
teseract结果 AY U N74 O54
图像处理源代码
kernel = cv2.getStructuringElement(cv2.MORPH_RECT , (8,8))
kernel2 = np.ones((3,3),np.uint8)
kernel3 = np.ones((5,5),np.uint8)
gray = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
gray = cv2.resize(gray, None, fx=7, fy=7)
gray = cv2.GaussianBlur(gray, (5,5), 1)
#cv2.medianBlur(gray, 5)
gray = cv2.dilate(gray, kernel3, iterations = 1)
gray = cv2.erode(gray, kernel3, iterations = 1)
gray = cv2.morphologyEx(gray, cv2.MORPH_DILATE, kernel3)
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
gray = cv2.bitwise_not(gray)
ts_img = Image.fromarray(gray)
txt = pytesseract.image_to_string(ts_img, config='--oem 3 --psm 12 -c tessedit_char_whitelist=12345678ABCDEFGHIJKLMNOPQRSTUVWXYZ load_system_dawg=false load_freq_dawg=false')
我尝试了一些其他psm设置,如psm 11、psm 8和ps6。结果不同,但也很糟糕。 我想最大的问题是与字母和数字相关的黑点,但我不知道如何去除它们。 我感谢你的帮助:)
OCR软件在将文本解释为单词或句子时会表现不佳,因为它需要的是真正的英语单词,而不是字符的随机组合。我建议将文本作为单个字符进行分析。我首先根据组的大小和位置确定哪些标记像素组(阈值图像的连接组件)是字符,从而解决了(示例)问题。然后,对于包含(单个)字符的每个图像部分,我使用
easyocr
来获得字符。我发现pytesseract
在单个字符上的性能很差或根本没有(即使在设置psm 10
和其他参数时也是如此)。下面的代码生成此结果:OCR out: 6UAE005X0721295
相关问题 更多 >
编程相关推荐