opencv python中的元组植入

tpgth1q7  于 2023-02-09  发布在  Python
关注(0)|答案(1)|浏览(166)

我有这个代码的代码,我为文本检测

def drawRedRectangleAroundPlate(imgOriginalScene, licPlate):
    p2fRectPoints = cv2.boxPoints(licPlate.rrLocationOfPlateInScene)            # get 4 vertices of rotated rect

    cv2.line(imgOriginalScene, tuple(p2fRectPoints[0]), tuple(p2fRectPoints[1]), SCALAR_RED, 2)         # draw 4 red lines
    cv2.line(imgOriginalScene, tuple(p2fRectPoints[1]), tuple(p2fRectPoints[2]), SCALAR_RED, 2)
    cv2.line(imgOriginalScene, tuple(p2fRectPoints[2]), tuple(p2fRectPoints[3]), SCALAR_RED, 2)
    cv2.line(imgOriginalScene, tuple(p2fRectPoints[3]), tuple(p2fRectPoints[0]), SCALAR_RED, 2)
# end function

我遇到了一个我不明白的回溯问题

cv2.line(imgOriginalScene, tuple(p2fRectPoints[0]), tuple(p2fRectPoints[1]), SCALAR_RED, 2)         # draw 4 red lines
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'line'
> 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
ih99xse1

ih99xse11#

你写道:

cv2.line(imgOriginalScene, tuple(p2fRectPoints[0]), tuple(p2fRectPoints[1]), SCALAR_RED, 2)

文档解释了.line()接受

void cv::line   (   InputOutputArray    img,
        Point   pt1,
        Point   pt2,
        const Scalar &      color, 
        ... )

p2fRectPoints有四个点,每个点都有(x,y)坐标,所以不用tuple(x, y)来构造两个整数的点,你可以直接传入p2fRectPoints[0],不需要调用tuple,你可以检查type(p2fRectPoints[0]),它应该是Point(或tuple)。

相关问题