Ask Your Question
0

FindHomography usage

asked Feb 18 '15

updated Feb 19 '15

Hi all, i'm completely new, so i think it's very simple my problem.

Context

I'm using OpenCV library for Android, i'm capturing a video with my device (fixed in a position, not in movement), with a component of my program i can determine 4 point from the scene. So at the end I have a 640x480 int array , and i have 4 values (indexes) of the four point in the scene.

Problem

I want to do this kind of transformation:

transformation

Question

What do i have to do to make such a ("plane") transformation, in order to watch the scene from above? What i'm trying to saying is that: given 4 indexes of a rgb array that identify 4 real points of the scene, what do i have to pass to findHomography function? And after that, what do i have to do with Mat object to apply the change in real time?

I actually need detailed steps, because I'm completely new. Thanks a lot,.

Sorry i'm new to Computer Vision.

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Feb 19 '15

updated Feb 19 '15

You need to pass the four pixel coordinates in your original image and the four corresponding pixel coordinates in your goal image (the second set could look somethink like)

vector<Point2f> training_corners;
training_corners.push_back(Point2f(0,0));
training_corners.push_back(Point2f(rgb.cols,0));
training_corners.push_back(Point2f(rgb.cols,rgb.rows));
training_corners.push_back(Point2f(0,rgb.rows));

You get your transformation:

 Mat H2 = findHomography(measured_pixels,training_corners);

Then you use warpPerspektive:

warpPerspective(rgb, unwarped_image, H2,cv::Size(rgb.cols, rgb.rows));
Preview: (hide)

Comments

What stands for rgb.cols? I have a int[] matrix (it's an array of int, rgb, values) so i have 4 indexes like 100, 1000, 2000, 3000. I've seen that findhomography wants point2f with x and y but i have only a single value. How can i overcome this? It's very frustrating that there isn't java documentation for this library....

psykomantisita gravatar imagepsykomantisita (Feb 19 '15)edit

In this code, I warp the region to the image rgb. (rgb.cols is therefore the number of columns in this goal image). You need to compute the pixel coordinates for your indices. Where did you get your indices from?

FooBar gravatar imageFooBar (Feb 19 '15)edit

Question Tools

1 follower

Stats

Asked: Feb 18 '15

Seen: 920 times

Last updated: Feb 19 '15