简体   繁体   English

薛定谔元组,是一个元组而不是一个元组

[英]schroedinger tuple, is a tuple and not a tuple

I have a tuple of tuples built using individual numerical values我有一个使用单个数值构建的元组元组

 maxcontour = ( (minx,miny),(maxx,miny),(maxx,maxy),(minx,maxy) )

and is indeed a tuple确实是一个元组

 print (maxcontour)

((374, 0), (2553, 0), (2553, 3999), (374, 3999)) ((374, 0), (2553, 0), (2553, 3999), (374, 3999))

but when using it where a tuple is expected但是在需要元组的地方使用它时

  cv2.polylines(img, maxcontour, True, (0,0,255), 5 )

I get this error我收到这个错误

error: OpenCV(4.5.3):-1: error: (-5:Bad argument) in function 'polylines' Overload resolution failed:错误:OpenCV(4.5.3):-1: 错误: (-5:Bad argument) in function 'polylines' 过载解析失败:

  • pts is not a numerical tuple pts 不是数字元组
  • Expected Ptr<cv::UMat> for argument 'pts'参数“pts”的预期 Ptr<cv::UMat>

I am obviously overlooking something very basic, but I can't see what;我显然忽略了一些非常基本的东西,但我看不到什么; and the error message "Expected Ptrcv::UMat for argument 'pts'" is of no great help.并且错误消息“Expected Ptrcv::UMat for argument 'pts'”没有太大帮助。

What is the way to create a "numerical tuple" valid for cv.polylines() ?创建对cv.polylines()有效的“数字元组”的方法是什么?

As @Nathaniel Ford said the points needs to be a numpy array正如@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.将这些点放入形状为 ROWSx1x2 的数组中,其中 ROWS 是顶点数,它应该是 int32 类型。

So所以

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM