我正在尝试开发一个阅读表检测系统,这是图片
我需要得到 Jmeter 阅读27599作为输出。我使用了以下代码:
import pytesseract
import cv2
image = cv2.imread('read2.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(H, W) = gray.shape
rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT, (20, 7))
gray = cv2.GaussianBlur(gray, (1, 3), 0)
blackhat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, rectKernel)
res = cv2.threshold(blackhat, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
pytesseract.image_to_string(res, config='--psm 12 --oem 3 digits')
我得到这个输出:
'.\n\n-\n\n3\n\n7\n\n7\n\n3\n\n-2105 566.261586\n\n161200\n\n310010\n\n--\n\n.-\n\n.\n\n5\n\x0c'
这是我的第一个光学字符识别项目。任何帮助将不胜感激。
1条答案
按热度按时间4nkexdtk1#
在我们开始阅读实际的电表号码之前,有很多文本可以删除。另一方面,我们可以将OCR限制为只读取数字,以防止误报(因为一些7段数字就像字母表中的字母)。
由于tesseract在7段数字上工作得不够好。我将使用EasyOCR。
因此,程序应该是这样的:
1.实际计数器周围有很大的空间可以裁剪。
1.我们模糊图像并运行霍夫变换以得到圆形米。
1.我们肯定知道该数字位于该圆的上半部分,因此我们再次根据检测到的圆的中心和半径进行裁剪。
1.裁剪后的图像然后可以输入EasyOCR,正如我之前所说,仅限于英语和数字。
检测数量:27599