Issue
I've been trying to use pytesseract for a project I've had in the works for quite a while. So far I've just been trying to make sure that it works well on my computer, but I've had no luck with getting it to work.
I've been trying to test it out on this image, using the following code:
image = cv2.imread('exit.png',cv2.IMREAD_GRAYSCALE)
th,image = cv2.threshold(image,0,255,cv2.THRESH_OTSU)
image = 255 - image
cv2.imshow('bruh',image)
cv2.waitKey(0)
print(pytesseract.image_to_data(image,config='--psm 3 --oem 3'))
The point of this code is to simply test if pytesseract is working by reading the image, binarizing it, and then flipping the black and white values because I read somewhere that tesseract works better with black text. The processed image looks like this.
I've tried running the image through with and without binarization, I've tried reinstalling both tesseract and pytesseract, I've tried different configs, I've tried to run tesseract over the image through the command line, but at this point I honestly have no clue what's going on.
I'm on Pop!_OS using Python version 3.10.4.
Solution
For your case, I had tried the OCR with easy ocr which also using tesseract engine to extract text.I get the proper result. You can install easyocr by pip install easyocr
.
import cv2
import easyocr
image = cv2.imread('exit.png')
resize = cv2.resize(image,(100,40))
cv2.imwrite('resize.png', resize)
reader = easyocr.Reader(['en'], gpu=False)
result = reader.readtext('resize.png')
for detection in result:
print(detection)
the output is
([[5, 0], [93, 0], [93, 40], [5, 40]], 'EXIT', 0.8129605341987216)
I hope this might help you.
Answered By - Berlin Benilo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.