【发布时间】:2011-12-26 17:46:17
【问题描述】:
我正在开发 OpenCV 中的 Panography / Panorama 应用程序,但遇到了一个我真的无法解决的问题。要了解全景照片的外观,请查看 Panography Wikipedia 文章:http://en.wikipedia.org/wiki/Panography
到目前为止,我可以拍摄多张图像,并将它们拼接在一起,同时制作任何我喜欢的图像作为参考图像;这里有一点我的意思。
但是,如您所见 - 它有很多问题。我面临的主要问题是图像被剪切(re:最右边的图像,图像的顶部)。为了突出为什么会发生这种情况,我将绘制已匹配的点,并绘制转换结束位置的线:
左图是参考图,右图是翻译后的图(原文如下)——我画了绿线来突出显示图像。图像具有以下角点:
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, H, cv::Size(thisImage.cols * 2, thisImage.rows * 2), cv::INTER_CUBIC );
/* stitch the transformed image to the reference image */
thisTransformed.copyTo(referenceImage, thisMask);
所以,我有扭曲图像将要结束的坐标,我有创建用于这些变换的齐次矩阵的点 - 但我不知道应该如何翻译这些图像所以他们不能被切断。非常感谢任何帮助或指示!
【问题讨论】: