即使 arg 类型是它应该是的,OpenCV 折线也会抛出断言失败
OpenCV polylines throws assertion failure even when arg type is what it's supposed to be
几个线程报告了这个问题,但它们都显示修复点列表的类型(到int32,即CV_32S)作为解决方案。下面的点列表具有适当的类型。
>>> ti = np.zeros((400,400,3), np.uint8) # Test image
>>> mask = np.array([[213,60],[333,240],[93,240],[150,120]], np.int32) # Test point list
>>> cv2.polylines(ti, mask, True, (255,0,0), 1)
*** cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2437: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'cv::polylines'
>>> print(mask.dtype, mask.shape)
int32 (4, 2)
我试过更改类型(我得到一个不同的错误,抱怨它是错误的类型)并将其重新转换为 int32。不能让它很好玩...
fillConvexPoly 工作正常(这让我得到了我现在需要的东西),fillPoly 表现出与上述相同的问题。
以上更正为 -
cv2.polylines(ti, [mask], True, (255,0,0), 1)
几个线程报告了这个问题,但它们都显示修复点列表的类型(到int32,即CV_32S)作为解决方案。下面的点列表具有适当的类型。
>>> ti = np.zeros((400,400,3), np.uint8) # Test image
>>> mask = np.array([[213,60],[333,240],[93,240],[150,120]], np.int32) # Test point list
>>> cv2.polylines(ti, mask, True, (255,0,0), 1)
*** cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\drawing.cpp:2437: error: (-215:Assertion failed) p.checkVector(2, CV_32S) >= 0 in function 'cv::polylines'
>>> print(mask.dtype, mask.shape)
int32 (4, 2)
我试过更改类型(我得到一个不同的错误,抱怨它是错误的类型)并将其重新转换为 int32。不能让它很好玩...
fillConvexPoly 工作正常(这让我得到了我现在需要的东西),fillPoly 表现出与上述相同的问题。
以上更正为 -
cv2.polylines(ti, [mask], True, (255,0,0), 1)