// MODforPTZC-OpenCV2.4.2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
//#include "opencv2/features2d/features2d.hpp"
//#include "opencv2/nonfree/features2d.hpp"
//#include <cv.h>
//#include <highgui.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
vector<Mat> imgs;
int main(int argc, char* argv[])
{
const int N=900;//待拼接图像数
const string str1="D:\\images\\";
const string str2=".bmp";
for(int i=1;i<N;i+=200)//1.bmp,201.bmp,301.bmp...
{
string imgpath;
char strn[5];
sprintf(strn, "%d", i); //将100转为字符串。
imgpath = str1 + strn + str2;
Mat img_original,img_bgr;
img_original = imread( imgpath, CV_LOAD_IMAGE_GRAYSCALE );
if( !img_original.data )
{ cout<<"--(!) Error reading images"<<endl; return -1;}
//stitcher.stitch要求图像必须为彩色图像,此实例用的灰度图像,故续先做转换。
cvtColor(img_original, img_bgr, CV_GRAY2BGR);
imgs.push_back(img_bgr);
imgpath.clear();
}
/*
const string name1="D:\\images\\1.bmp";
const string name2="D:\\images\\201.bmp";
const string name3="D:\\images\\401.bmp";
Mat img1 = imread( name1, CV_LOAD_IMAGE_GRAYSCALE );
Mat img2 = imread( name2, CV_LOAD_IMAGE_GRAYSCALE );
Mat img3 = imread( name3, CV_LOAD_IMAGE_GRAYSCALE );
if( !img1.data || !img2.data || !img3.data)
{
std::cout<< " --(!) Error reading images " << std::endl; return -1;
}
Mat img1_temp, img2_temp, img3_temp;
cvtColor(img1,img1_temp, CV_GRAY2BGR);
cvtColor(img2,img2_temp, CV_GRAY2BGR);
cvtColor(img3,img3_temp, CV_GRAY2BGR);
imgs.push_back(img1_temp);
imgs.push_back(img2_temp);
imgs.push_back(img3_temp);
//imgs.push_back(img3);
imshow("img1",img1_temp);
imshow("img2",img2_temp);
imshow("img3",img3_temp);
*/
cout<<"imgs.size(): "<<imgs.size()<<endl;
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status= stitcher.stitch(imgs, pano);//Stitcher::ERR_NEED_MORE_IMGS;
int a1=1;
//imshow("pano", pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << status << endl;
return -1;
}
imshow("pano", pano);
const string panopath="D:\\images\\pano.jpg";
imwrite(panopath,pano);
waitKey(0);
return 0;
}
- 1
- 2
- 3
- 4
前往页