# At what situation points need to be reshaped like reshape(-1,1,2) in python-opencv?

I'm a newer to python-opencv, so I read this tutorial and found some sample codes like this:

pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
pts = pts.reshape((-1,1,2))
cv2.polylines(img,[pts],True,(0,255,255))


it's about to show you how to draw polygons using cv2.polylines function, most of them are easy to understand, which I'm curious about is :

pts = pts.reshape((-1,1,2)) #I understand this makes pts.shape to be (4,1,2)


I try to remove this code and find that didn't make any difference, it works fine, either. before this reshape operation, pts's shape is (4,2), which is intuitive enough for me. Besides, when I write codes like this:

convex_pts = cv2.convexHull(pts) #get a convexhull from pts，pts's shape is(4,2)
print(convex_pts)       #[[[72,20]],[[20,30]],[[10,5]],[[50,10]]]
print(convex_pts.shape) #(4,1,2)


it seems to me that python-opencv insists to "unsqueeze" it and make it has shape like(x,1,2), that's weird to me cause when the shape is (x,2) it just works fine in the tutorial case .Any reason why is this necessary ? I searched around and found nothing helpful, am I missing something? So I want to know why and at what situation points need to be reshaped like this?

edit retag close merge delete