Ask Your Question
0

FindHomography usage

asked 2015-02-18 12:43:52 -0600

updated 2015-02-19 09:17:39 -0600

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-02-19 02:31:19 -0600

updated 2015-02-19 02:32:37 -0600

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));
edit flag offensive delete link more

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 ( 2015-02-19 08:40:35 -0600 )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 ( 2015-02-19 09:22:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-02-18 12:42:38 -0600

Seen: 894 times

Last updated: Feb 19 '15