From bf4cd8d028bb28d0971cc4b5396cc0af56890f6d Mon Sep 17 00:00:00 2001 From: raiots Date: Fri, 2 Jun 2023 21:01:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20tesseract=20=E5=8D=95=E5=AD=97=E6=AF=8D?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ocr.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ocr.py b/ocr.py index 857f6f2..6491aee 100644 --- a/ocr.py +++ b/ocr.py @@ -4,7 +4,7 @@ import numpy as np from pytesseract import Output # img_source = cv2.VideoCapture(0) -img_source = cv2.imread('./coffee-ocr.jpg') +img_source = cv2.imread('./img.png') def get_grayscale(image): @@ -51,4 +51,16 @@ def test_performance(): cv2.imshow('img', img) cv2.waitKey(0) -print(pytesseract.image_to_data(img_source, output_type=Output.DICT)['text']) \ No newline at end of file +# print(pytesseract.image_to_data(img_source, output_type=Output.DICT)['text']) + +def identy_char(img_path): + source_img = cv2.imread(img_path) + d = pytesseract.image_to_data(source_img, output_type=Output.DICT, config='--psm 10') + + for text in d['text']: + # print(text) + if len(text) == 1 and text.isalpha(): + print(text) + +if __name__ == "__main__": + identy_char('./img.png') \ No newline at end of file