我想要在塑料零件的直表面的单个图像中拼接很多图像(25)。图片是这样的:无法在opencv C++中使用Stitcher类拼接很多图像
我想使用拼接类形式的OpenCV。我的代码是在这里:
#include <iostream>
#include <fstream>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/stitching.hpp>
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
string result_name = "result.jpg";
Mat img1, img2,img3,img4,img5,img6,img7, pano;
void printUsage();
//int parseCmdArgs(int argc, char** argv);
int main(int argc, char* argv[])
{
// Load images from HD.
img1 = imread("1.bmp");
img2 = imread("2.bmp");
img3 = imread("3.bmp");
img4 = imread("4.bmp");
// Put images into vector of images "imgs".
imgs.push_back(img1);
imgs.push_back(img2);
imgs.push_back(img3);
imgs.push_back(img4);
// Create stitcher instance and use stitch method with imgs.
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
stitcher.setPanoConfidenceThresh(0.8);
Stitcher::Status status = stitcher.stitch(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << status << endl;
return -1;
}
imwrite(result_name, pano);
return 0;
}
我总是得到一个错误说:“不能拼接图像,错误代码= 1”,因此该系统是说,它需要更多的图像。在调试时,我看到图像已正确加载,然后正确创建矢量图像。原因是什么?我的calcuclation也持续很长时间(2秒)...
你能告诉你图片的大小吗? –
恕我直言,缝合器对您的输入有点矫枉过正。假设图像是有序的,它们没有失真并且相机沿着一个轴以一致的方向移动,您可以利用这一点。您可以使用模板匹配来查找相邻图像的重叠部分,并使用它来制作合成图像。最简单的方法是将非重叠部分连接起来。或者在做重叠的零件上进行一些混合。 |然而,理想的方法是消除完全这样做的需要 - 一个线照相机+一些编码器。 –
@ skoda23一个非常简单的[Python原型](http://pastebin.com/dMfGfyJ1),生成[this result](http://i.imgur.com/2bSw2dj.png)。您可以添加一些垂直的“摆动空间”,以防切片排列不像您的合成示例中那样好。还要添加一些重叠部分的混合,不管是使用'addWeighted'的一半还是使用权重的梯度。 –