简体   繁体   中英

How do I make perspective transform of point with x and y coordinate

So I wrote this little program which allows me to select 4 points on two images.

Usign those points I get a transformation matrix. After that I select a point on one of the images and want to get visualization of where that point will be on other image.

Say my point is marked like this -> (x,y) - so it's a tuple. How should I format this "position" on image so it can be possible to transform it.

I have looked at documentation for perspectiveTransform() method and figured that I should be storing it in following shape:

numpy.array([
        [self.points[self.length-1][0]],
        [self.points[self.length-1][1]]
        ], dtype="float32")

Which would give me on a single click this format:

Point= [[ 2300.]
        [  634.]]

This format doesn't seem to work, I use this Transformation matrix:

M = [[ -1.71913123e+00  -4.76850572e+00   5.27968944e+03]
     [  2.07693562e-01  -1.09738424e+01   6.35222770e+03]
     [  1.02865125e-04  -4.80067600e-03   1.00000000e+00]]

in this method (and get following error):

cv2.perspectiveTransform(src, M)
OpenCV Error: Assertion failed (scn + 1 == m.cols) in cv::perspectiveTransform, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\core\src\matmul.cpp

Any advice or tip is welcome.

I figured out the answer.

Found it on this link

The key is to put your point like this:

 pts = numpy.array([[x,y]], dtype = "float32")

And then call another numpy.array on existing variable pts :

 pts = numpy.array([pts])

The procedure is the same after this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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