mirror of
https://github.com/opencv/opencv.git
synced 2025-06-08 18:13:13 +08:00
Update stitching.cpp
This commit is contained in:
parent
91ef0b9537
commit
efa0e75eac
@ -1,60 +1,20 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
||||||
//
|
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
|
||||||
// If you do not agree to this license, do not download, install,
|
|
||||||
// copy or use the software.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License Agreement
|
|
||||||
// For Open Source Computer Vision Library
|
|
||||||
//
|
|
||||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
|
||||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
|
||||||
// Third party copyrights are property of their respective owners.
|
|
||||||
//
|
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
// are permitted provided that the following conditions are met:
|
|
||||||
//
|
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer.
|
|
||||||
//
|
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
|
||||||
// and/or other materials provided with the distribution.
|
|
||||||
//
|
|
||||||
// * The name of the copyright holders may not be used to endorse or promote products
|
|
||||||
// derived from this software without specific prior written permission.
|
|
||||||
//
|
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
|
||||||
// any express or implied warranties, including, but not limited to, the implied
|
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
||||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
|
||||||
// the use of this software, even if advised of the possibility of such damage.
|
|
||||||
//
|
|
||||||
//M*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include "opencv2/imgcodecs.hpp"
|
#include "opencv2/imgcodecs.hpp"
|
||||||
#include "opencv2/highgui.hpp"
|
#include "opencv2/highgui.hpp"
|
||||||
#include "opencv2/stitching.hpp"
|
#include "opencv2/stitching.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
bool try_use_gpu = false;
|
bool try_use_gpu = false;
|
||||||
|
bool divide_images = false;
|
||||||
Stitcher::Mode mode = Stitcher::PANORAMA;
|
Stitcher::Mode mode = Stitcher::PANORAMA;
|
||||||
vector<Mat> imgs;
|
vector<Mat> imgs;
|
||||||
string result_name = "result.jpg";
|
string result_name = "result.jpg";
|
||||||
|
|
||||||
void printUsage();
|
void printUsage(char** argv);
|
||||||
int parseCmdArgs(int argc, char** argv);
|
int parseCmdArgs(int argc, char** argv);
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
@ -73,16 +33,18 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
imwrite(result_name, pano);
|
imwrite(result_name, pano);
|
||||||
|
cout << "stitching completed successfully\n" << result_name << " saved!";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printUsage()
|
void printUsage(char** argv)
|
||||||
{
|
{
|
||||||
cout <<
|
cout <<
|
||||||
"Images stitcher.\n\n"
|
"Images stitcher.\n\n" << "Usage :\n" << argv[0] <<" [Flags] img1 img2 [...imgN]\n\n"
|
||||||
"stitching img1 img2 [...imgN]\n\n"
|
|
||||||
"Flags:\n"
|
"Flags:\n"
|
||||||
|
" --d3\n"
|
||||||
|
" internally creates three chunks of each image to increase stitching success"
|
||||||
" --try_use_gpu (yes|no)\n"
|
" --try_use_gpu (yes|no)\n"
|
||||||
" Try to use GPU. The default value is 'no'. All default values\n"
|
" Try to use GPU. The default value is 'no'. All default values\n"
|
||||||
" are for CPU mode.\n"
|
" are for CPU mode.\n"
|
||||||
@ -91,7 +53,8 @@ void printUsage()
|
|||||||
" mode suitable for creating photo panoramas. Option 'scans' is suitable\n"
|
" mode suitable for creating photo panoramas. Option 'scans' is suitable\n"
|
||||||
" for stitching materials under affine transformation, such as scans.\n"
|
" for stitching materials under affine transformation, such as scans.\n"
|
||||||
" --output <result_img>\n"
|
" --output <result_img>\n"
|
||||||
" The default is 'result.jpg'.\n";
|
" The default is 'result.jpg'.\n\n"
|
||||||
|
"Example usage :\n" << argv[0] << " --d3 --try_use_gpu yes --mode scans img1.jpg img2.jpg";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,14 +62,15 @@ int parseCmdArgs(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
printUsage();
|
printUsage(argv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
|
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
|
||||||
{
|
{
|
||||||
printUsage();
|
printUsage(argv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else if (string(argv[i]) == "--try_use_gpu")
|
else if (string(argv[i]) == "--try_use_gpu")
|
||||||
@ -122,6 +86,10 @@ int parseCmdArgs(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
else if (string(argv[i]) == "--d3")
|
||||||
|
{
|
||||||
|
divide_images = true;
|
||||||
|
}
|
||||||
else if (string(argv[i]) == "--output")
|
else if (string(argv[i]) == "--output")
|
||||||
{
|
{
|
||||||
result_name = argv[i + 1];
|
result_name = argv[i + 1];
|
||||||
@ -148,6 +116,17 @@ int parseCmdArgs(int argc, char** argv)
|
|||||||
cout << "Can't read image '" << argv[i] << "'\n";
|
cout << "Can't read image '" << argv[i] << "'\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (divide_images)
|
||||||
|
{
|
||||||
|
Rect rect(0, 0, img.cols / 2, img.rows);
|
||||||
|
imgs.push_back(img(rect).clone());
|
||||||
|
rect.x = img.cols / 3;
|
||||||
|
imgs.push_back(img(rect).clone());
|
||||||
|
rect.x = img.cols / 2;
|
||||||
|
imgs.push_back(img(rect).clone());
|
||||||
|
}
|
||||||
|
else
|
||||||
imgs.push_back(img);
|
imgs.push_back(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user