簡體   English   中英

pytesseract 7seg 檢測的圖像增強

[英]Image enhancement for pytesseract 7seg detection

我正在開發一個系統來預測來自 7Seg LCD 的數字,我正在使用 tesseract OCR 引擎,它是 python pytesseract 的包裝器。

我正在用相機拍照,然后裁剪感興趣的區域,我發現我必須提高我的圖像質量以提高 OCR 引擎的准確性。

我使用了一些圖像處理技術(灰度 --> 高斯模糊 --> 閾值),我得到了一張安靜的好圖像,但 tesseract 仍然無法檢測到圖像中的數字。

我使用代碼:

image = cv2.imread('test.jpg')
image = image[50:200, 300:540]

image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.GaussianBlur(image, (3,3), 0)

_, image = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

cv2.imshow('result', image)

cv2.waitKey()
cv2.destroyAllWindows()

cv2.imwrite('enhanced.jpg', image)

tess_dir_config = r'--tessdata-dir "C:\Program Files\Tesseract-OCR\tessdata"'
text = image_to_string(image, lang='letsgodigital', config=tess_dir_config)
print(text)

Output 圖像:

1

輸入圖像:

2

引擎通常有一個空的 output,如果沒有,它將無法正確檢測到數字。

是否可以使用某種其他圖像處理來發揮引擎的潛力。

注意:我正在使用letsgodigital權重

這對我有用,如果我稍微改進一下裁剪,並使用頁面分割模式 7。(此模式不進行頁面分割並假設單行文本。)

import cv2
import matplotlib.pyplot as plt
import pytesseract

image = cv2.imread('seven_seg_disp.jpg')
# Strip off top of meter and little percent symbol.
image = image[90:200, 300:520]
# plt.imshow(image)

image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = cv2.GaussianBlur(image, (3,3), 0)

_, image = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
# plt.imshow(image)

tess_dir_config = r'--tessdata-dir "../.tesseract" --psm 7'
text = pytesseract.image_to_string(image, lang='letsgodigital', config=tess_dir_config)
text = text.strip()
print(text)  # prints 75

注意:我更改了 tessdata-dir 的值,因為它在我的計算機上的不同位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM