错误代码:OpenCV(4.5.2):-1:错误:(-5:参数错误)在函式'rectangle'中

hm2xizp9  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(555)

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) emoji people:-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()
svmlkihl

svmlkihl1#

cv2.rectangle需要int值,而easyocr可以返回浮点数。请尝试:

top_left = (int(detection[0][0][0]), int(detection[0][0][1]))
        bottom_right = (int(detection[0][2][0]), int(detection[0][2][1]))

相关问题