OpenCV图像拼接,图像分辨率大于1080 * 1080
OpenCV Image Stitching with Image Resolutions greater than 1080 * 1080
我一直在使用OpenCV在树莓派和基于Windows操作系统的PC上将两张图像拼接在一起。
#include <stdio.h>
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
int main (int argc, char** argv) {
Mat image_1 = imread (argv[1]);
Mat image_2 = imread (argv[2]);
Mat gray_image_1;
Mat gray_image_2;
cvtColor (image_1, gray_image_1, CV_RGB2GRAY);
cvtColor (image_2, gray_image_2, CV_RGB2GRAY);
// Check if image files can be read
if (!gray_image_1.data) {
std::cout << "Error Reading Image 1" << std::endl;
return 0;
}
if (!gray_image_2.data) {
std::cout << "Error Reading Image 2" << std::endl;
return 0;
}
// Detect the keypoints using SURF Detector
// Based from Anna Huaman's 'Features2D + Homography to find a known object' Tutorial
int minHessian = 50;
SurfFeatureDetector detector (minHessian);
std::vector <KeyPoint> keypoints_object, keypoints_scene;
detector.detect (gray_image_2, keypoints_object);
detector.detect (gray_image_1, keypoints_scene);
// Calculate Feature Vectors (descriptors)
// Based from Anna Huaman's 'Features2D + Homography to find a known object' Tutorial
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute (gray_image_2, keypoints_object, descriptors_object);
extractor.compute (gray_image_1, keypoints_scene, descriptors_scene);
// Matching descriptor vectors using FLANN matcher
// Based from Anna Huaman's 'Features2D + Homography to find a known object' Tutorial
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
// Based from Anna Huaman's 'Features2D + Homography to find a known object' Tutorial
for (int i = 0; i < descriptors_object.rows; i++) {
double dist = matches[i].distance;
if (dist < min_dist) {
min_dist = dist;
}
}
// Use matches that have a distance that 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;
warpPerspective (image_2, result, H, cv::Size (image_2.cols + image_1.cols, image_2.rows));
cv::Mat half (result, cv::Rect (0, 0, image_1.cols, image_1.rows));
image_1.copyTo (half);
// Write image
imwrite("Update.jpg", result);
waitKey (0);
return 0;
}
我使用的两个图像作为输入结果是成功的。但是,只有当这两张图像的分辨率为<= 1080 * 1080像素时。
对于1440 * 1440和1944 * 1944分辨率,我发现findHomography不能工作,因为我不再得到超过3个好的匹配。findHomography需要至少4个好的匹配
I have try…
cv::resize(输入图像)-结果没有分辨率大小的图像产生足够好的匹配findHomography
min Hessian升高或降低-无变化
最小距离增加或减少-无变化
注意:两个图像重叠且尺寸相同。
谁有解决这个问题的办法?我花了几个小时研究这个问题,只得出结论,OpenCV图像拼接不能处理高分辨率图像。
下面我将包括两张高分辨率的图片,以供希望提供帮助的人使用。
colour_1_1440
colour_2_1440
我使用的是OpenCV 2.4.13,而不是新的OpenCV 3.1.0。
根据Martin Matilla的评论:
"你确定你没有在距离过滤部分丢弃好的匹配吗? "如果(匹配[我]。距离& lt;3 * min_dist)- Martin Matilla 53 mins ago
解确实位于3 * min_dist。我将值'3'改为'4',以便处理高分辨率的图像。
注意:最初我将'3'更改为'30',发现第二个输入图像如预期的那样扭曲。<-只是想让大家知道:)
相关文章:
- 大于65535的C++数组[size]引发不一致的溢出
- 查找最接近的大于当前数字的数字的索引
- 如何找到大于整数的最小数字
- 为什么签名字符可以保存大于 127 的值?
- 如何打印大于"无符号长长"的"std::bitset"的十进制值?
- 为什么它总是给我大于 4?
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 在向量中查找大于 0(或通常为 k)的最小元素的最佳方法是什么?
- 使用 RapidXML 解析大型 XML(大小大于 65 KB)文件时出现问题
- CStdioFile 不能处理大于 2GB 的文件?
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- C++大于或等于运算符
- 除数大于两个大因子时的模积
- 如何查找数字大于 5 的数字总和
- 数组大于指定大小(C++)
- 16 位系统中的程序如何访问大于 65535 的整数,但不能访问地址
- 第 k 个最小元素 - 不能创建大于 k 大小的数组
- 特征::向量;在函数中使用 Eigen::Matrix3f 的值初始化向量,大于 4 个条目
- 如何在随机数列表中查找大于或小于的元素
- OpenCV图像拼接,图像分辨率大于1080 * 1080