在raspberry中运行时,应为“integer argument get float”皮。什么可以解决吗?

2024-05-23 19:52:02 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当我在raspberry pi中运行这个“integer argument expected got float”时出错


Tags: ofgetdeflineredcv2scalarvertices
1条回答
网友
1楼 · 发布于 2024-05-23 19:52:02

我猜每个p2fRectPoints都包含float而不是int类型。
试试这个:
def drawRedRectangleAroundPlate(imgOriginalScene, licPlate): # get 4 vertices of rotated rect p2fRectPoints = cv2.boxPoints(licPlate.rrLocationOfPlateInScene) # convert float arrays to int tuples for use with cv2.line() p0 = (int(p2fRectPoints[0][0]), int(p2fRectPoints[0][1])) p1 = (int(p2fRectPoints[1][0]), int(p2fRectPoints[1][1])) p2 = (int(p2fRectPoints[2][0]), int(p2fRectPoints[2][1])) p3 = (int(p2fRectPoints[3][0]), int(p2fRectPoints[3][1])) # draw 4 red lines cv2.line(imgOriginalScene, p0, p1, SCALAR_RED, 2) cv2.line(imgOriginalScene, p1, p2, SCALAR_RED, 2) cv2.line(imgOriginalScene, p2, p3, SCALAR_RED, 2) cv2.line(imgOriginalScene, p3, p0, SCALAR_RED, 2)

相关问题 更多 >