Skip to content

numpy_array.reshape(1,-1,2) is often needed in Python #18413

@vpisarev

Description

@vpisarev
System information (version)
  • OpenCV => 4.x
  • Operating System / Platform => any
  • Compiler => Python 2.x/3.x
Detailed description

When OpenCV functions that processes point a sequence/point cloud is called from Python, it fails to process it because of unsupported shape of array. And so it needs reshape to pass through. If the output of point cloud processing functions is also a point cloud, it also needs to be reshaped in a similar way.

Steps to reproduce
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))

...
pts = ...
rpts = pts.reshape((1,-1,2))
xfm_pts = cv2.perspectiveTransform(rpts,H).reshape((-1,2))
References

https://stackoverflow.com/questions/51723910/at-what-situation-points-need-to-be-reshaped-like-reshape-1-1-2-in-python-open/51724120

reported by @garybradski

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions