OpenCV findHomography gives meaningless results

I am making a program that tracks functions with ORB from OpenCV (2.43) this tutorial and used the tip here .

My goal is to track an object in the video stream (face) and draw a rectangle around it.

My program finds the key points and matches them correctly, but when I try to use findHomography+ perspectiveTransformto find new angles for the image, it usually returns some values ​​such as meaninglessness (although sometimes it returns the correct homography).

Here is an example of a picture: example

Here is the relevant problematic part:

Mat H = findHomography( obj, scene, CV_RANSAC );  

//-- Get the corners from the image_1 ( the object to be "detected" )
std::vector<Point2f> obj_corners(4);
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 );
obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows );
std::vector<Point2f> scene_corners(4);

perspectiveTransform( obj_corners, scene_corners, H);

//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );

, , . , - , , , .

P.S. - , , , ?

+5
1

perspectiveTransform , . . , RANSAC, .

findHomography, . . 4 , . - , . CV_RANSAC, ( ) .

0

All Articles