Home > OS >  schroedinger tuple, is a tuple and not a tuple
schroedinger tuple, is a tuple and not a tuple

Time:10-09

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

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:

  • pts is not a numerical tuple
  • Expected Ptr<cv::UMat> for argument 'pts'

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.

What is the way to create a "numerical tuple" valid for cv.polylines()?

CodePudding user response:

As @Nathaniel Ford said the points needs to be a numpy array

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.

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