Perspective conversion of OpenCV in python

I am trying to fix an image in python. I have a homography H (from a rotation matrix that rotates around the x, y and z axis), which looks like this: [[9.95671447e-01 7.83610423e-02 7.47993630e + 02] [-7.69292630e-02 9.96586377e-01 -4.48354859e + 02] [-3.48494755e-06 1.73615469e-06 9.98300856e-01]]

I thought I could do it cv2.perspectiveTransform (), but I can't get it to work. This is the code I'm using:

   # warp image
   img_cv2 = cv2.imread('surf.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
   # strange output but it does something:
   dst = cv2.perspectiveTransform(img_cv2,H)

But I get the following error:

    Traceback (most recent call last):
    File "C:\directory structure\python_files\Rectification\rectify.py", line 82, in <module>
    dst = cv2.perspectiveTransform(img_cv2,H)
    error: C:\slave\WinInstallerMegaPack\src\opencv\modules\core\src\matmul.cpp:1916: error: (-215) scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)`</pre>

Can anyone understand what is going wrong?

+3
source share
3 answers

The source and destination image must be floating point data.

cv2.perspectiveTransform (src, m [, dst]) → dst

Parameters

  • src - ; 2D/3D .
  • dst - , src.
  • m - 3x3 4x4.

: http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=perspectivetransform#cv2.perspectiveTransform

, 8U .

+2

, cv2.warpPerspective (. ()), cv2.perspectiveTransform.

+2

, np.float32 np.float64.

, img_cv2 = np.float32(img_cv2).

cv2.perspectiveTransform() cv2.warpPerspective()

0

All Articles