-1
Q
全景图拼接算法
A
回答
0
如果你知道在你的拍摄图像,您可以按照此代码为您的拼接图像一起顺序。如果订单未知,那么解决方案会变得更加复杂。此外,此代码是为相同大小的图像而设计的,如果您的相机被移动了,它可能会导致一些错误的结果。实施一些检查以便正确理解。您可以参考这篇文章“http://ramsrigoutham.com/2012/11/22/panorama-image-stitching-in-opencv/”,以更好地理解主要调用两次的拼接功能。
#include <stdio.h>
#include <iostream>
#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;
void stitching(cv::Mat&,cv::Mat& ,cv::Mat&);
int main()
{
Mat image1= imread("image1.jpg");
Mat image2= imread("image2.jpg");
Mat image3= imread("image3.jpg");
Mat gray_image1;
Mat gray_image2;
Mat gray_image3;
Mat result1,result2;
// Convert to Grayscale
cvtColor(image1, gray_image1, CV_RGB2GRAY);
cvtColor(image2, gray_image2, CV_RGB2GRAY);
cvtColor(image3, gray_image3, CV_RGB2GRAY);
stitching(gray_image1,gray_image2,result1);
stitching(result1,gray_image3,result2);
cv::imshow("stitched image"result2);
cv::WaitKey(0);
}
void stitching(cv::Mat& im1,cv::Mat& im2,cv::Mat& stitch_im)
{
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect(im1, keypoints_object);
detector.detect(im2, keypoints_scene);
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute(im1, keypoints_object, descriptors_object);
extractor.compute(im2, keypoints_scene, descriptors_scene);
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_object, descriptors_scene, matches);
double max_dist = 0; double min_dist = 100;
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;
}
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++)
{
obj.push_back(keypoints_object[ good_matches[i].queryIdx ].pt);
scene.push_back(keypoints_scene[ good_matches[i].trainIdx ].pt);
}
Mat H = findHomography(obj, scene, CV_RANSAC);
cv::Mat result;
warpPerspective(im1,stitch_im,H,cv::Size(im1.cols+im2.cols,im1.rows));
}
相关问题
- 1. 无法拼接图像
- 2. 图像拼接
- 3. 用A *算法解决8拼图
- 4. 块拼图解决C++算法
- 5. 推荐算法编程拼图
- 6. 照片拼接/全景API/DLL /库任何人?
- 7. 多图像放置算法 - 拼贴算法
- 8. R拼接图像
- 9. OpenCV - 图像拼接
- 10. 图像拼接&OCR
- 11. 拼写校正算法
- 12. 拼合表达式算法
- 13. 重构拼图图像 - 拼图解算器
- 14. 钢琴拼图:背景图像
- 15. 15拼图背景图片JavaScript/CSS
- 16. 图像拼接方法去除接缝为缝合图像
- 17. 是否有任何Autopano服务器替代或自动全景拼接/视频全景开源?
- 18. 使用拼接将图像url设置为背景属性
- 19. 在另一幅图像中搜索图像的算法。 (拼贴)
- 20. Xamarin Forms ContentPage背景图片拼贴
- 21. 用PHP拼接图像GD
- 22. 拼接无重叠图像
- 23. 在iOS上拼接图像
- 24. 图像建模/拼接
- 25. 在功能_start,“未定义的引用主”,OpenCV的,全景拼接
- 26. 拼图拼图变形
- 27. 谷歌地图与谷歌街景全景图自定义全景图冲突
- 28. SWT图像连接或拼接/镶嵌
- 29. 图连接器算法
- 30. 带拼写纠错算法的拼写检查器
请提供更多详情。 – Piglet
查看[Wiki:autostitch](https://en.wikipedia.org/wiki/AutoStitch)它是如何工作的。当您运行拼接算法时,您将获得每个图像的变换矩阵,以便将其转换为多边形,并将它们的相交/重叠计算为几何问题。 – Spektre