薛定谔元组,是一个元组而不是一个元组
schroedinger tuple, is a tuple and not a tuple
我有一个使用单个数值构建的元组元组
maxcontour = ( (minx,miny),(maxx,miny),(maxx,maxy),(minx,maxy) )
并且确实是一个元组
print (maxcontour)
((374, 0), (2553, 0), (2553, 3999), (374, 3999))
但是在需要元组的地方使用它时
cv2.polylines(img, maxcontour, True, (0,0,255), 5 )
我收到这个错误
error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'polylines'
Overload resolution failed:
- pts is not a numerical tuple
- Expected Ptr<cv::UMat> for argument 'pts'
我显然忽略了一些非常基本的东西,但我看不到什么;并且错误消息 "Expected Ptrcv::UMat for argument 'pts'" 没有太大帮助。
创建对 cv.polylines()
有效的“数值元组”的方法是什么?
正如@Nathaniel Ford 所说,这些点需要是一个 numpy 数组
To draw a polygon, first you need coordinates of vertices. Make those
points into an array of shape ROWSx1x2 where ROWS are number of
vertices and it should be of type int32.
所以
maxcontour = np.array( [[minx,miny],[maxx,miny],[maxx,maxy],[minx,maxy]],np.int32)
maxcontour = maxcontour.reshape((-1,1,2))
cv2.polylines(img, [maxcontour], True, (0,0,255))
我有一个使用单个数值构建的元组元组
maxcontour = ( (minx,miny),(maxx,miny),(maxx,maxy),(minx,maxy) )
并且确实是一个元组
print (maxcontour)
((374, 0), (2553, 0), (2553, 3999), (374, 3999))
但是在需要元组的地方使用它时
cv2.polylines(img, maxcontour, True, (0,0,255), 5 )
我收到这个错误
error: OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function 'polylines' Overload resolution failed:
- pts is not a numerical tuple
- Expected Ptr<cv::UMat> for argument 'pts'
我显然忽略了一些非常基本的东西,但我看不到什么;并且错误消息 "Expected Ptrcv::UMat for argument 'pts'" 没有太大帮助。
创建对 cv.polylines()
有效的“数值元组”的方法是什么?
正如@Nathaniel Ford 所说,这些点需要是一个 numpy 数组
To draw a polygon, first you need coordinates of vertices. Make those points into an array of shape ROWSx1x2 where ROWS are number of vertices and it should be of type int32.
所以
maxcontour = np.array( [[minx,miny],[maxx,miny],[maxx,maxy],[minx,maxy]],np.int32)
maxcontour = maxcontour.reshape((-1,1,2))
cv2.polylines(img, [maxcontour], True, (0,0,255))