0

hello guys i'm working on my project with easy ocr for text detection i got some errors, but i don't know how to fix it, it will be greatful if someone can help me?

here's few errors i get

cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'rectangle'

Overload resolution failed:

  • Can't parse 'pt1'. Sequence item with index 0 has a wrong type
  • Can't parse 'pt1'. Sequence item with index 0 has a wrong type
  • Can't parse 'rec'. Expected sequence length 4, got 2
  • Can't parse 'rec'. Expected sequence length 4, got 2

anyway this is my code

import cv2
import numpy as np
from matplotlib import pyplot as plt
import easyocr


cap = cv2.VideoCapture(0)
reader = easyocr.Reader(['en'], gpu = True)

while True :
    _, frame = cap.read()
    result = reader.readtext(frame)
    for detection in result:
        top_left = tuple(detection[0][0])
        bottom_right = tuple(detection[0][2])
        text = detection[1]
        print (text)
        img = cv2.rectangle(frame,top_left,bottom_right,(0,255,0),2)
    cv2.imshow("Text Recognition", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
Markus
  • 5,976
  • 5
  • 6
  • 21

1 Answers1

0

cv2.rectangle expects int values, while easyocr can return floats. Try:

        top_left = (int(detection[0][0][0]), int(detection[0][0][1]))
        bottom_right = (int(detection[0][2][0]), int(detection[0][2][1]))
Markus
  • 5,976
  • 5
  • 6
  • 21