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