Reputation: 3507
I am creating an application where I'll find the bird view perspective of an image by multiplying it with a homography matrix. I have read a lot about it and it seems that the function to multiply the matrices is warpPerspective(). Although when I do so, the resulting image is an image where all pixels are zero and only the first row is not.
Please provide me with the way to multiply a homography matrix by an image whether is C++ or Python.
Here's the code I'm using:
import cv2
import numpy as np
tilt = np.pi * 35 / 180
a = np.zeros((3, 3))
a[0][0] = 1
a[1][1] = np.sin(tilt)
a[1][2] = -np.sin(tilt)
a[2][2] = np.cos(tilt)
a[2][2] = np.cos(tilt)
src = cv2.imread("S2.jpg")
width, height, depth = src.shape
output = cv2.warpPerspective(src, a, (width, height))
cv2.imwrite("results.png", output)
The image I'm applying the homography on:
The result of using warpPerspective is:
It can be seen that there is a small part on the top-left of resulting picture.
Your help is highly appreciated!!
Upvotes: 0
Views: 2455
Reputation: 12607
I think it's got to do with your a
matrix, since calling your code with
a = np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]],
dtype=np.float32)
works fine.
Upvotes: 1