1
1
// system includes
2
- #include < getopt.h>
3
2
#include < iostream>
4
3
5
4
// library includes
16
15
#include < opencv2/cvv/dmatch.hpp>
17
16
#include < opencv2/cvv/final_show.hpp>
18
17
18
+ using namespace std ;
19
19
using namespace cv ;
20
20
21
21
template <class T > std::string toString (const T& p_arg)
@@ -42,28 +42,22 @@ main(int argc, char** argv)
42
42
{
43
43
cv::Size* resolution = nullptr ;
44
44
45
- // parse options
46
- const char * optstring = " hr:" ;
47
- int opt;
48
- while ((opt = getopt (argc, argv, optstring)) != -1 ) {
49
- switch (opt) {
50
- case ' h' :
51
- usage ();
52
- return 0 ;
53
- break ;
54
- case ' r' :
55
- {
56
- char dummych;
57
- resolution = new cv::Size ();
58
- if (sscanf (optarg, " %d%c%d" , &resolution->width , &dummych, &resolution->height ) != 3 ) {
59
- printf (" %s not a valid resolution\n " , optarg);
60
- return 1 ;
61
- }
62
- }
63
- break ;
64
- default : /* '?' */
65
- usage ();
66
- return 2 ;
45
+ // parser keys
46
+ const char *keys =
47
+ " { help h usage ? | | show this message }"
48
+ " { resolution r |0x0| resolution to width and height in the format WxH }" ;
49
+ CommandLineParser parser (argc, argv, keys);
50
+ string res (parser.get <string>(" resolution" ));
51
+ if (parser.has (" help" )) {
52
+ usage ();
53
+ return 0 ;
54
+ }
55
+ if (res != " 0x0" ) {
56
+ char dummych;
57
+ resolution = new cv::Size ();
58
+ if (sscanf (res.c_str (), " %d%c%d" , &resolution->width , &dummych, &resolution->height ) != 3 ) {
59
+ cout << res << " not a valid resolution" << endl;
60
+ return 1 ;
67
61
}
68
62
}
69
63
@@ -78,6 +72,7 @@ main(int argc, char** argv)
78
72
printf (" Setting resolution to %dx%d\n " , resolution->width , resolution->height );
79
73
capture.set (CV_CAP_PROP_FRAME_WIDTH, resolution->width );
80
74
capture.set (CV_CAP_PROP_FRAME_HEIGHT, resolution->height );
75
+ delete resolution;
81
76
}
82
77
83
78
0 commit comments