@@ -28,13 +28,6 @@ template<class T> std::string toString(const T& p_arg)
28
28
}
29
29
30
30
31
- void
32
- usage ()
33
- {
34
- printf (" usage: cvv_demo [-r WxH]\n " );
35
- printf (" -h print this help\n " );
36
- printf (" -r WxH change resolution to width W and height H\n " );
37
- }
38
31
39
32
40
33
int
@@ -44,35 +37,29 @@ main(int argc, char** argv)
44
37
45
38
// parser keys
46
39
const char *keys =
47
- " { help h usage ? | | show this message }"
48
- " { resolution r |0x0| resolution to width and height in the format WxH }" ;
40
+ " { help h usage ? | | show this message }"
41
+ " { width W | 0| camera resolution width. leave at 0 to use defaults }"
42
+ " { height H | 0| camera resolution height. leave at 0 to use defaults }" ;
43
+
49
44
CommandLineParser parser (argc, argv, keys);
50
- string res (parser.get <string>(" resolution" ));
51
45
if (parser.has (" help" )) {
52
- usage ();
46
+ parser. printMessage ();
53
47
return 0 ;
54
48
}
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 ;
61
- }
62
- }
49
+ int res_w = parser.get <int >(" width" );
50
+ int res_h = parser.get <int >(" height" );
63
51
64
52
// setup video capture
65
53
cv::VideoCapture capture (0 );
66
54
if (!capture.isOpened ()) {
67
55
std::cout << " Could not open VideoCapture" << std::endl;
68
- return 3 ;
56
+ return 1 ;
69
57
}
70
58
71
- if (resolution) {
72
- printf (" Setting resolution to %dx%d\n " , resolution->width , resolution->height );
73
- capture.set (CV_CAP_PROP_FRAME_WIDTH, resolution->width );
74
- capture.set (CV_CAP_PROP_FRAME_HEIGHT, resolution->height );
75
- delete resolution;
59
+ if (res_w>0 && res_h>0 ) {
60
+ printf (" Setting resolution to %dx%d\n " , res_w, res_h);
61
+ capture.set (CV_CAP_PROP_FRAME_WIDTH, res_w);
62
+ capture.set (CV_CAP_PROP_FRAME_HEIGHT, res_h);
76
63
}
77
64
78
65
0 commit comments