python - 七个小节数字识别-计算机视觉

标签 python opencv computer-vision image-recognition python-tesseract

我试图识别下图底部左上角代表时间的数字。
enter image description here
具体来说,这是我需要识别的图像:
enter image description here
数字采用七格格式。
我正在使用opencv和tesseract,但是我使用的任何过滤器都无法获得良好的结果。
这是开发的代码(我假设已经确定了数字所在的部分,所以这是我的起点):

image = cv2.imread("C:\example2.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 50, 200, 255)

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

text = pytesseract.image_to_string(edged)
尝试过使用另一组滤镜,但没有一个滤镜能给我接近图像的结果。
提前致谢。

最佳答案

Tesseract喜欢在白色背景上的黑色文本。另外,它喜欢characters to be a minimum height
我通过cv2.THRESH_OTSU进行Otsu thresholdingcv2.THRESH_BINARY_INV来反转图像(将黑变白,白变黑)。以原始大小,“9”被识别为“q”。我将尺寸调整为2,识别度更好。

import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

img = cv2.imread('example2.jpg', cv2.IMREAD_GRAYSCALE)  

thresh = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)[1]
thresh = cv2.resize(thresh, (0,0), fx=2, fy=2)  # scale image 2X

detected_text = pytesseract.image_to_string(thresh, config = '--psm 6')
print(detected_text)
这使
9:47

关于python - 七个小节数字识别-计算机视觉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63529678/

相关文章:

python - 在这种情况下,if 代码块如何从 while 循环中断的位置继续执行?

python - 在 scipy 优化中限制/最小化步长?

python - 从我的Python代码返回Opencv Mat类型

python-3.x - 导入错误 : No module named 'onnx_backend' ?

python - Tesseract OCR 无法检测数字

python - 沿其中一个轴应用 numpy 'where'

c++ - 如何在 iOS 上使用 caffemodel 和 OpenCV?

c++ - 彩色图像的边缘检测CannyAlgorithm

opencv - 深度 CNN 不会学习,准确率只是保持在相同值

python - 查找 Python 列表中的显着变化