我正在制作一个程序,使用 OpenCV (2.43) 中的 ORB 跟踪功能,我遵循并使用了建议从这里 https://stackoverflow.com/questions/9919505/how-can-i-extract-fast-features-from-an-image.
我的目标是跟踪视频源中的对象(脸部)并在其周围绘制一个矩形。
我的程序找到关键点并正确匹配它们,但是当我尝试使用findHomography
+ perspectiveTransform
为图像找到新的角点通常会返回一些无意义的类型值(尽管有时它会返回正确的单应性)。
Here is an example picture:
这是相应的有问题的部分:
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 );
其余代码实际上与我提供的链接中的相同。
绘制的线条看起来完全随机,我的目标只是在新场景中获得源对象的最小矩形,因此如果有使用单应性的替代方法也可以。
附:要跟踪的源图像是从视频输入复制的区域,然后在该输入的新图片中进行跟踪,这重要吗?