I\'m trying to rectify an image in python. I have a Homography H (from a rotation matrix that rotates around the x, y and z axis) that looks like this for example: [
It says the image should be np.float32
or np.float64
.
So convert the image first by img_cv2 = np.float32(img_cv2)
.
Then apply the cv2.perspectiveTransform()
and cv2.warpPerspective()
Check this tutorial for demo
I think what you want is cv2.warpPerspective
(see documentation (link)), not cv2.perspectiveTransform
.
The source and destination image must be floating point data.
cv2.perspectiveTransform(src, m[, dst]) → dst
Parameters:
- src – input two-channel or three-channel floating-point array; each element is a 2D/3D vector to be transformed.
- dst – output array of the same size and type as src.
- m – 3x3 or 4x4 floating-point transformation matrix.
Refer:http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=perspectivetransform#cv2.perspectiveTransform
So convert the 8U image to the appropriate datatype.