Skip to content

Commit efa0e75

Browse files
committed
Update stitching.cpp
1 parent 91ef0b9 commit efa0e75

File tree

1 file changed

+39
-60
lines changed

1 file changed

+39
-60
lines changed

samples/cpp/stitching.cpp

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,20 @@
1-
/*M///////////////////////////////////////////////////////////////////////////////////////
2-
//
3-
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4-
//
5-
// By downloading, copying, installing or using the software you agree to this license.
6-
// If you do not agree to this license, do not download, install,
7-
// copy or use the software.
8-
//
9-
//
10-
// License Agreement
11-
// For Open Source Computer Vision Library
12-
//
13-
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14-
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15-
// Third party copyrights are property of their respective owners.
16-
//
17-
// Redistribution and use in source and binary forms, with or without modification,
18-
// are permitted provided that the following conditions are met:
19-
//
20-
// * Redistribution's of source code must retain the above copyright notice,
21-
// this list of conditions and the following disclaimer.
22-
//
23-
// * Redistribution's in binary form must reproduce the above copyright notice,
24-
// this list of conditions and the following disclaimer in the documentation
25-
// and/or other materials provided with the distribution.
26-
//
27-
// * The name of the copyright holders may not be used to endorse or promote products
28-
// derived from this software without specific prior written permission.
29-
//
30-
// This software is provided by the copyright holders and contributors "as is" and
31-
// any express or implied warranties, including, but not limited to, the implied
32-
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33-
// In no event shall the Intel Corporation or contributors be liable for any direct,
34-
// indirect, incidental, special, exemplary, or consequential damages
35-
// (including, but not limited to, procurement of substitute goods or services;
36-
// loss of use, data, or profits; or business interruption) however caused
37-
// and on any theory of liability, whether in contract, strict liability,
38-
// or tort (including negligence or otherwise) arising in any way out of
39-
// the use of this software, even if advised of the possibility of such damage.
40-
//
41-
//M*/
421

43-
#include <iostream>
44-
#include <fstream>
452
#include "opencv2/imgcodecs.hpp"
463
#include "opencv2/highgui.hpp"
474
#include "opencv2/stitching.hpp"
485

6+
#include <iostream>
7+
498
using namespace std;
509
using namespace cv;
5110

5211
bool try_use_gpu = false;
12+
bool divide_images = false;
5313
Stitcher::Mode mode = Stitcher::PANORAMA;
5414
vector<Mat> imgs;
5515
string result_name = "result.jpg";
5616

57-
void printUsage();
17+
void printUsage(char** argv);
5818
int parseCmdArgs(int argc, char** argv);
5919

6020
int main(int argc, char* argv[])
@@ -73,40 +33,44 @@ int main(int argc, char* argv[])
7333
}
7434

7535
imwrite(result_name, pano);
36+
cout << "stitching completed successfully\n" << result_name << " saved!";
7637
return 0;
7738
}
7839

7940

80-
void printUsage()
41+
void printUsage(char** argv)
8142
{
8243
cout <<
83-
"Images stitcher.\n\n"
84-
"stitching img1 img2 [...imgN]\n\n"
85-
"Flags:\n"
86-
" --try_use_gpu (yes|no)\n"
87-
" Try to use GPU. The default value is 'no'. All default values\n"
88-
" are for CPU mode.\n"
89-
" --mode (panorama|scans)\n"
90-
" Determines configuration of stitcher. The default is 'panorama',\n"
91-
" mode suitable for creating photo panoramas. Option 'scans' is suitable\n"
92-
" for stitching materials under affine transformation, such as scans.\n"
93-
" --output <result_img>\n"
94-
" The default is 'result.jpg'.\n";
44+
"Images stitcher.\n\n" << "Usage :\n" << argv[0] <<" [Flags] img1 img2 [...imgN]\n\n"
45+
"Flags:\n"
46+
" --d3\n"
47+
" internally creates three chunks of each image to increase stitching success"
48+
" --try_use_gpu (yes|no)\n"
49+
" Try to use GPU. The default value is 'no'. All default values\n"
50+
" are for CPU mode.\n"
51+
" --mode (panorama|scans)\n"
52+
" Determines configuration of stitcher. The default is 'panorama',\n"
53+
" mode suitable for creating photo panoramas. Option 'scans' is suitable\n"
54+
" for stitching materials under affine transformation, such as scans.\n"
55+
" --output <result_img>\n"
56+
" The default is 'result.jpg'.\n\n"
57+
"Example usage :\n" << argv[0] << " --d3 --try_use_gpu yes --mode scans img1.jpg img2.jpg";
9558
}
9659

9760

9861
int parseCmdArgs(int argc, char** argv)
9962
{
10063
if (argc == 1)
10164
{
102-
printUsage();
65+
printUsage(argv);
10366
return -1;
10467
}
68+
10569
for (int i = 1; i < argc; ++i)
10670
{
10771
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
10872
{
109-
printUsage();
73+
printUsage(argv);
11074
return -1;
11175
}
11276
else if (string(argv[i]) == "--try_use_gpu")
@@ -122,6 +86,10 @@ int parseCmdArgs(int argc, char** argv)
12286
}
12387
i++;
12488
}
89+
else if (string(argv[i]) == "--d3")
90+
{
91+
divide_images = true;
92+
}
12593
else if (string(argv[i]) == "--output")
12694
{
12795
result_name = argv[i + 1];
@@ -148,7 +116,18 @@ int parseCmdArgs(int argc, char** argv)
148116
cout << "Can't read image '" << argv[i] << "'\n";
149117
return -1;
150118
}
151-
imgs.push_back(img);
119+
120+
if (divide_images)
121+
{
122+
Rect rect(0, 0, img.cols / 2, img.rows);
123+
imgs.push_back(img(rect).clone());
124+
rect.x = img.cols / 3;
125+
imgs.push_back(img(rect).clone());
126+
rect.x = img.cols / 2;
127+
imgs.push_back(img(rect).clone());
128+
}
129+
else
130+
imgs.push_back(img);
152131
}
153132
}
154133
return 0;

0 commit comments

Comments
 (0)