int main(int argc, char* argv[])
{
int retval = parseCmdArgs(argc, argv);
if (retval) return -1;
Mat pano;
printf("Channels image1: %d\n", imgs[0].type());
printf("Channels image2: %d\n", imgs[1].type());
int width = 170;
cv::Rect rect1 = cvRect( imgs[0].cols-width, 0, width, imgs[0].rows); //second half of the first image
cv::vector<cv::Rect> roi1;
roi1.push_back(rect1);
cv::Rect rect12 = cvRect(0, 0,width, imgs[1].rows); //first half of the second image
cv::Rect rect23 = cvRect(imgs[1].cols -width, 0, width, imgs[1].rows); //second half of the first image
cv::vector<cv::Rect> roi2;
roi2.push_back(rect12);
roi2.push_back(rect23);
cv::Rect rect3 = cvRect(0, 0, width, imgs[2].rows); //first half of the third image
cv::vector<cv::Rect> roi3;
roi3.push_back(rect3);
cv::vector<cv::vector<cv::Rect>> rois;
rois.resize(3);
rois[0] = roi1;
rois[1] = roi2;
rois[2] = roi3;
//cv::imshow("debug_img1", imgs[0]);
Mat tmp1, tmp2, tmp3;
cvtColor(imgs[0], tmp1, CV_BGR2GRAY);
cvtColor(imgs[1], tmp2, CV_BGR2GRAY);
cvtColor(imgs[2], tmp3, CV_BGR2GRAY);
/*lensCorrectorBarrel(tmp1.data, tmp1.cols, tmp1.rows);
lensCorrectorBarrel(tmp2.data, tmp2.cols, tmp2.rows);
lensCorrectorBarrel(tmp3.data, tmp3.cols, tmp3.rows);
imwrite("corr1.tif", tmp1);
imwrite("corr2.tif", tmp2);
imwrite("corr3.tif", tmp3);*/
/*namedWindow( "debug_img_corr1", CV_WINDOW_AUTOSIZE );
namedWindow( "debug_img_corr2", CV_WINDOW_AUTOSIZE );
cv::imshow("debug_img_corr1", tmp1);
cv::imshow("debug_img_corr2", tmp2);*/
cvtColor(tmp1, imgs[0], CV_GRAY2BGR);
cvtColor(tmp2, imgs[1], CV_GRAY2BGR);
cvtColor(tmp3, imgs[2], CV_GRAY2BGR);
//char cc = cvWaitKey(0);
/*cv::rectangle( imgs[0], rect1, CV_RGB(255,0,0), 1);
cv::rectangle( imgs[1], rect12, CV_RGB(255,0,0), 1);
cv::rectangle( imgs[1], rect23, CV_RGB(255,0,0), 1);
cv::rectangle( imgs[2], rect3, CV_RGB(255,0,0), 1);
cv::imshow("debug_img1", imgs[0]);
cv::imshow("debug_img2", imgs[1]);
cv::imshow("debug_img3", imgs[2]);
char c = cvWaitKey(0);*/
Stitcher stitcher = Stitcher::createDefault(false);
stitcher.setPanoConfidenceThresh(0.07);
stitcher.setWaveCorrection(false);
//detail::BestOf2NearestMatcher *matcher = new detail::BestOf2NearestMatcher(false, 0.001/*=match_conf*/);
//detail::SurfFeaturesFinder *featureFinder = new detail::SurfFeaturesFinder(100);
//stitcher.setFeaturesMatcher(matcher);
//stitcher.setFeaturesFinder(featureFinder);
Stitcher::Status status = stitcher.stitch(imgs, rois, pano);
//Stitcher::Status status = stitcher.composePanorama(imgs, pano);
if (status != Stitcher::OK)
{
cout << "Can't stitch images, error code = " << status << endl;
return -1;
}
imwrite(result_name, pano);
char ac = cvWaitKey(0);
if(ac == 'ESC')
return 0;
}
Stitcher拼接设置感兴趣区域
最新推荐文章于 2024-02-05 09:11:40 发布