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

在使用opencv画矩形框的时候下面的这行出现了错误:

 cv2.rectangle(img, (22.0, 3.0),(33.0, 45.0), translate_color(classes[k]), 3, 1)

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

Overload resolution failed:
Can’t parse ‘pt1’. Expected sequence length 2, got 4
Can’t parse ‘pt1’. Expected sequence length 2, got 4
Can’t parse ‘rec’. Sequence item with index 0 has a wrong type
Can’t parse ‘rec’. Sequence item with index 0 has a wrong type

原因分析:

输入到cv2.rectangle()这个函数中两个的坐标:(22.0,3.0)和(33.0,45.0)不能是浮点数的类型,要转换成整数才行,于是就使用int()强制类型转换,之后代码成功运行。

猜你喜欢

转载自blog.csdn.net/qq_39237205/article/details/124201569