设为首页 加入收藏

TOP

【OpenCV】透视变换 Perspective Transformation(续)(二)
2015-02-02 14:36:42 来源: 作者: 【 】 浏览:11
Tags:OpenCV 透视 变换 Perspective Transformation
[i].trainIdx ].pt );
?}


?Mat H = findHomography( obj, scene, RANSAC );


?//-- Get the corners from the image_1 ( the object to be "detected" )
?std::vector obj_corners(4);
?obj_corners[0] = Point(0,0); obj_corners[1] = Point( img_object.cols, 0 );
?obj_corners[2] = Point( img_object.cols, img_object.rows ); obj_corners[3] = Point( 0, img_object.rows );
?std::vector scene_corners(4);
?perspectiveTransform( obj_corners, scene_corners, H);
?//-- Draw lines between the corners (the mapped object in the scene - image_2 )
?Point2f offset( (float)img_object.cols, 0);
?line( img_matches, scene_corners[0] + offset, scene_corners[1] + offset, Scalar(0, 255, 0), 4 );
?line( img_matches, scene_corners[1] + offset, scene_corners[2] + offset, Scalar( 0, 255, 0), 4 );
?line( img_matches, scene_corners[2] + offset, scene_corners[3] + offset, Scalar( 0, 255, 0), 4 );
?line( img_matches, scene_corners[3] + offset, scene_corners[0] + offset, Scalar( 0, 255, 0), 4 );


?//-- Show detected matches
?imshow( "Good Matches & Object detection", img_matches );
?waitKey(0);
?return 0;
}


代码运行效果:


?



?


findHomography()函数直接通过两个平面上相匹配的特征点求出变换公式,之后代码又对原图的四个边缘点进行变换,在右图上画出对应的矩形。这个图也很好地解释了所谓透视变换的“Viewing Plane”。


--------------------------------------分割线 --------------------------------------


--------------------------------------分割线 --------------------------------------


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇【图像处理】透视变换 Perspectiv.. 下一篇OpenCV 闭合轮廓检测

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: