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*/
42
1
43
- #include < iostream>
44
- #include < fstream>
45
2
#include " opencv2/imgcodecs.hpp"
46
3
#include " opencv2/highgui.hpp"
47
4
#include " opencv2/stitching.hpp"
48
5
6
+ #include < iostream>
7
+
49
8
using namespace std ;
50
9
using namespace cv ;
51
10
52
11
bool try_use_gpu = false ;
12
+ bool divide_images = false ;
53
13
Stitcher::Mode mode = Stitcher::PANORAMA;
54
14
vector<Mat> imgs;
55
15
string result_name = " result.jpg" ;
56
16
57
- void printUsage ();
17
+ void printUsage (char ** argv );
58
18
int parseCmdArgs (int argc, char ** argv);
59
19
60
20
int main (int argc, char * argv[])
@@ -73,40 +33,44 @@ int main(int argc, char* argv[])
73
33
}
74
34
75
35
imwrite (result_name, pano);
36
+ cout << " stitching completed successfully\n " << result_name << " saved!" ;
76
37
return 0 ;
77
38
}
78
39
79
40
80
- void printUsage ()
41
+ void printUsage (char ** argv )
81
42
{
82
43
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" ;
95
58
}
96
59
97
60
98
61
int parseCmdArgs (int argc, char ** argv)
99
62
{
100
63
if (argc == 1 )
101
64
{
102
- printUsage ();
65
+ printUsage (argv );
103
66
return -1 ;
104
67
}
68
+
105
69
for (int i = 1 ; i < argc; ++i)
106
70
{
107
71
if (string (argv[i]) == " --help" || string (argv[i]) == " /?" )
108
72
{
109
- printUsage ();
73
+ printUsage (argv );
110
74
return -1 ;
111
75
}
112
76
else if (string (argv[i]) == " --try_use_gpu" )
@@ -122,6 +86,10 @@ int parseCmdArgs(int argc, char** argv)
122
86
}
123
87
i++;
124
88
}
89
+ else if (string (argv[i]) == " --d3" )
90
+ {
91
+ divide_images = true ;
92
+ }
125
93
else if (string (argv[i]) == " --output" )
126
94
{
127
95
result_name = argv[i + 1 ];
@@ -148,7 +116,18 @@ int parseCmdArgs(int argc, char** argv)
148
116
cout << " Can't read image '" << argv[i] << " '\n " ;
149
117
return -1 ;
150
118
}
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);
152
131
}
153
132
}
154
133
return 0 ;
0 commit comments