c – OpenCV findHomography问题

c – OpenCV findHomography问题,第1张

概述我正在开发OpenCV中的Panography / Panorama应用程序,我遇到了一个我无法弄清楚的问题.有关全景照片的概念,请查看Panography Wikipedia文章: http://en.wikipedia.org/wiki/Panography 到目前为止,我可以拍摄多张图像,并将它们拼接在一起,同时制作任何我喜欢参考图像的图像;这是我的意思. 但是,正如您所看到的 – 它有很多 我正在开发OpenCV中的Panography / Panorama应用程序,我遇到了一个我无法弄清楚的问题.有关全景照片的概念,请查看Panography Wikipedia文章: http://en.wikipedia.org/wiki/Panography

到目前为止,我可以拍摄多张图像,并将它们拼接在一起,同时制作任何我喜欢参考图像的图像;这是我的意思.

但是,正如您所看到的 – 它有很多问题.我面临的主要问题是图像被切割(重新:最右边的图像,图像的顶部).为了突出显示这种情况的原因,我将绘制已匹配的点,并绘制转换结束位置的行:

左图像是参考图像,右图像是翻译后的图像(下面的原始图像) – 我绘制了绿线以突出显示图像.该图像具有以下角点:

TL: [234.759,-117.696]TR: [852.226,-38.9487]BR: [764.368,374.84]BL: [176.381,259.953]

所以我的主要问题是在透视图改变后的图像:

像这样遭受损失:

现在有足够的图像,一些代码.

我正在使用cv :: SurfFeatureDetector,cv :: SurfDescriptorExtractor和cv :: FlannBasedMatcher来获取所有这些点,我通过执行以下 *** 作来计算匹配和更重要的好匹配:

/* calculate the matches */for(int i = 0; i < descriptors_thisImage.rows; i++) {    double dist = matches[i].distance;    if(dist < min_dist) min_dist = dist;    if(dist > max_dist) max_dist = dist;}/* calculate the good matches */for(int i = 0; i < descriptors_thisImage.rows; i++) {    if(matches[i].distance < 3*min_dist) {        good_matches.push_back(matches[i]);    }}

这是非常标准的,为了做到这一点,我按照这里的教程:http://opencv.itseez.com/trunk/doc/tutorials/features2d/feature_homography/feature_homography.html

为了复制彼此之上的图像,我使用以下方法(其中img1和img2是std :: vector< cv :: Point2f>)

/* set the keypoints from the good matches */for( int i = 0; i < good_matches.size(); i++ ) {    img1.push_back( keypoints_thisImage[ good_matches[i].queryIDx ].pt );    img2.push_back( keypoints_referenceImage[ good_matches[i].trainIDx ].pt );}/* calculate the homography */cv::Mat H = cv::findHomography(cv::Mat(img1),cv::Mat(img2),CV_RANSAC);/* warp the image */cv::warpPerspective(thisImage,thistransformed,H,cv::Size(thisImage.cols * 2,thisImage.rows * 2),cv::INTER_CUBIC );/* place the contents of thisImage in gsThisImage */thisImage.copyTo(gsThisImage);/* set the values of gsThisImage to 255 */for(int i = 0; i < gsThisImage.rows; i++) {    cv::Vec3b *p = gsThisImage.ptr<cv::Vec3b>(i);    for(int j = 0; j < gsThisImage.cols; j++) {        for( int grb=0; grb < 3; grb++ ) {            p[j][grb] = cv::saturate_cast<uchar>( 255.0f );        }    }}/* convert the colour to greyscale */cv::cvtcolor(gsThisImage,gsThisImage,CV_BGR2GRAY);/* warp the greyscale image to create an image mask */cv::warpPerspective(gsThisImage,thisMask,cv::INTER_CUBIC );/* stitch the transformed image to the reference image */thistransformed.copyTo(referenceImage,thisMask);

所以,我有翘曲图像最终的坐标,我有点创建用于这些变换的均匀矩阵 – 但我无法弄清楚我应该如何翻译这些图像以便他们可以不会被切断.任何帮助或指示非常感谢!

解决方法 首先,为什么不使用新添加的拼接模块?它确实完成了你想要做的事情.

其次,如果你想继续你的代码,要纠正它很容易.在单应矩阵中,平移表示最后一列的值.

a11 a12 a13 t1a21 a22 a23 t2a31 a32 a33 t3a41 a42 a43 1

(如果你有3×3矩阵,你会错过a13..a43列和a41..1行.a33将(应该)变为1).

所以,你要做的是弄清楚你应该把什么放在最后一列,以便你的图像对齐.

当你知道相机参数时,还要检查这篇文章,解释说明(不知何故相反的问题)如何建立单应性.它将帮助您了解矩阵值的作用.

Opencv virtually camera rotating/translating for bird’s eye view

请注意,我告诉你的关于最后一列的所有内容都只是近似值,因为最后一列中的值实际上是翻译加上一些(次要)因素.

总结

以上是内存溢出为你收集整理的c – OpenCV findHomography问题全部内容,希望文章能够帮你解决c – OpenCV findHomography问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1239013.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存