我有一张图片,我希望从中获得垂直投影回报率,应用一些转换并添加到另一张图像。
我在StackOverflow和其他论坛上阅读了很多问题和答案,但我仍然坚持这个问题。目前我正在使用OpenCV的C接口,但如果需要我可以使用C ++(我必须编写转换函数,因为我在Cocoa中使用CGImageRef)。
要从顶部图像(见下文)到底部图像,我想我必须:
目前,我管理得很好:
但是,我根本不知道如何扭曲我的ROI的结果图像,我不知道它是否甚至可能在OpenCV中。我是否必须使用一种透视校正?
而且,我一直在尝试使用旋转的边界框旋转我在这里找到的几个好帖子解决方案,但目前没有好的结果。
编辑:
好吧,我成功完成了第一部分工作:
我使用了这篇文章中解释和编码的方法:https://stackoverflow.com/a/16285286/1060921
我只添加了一个变量来设置旋转点并获得我的内圈。
NB :我设置ROI BEFORE以调用方法,因此post方法中的ROI是...图像大小。然后我用cvAdd将它放在我最终图像的中心。
这里我得到了一个相机输入的像素切片。 我现在要做的是扭曲更大的切片,例如从内圆上的2个像素到外圆上的5个像素。
答案 0 :(得分:0)
请参阅tutorial,其中使用warpPerspective
来纠正透视失真。
编辑:在你的情况下,warpAffine应该是更好更简单的解决方案。
所以,你可以这样做,只需使用四个点而不是三个点:
Point2f srcTri[3];
Point2f dstTri[3];
Mat rot_mat( 2, 3, CV_32FC1 );
Mat warp_mat( 2, 3, CV_32FC1 );
Mat src, warp_dst, warp_rotate_dst;
/// Load the image
src = imread( ... );
/// Set the dst image the same type and size as src
warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
/// Set your 3 points to calculate the Affine Transform
srcTri[0] = Point2f( 0,0 );
srcTri[1] = Point2f( src.cols - 1, 0 );
srcTri[2] = Point2f( 0, src.rows - 1 );
dstTri[0] = Point2f( src.cols*0.0, src.rows*0.33 );
dstTri[1] = Point2f( src.cols*0.85, src.rows*0.25 );
dstTri[2] = Point2f( src.cols*0.15, src.rows*0.7 );
/// Get the Affine Transform
warp_mat = getAffineTransform( srcTri, dstTri );
/// Apply the Affine Transform just found to the src image
warpAffine( src, warp_dst, warp_mat, warp_dst.size() );