【发布时间】:2017-02-17 17:22:00
【问题描述】:
我从图像拼接中找到了非常有用的示例,但我的问题是那些类型的图像 这是一个例子
当我使用 opencv 缝合器时,结果图像越来越小 喜欢这个
这里是代码
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<opencv2/opencv.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include<vector>
using namespace cv;
using namespace std;
cv::vector<cv::Mat> ImagesList;
string result_name ="/TopViewsHorizantale/1.bmp";
int main()
{
// Load the images
Mat image1= imread("current_00000.bmp" );
Mat image2= imread("current_00001.bmp" );
cv::resize(image1, image1, image2.size());
Mat gray_image1;
Mat gray_image2;
Mat Matrix = Mat(3,3,CV_32FC1);
// Convert to Grayscale
cvtColor( image1, gray_image1, CV_RGB2GRAY );
cvtColor( image2, gray_image2, CV_RGB2GRAY );
namedWindow("first image",WINDOW_AUTOSIZE);
namedWindow("second image",WINDOW_AUTOSIZE);
imshow("first image",image2);
imshow("second image",image1);
if( !gray_image1.data || !gray_image2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector< KeyPoint > keypoints_object, keypoints_scene;
detector.detect( gray_image1, keypoints_object );
detector.detect( gray_image2, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( gray_image1, keypoints_object, descriptors_object );
extractor.compute( gray_image2, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_object.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Use only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_object.rows; i++ )
{ if( matches[i].distance < 3*min_dist )
{ good_matches.push_back( matches[i]); }
}
std::vector< Point2f > obj;
std::vector< Point2f > scene;
for( int i = 0; i < good_matches.size(); i++ )
{
//-- Get the keypoints from the good matches
obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
}
// Find the Homography Matrix
Mat H = findHomography( obj, scene, CV_RANSAC );
// Use the Homography Matrix to warp the images
cv::Mat result;
int N = image1.rows + image2.rows;
int M = image1.cols+image2.cols;
warpPerspective(image1,result,H,cv::Size(N,M));
cv::Mat half(result,cv::Rect(0,0,image2.rows,image2.cols));
result.copyTo(half);
namedWindow("Result",WINDOW_AUTOSIZE);
imshow( "Result", result);
imwrite(result_name, result);
waitKey(0);
return 0;
}
这里还有一些图片的链接 :: https://www.dropbox.com/sh/ovzkqomxvzw8rww/AAB2DDCrCF6NlCFre7V1Gb6La?dl=0 太感谢了 拉菲
【问题讨论】:
-
请详细解释您的问题?这个视频是怎么录制的?为什么相机在对角线移动等。
-
相机可以旋转,也可以录像,可以任意角度旋转,我们要拼接所有的图像
-
问题是在拼接这些图像时,结果图像越来越小
-
你可以访问当前帧和前一帧之间的单应矩阵吗?您是否正在使用图像流并拼接 Stitched Frame 和 Current frame?或者您是一次将所有图像输入到 OPencvStitcher?
-
我可以通过在当前帧和蝾螈帧之间使用 FindHomography 得到 Homography 矩阵。我已经测试了存储到向量中的所有农场的 OPencv Sticher,并且我已经使用当前帧和下一帧之间的 surf 匹配然后在前一帧和新下一帧的结果之间进行测试。但是当我使用匹配然后包裹透视图时,结果图像越来越小,而当使用 OpencvSticher 时,相同的细节被隐藏了
标签: opencv perspectivecamera panoramas image-stitching