难以阅读pytesseract的文字

问题描述 投票:0回答:1

我需要您的帮助。

我需要读取热像图上的最高温度,如下所示:

IR_1544_INFRA.jpg

IR_1546_INFRA.jpg

IR_1560_INFRA.jpg

IR_1564_INFRA.jpg

我使用了以下代码,这是我能做到的最好的。我还尝试了其他几种方法,例如:模糊,灰度,二值化等,但是它们都失败了。

import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Users\User\AppData\Local\Tesseract-OCR\tesseract.exe"

# Load image, grayscale, Otsu's threshold
entrada = cv2.imread('IR_1546_INFRA.jpg')

image = entrada[40:65, 277:319]

#image = cv2.imread('IR_1546_INFRA.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = 255 - cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Blur and perform text extraction
thresh = cv2.GaussianBlur(thresh, (3,3), 0)
data = pytesseract.image_to_string(thresh, lang='eng', config='--psm 6')
print(data)

cv2.imshow('thresh', thresh)
cv2.waitKey()

在第一张图片中,我发现this

在第二张图片中,我找到了this

imagem布局始终相同,也就是说,温度始终在同一位置,因此我裁剪了图像,只隔离了我想要的数字(97.7 here和85.2 here)。

我的代码需要了解所有这些图像,以便始终检测该温度并生成一个从最高到最低的列表。

在这些图像的情况下,您对我来说是什么要改善pytesseract的自信?

注1:当我分析整个图像(不进行裁剪)时,它返回的数据甚至不存在。

注2:在某些具有二进制数的图像中,pytesseract(image_to_string)不返回任何数据。

谢谢大家,对错字感到抱歉,用英语写对我来说仍然是个挑战。

python-3.x text ocr python-tesseract string-decoding
1个回答
0
投票
import cv2 import pytesseract import os image_path = "temperature" for nama_file in sorted(os.listdir(image_path)): print(nama_file) img = cv2.imread(os.path.join(image_path, nama_file)) crop = img[43:62, 278:319] gray = cv2.cvtColor(crop, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY)[1] thresh = cv2.bitwise_not(thresh) double = cv2.resize(thresh, None, fx=2, fy=2) custom_config = r'-l eng --oem 3 --psm 7 -c tessedit_char_whitelist="1234567890." ' text = pytesseract.image_to_string(double, config=custom_config) print("detected: " + text) cv2.imshow("img", img) cv2.imshow("double", double) cv2.waitKey(0) cv2.destroyAllWindows()
© www.soinside.com 2019 - 2024. All rights reserved.