简体   繁体   中英

Using Tesseract to recognize time from an image

I want to read the time from the image below using Tesseract. My code is:

text = pytesseract.image_to_string('test.png')
print(text)

The image is as below: 在此处输入图像描述

But for some reason, this program doesn't work, and the text is always a space. Does anyone know how to solve this problem?

Use the flag config="--psm 6" and it should work. This specifies that you have a single uniform block of text. 7 also work which is for a single line of uniform text.

print(pytesseract.image_to_string('test.png', config="--psm 6"))

# prints "06-04-2021 11:27:17\n\x0c"

See this other post for another example https://stackoverflow.com/a/66179528/15271127

EDIT: Also see this website if you want more options https://muthu.co/all-tesseract-ocr-options/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM