"integer argument expected got float"while 运行 in raspberry pi.what 可以解决吗?
"integer argument expected got float"while running in raspberry pi.what can be the solution?
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)
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)