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”时出错
我猜每个
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)
相关问题 更多 >
编程相关推荐