Any ways to further improve OCR results

239 views
Skip to first unread message

Lee Kar Yee

unread,
Jun 27, 2023, 6:01:13 AM6/27/23
to tesseract-ocr
Hi all,

I am new to Tesseract OCR. I am trying to achieve extracting alphabets and numbers from images.
These images are being converted from a mp4 video into frames as JPG.

While using Page segmentation method 3, it is working wonders on extracting alphabets, but it failed to extract numbers.

I have tried setting the Region of Interest (ROI) but yet it still failed.

Any thoughts or direction that can point me to so that I can improve it?

Thanks,

Lee

Zdenko Podobny

unread,
Jun 27, 2023, 6:25:50 AM6/27/23
to tesser...@googlegroups.com
without an example image nobody can help you.

Zdenko


ut 27. 6. 2023 o 12:01 Lee Kar Yee <leeka...@gmail.com> napísal(a):
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/67b453f2-7781-44a5-be05-05676d3ee5fan%40googlegroups.com.

Lee Kar Yee

unread,
Jun 27, 2023, 10:26:17 PM6/27/23
to tesseract-ocr
Hi, 

Apologies. Kindly refer to the following.

With the following code, I managed to draw rectangle on the region that are processed by Tesseract OCR.

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

video = r"C:\Users\User\Downloads\FATHER\test.mp4"
cap = cv2.VideoCapture(video)
frame_count = 0

while cap.isOpened() and frame_count < 2:
    ret, frame = cap.read()

    if not ret:
        break

    # Perform OCR on the entire frame without dictionaries
    text = pytesseract.image_to_string(frame, config='--psm 1 -l eng --oem 1')

    print(text)

    # Get the bounding box coordinates of the detected text regions
    boxes = pytesseract.image_to_boxes(frame, config='--psm 1 -l eng --oem 1')

    # Draw bounding box rectangles on the frame
    for box in boxes.splitlines():
        _, x, y, w, h, _ = box.split(' ')
        x, y, w, h = int(x), int(y), int(w), int(h)
        # Draw rectangles on the frame
        cv2.rectangle(frame, (x, y), (w, h), (0, 0, 255), 1)

    # Save the frame as an image
    cv2.imwrite(f"frame_{frame_count}.jpg", frame)

    frame_count += 1

cap.release()
cv2.destroyAllWindows()

And the results are as below.

ntes F-Farm Annlicatinns Service Reiest 9 Oar

individual Name IDK

GOH SCE YUAN 600


nten  F-Farm Annlicatinns Service Request «9 [or

Individual Name IDK

GOH SCE YUAN 600

Kindly refer to the objective.jpg for what I actually intend to capture.

Thanks,

Lee
frame_1.jpg
frame_0.jpg
objective.jpg

Harsha Perera

unread,
Jun 28, 2023, 10:48:08 AM6/28/23
to tesser...@googlegroups.com

Zdenko Podobny

unread,
Jul 8, 2023, 11:54:17 AM7/8/23
to tesser...@googlegroups.com
I am not sure what you mean by "I have tried setting the Region of Interest (ROI) ", but when I cut region and pre-processed it as described in the documentation I got the correct results:

tesseract frame_1-ROI1_preprocessed.png - --psm 7
GOH SCE YUAN

tesseract frame_1-ROI2_preprocessed.png - --psm 4
0197782267
073351668
0197732267


Zdenko


st 28. 6. 2023 o 4:26 Lee Kar Yee <leeka...@gmail.com> napísal(a):
frame_1-ROI1_preprocessed.png
frame_1-ROI2_preprocessed.png

Lee Kar Yee

unread,
Jul 9, 2023, 6:31:38 AM7/9/23
to tesseract-ocr
Hi Zdenko,

May I know how do you cut region and pre-processed it?

Much appreciate if you could guide me on this.

Thanks,

Lee

Reply all
Reply to author
Forward
0 new messages