Skip to content

Commit ff9d313

Browse files
committed
Merge pull request #1800 from berak:fix_cvv_demo
2 parents 4070b5f + 502970b commit ff9d313

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

modules/cvv/samples/cvv_demo.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ template<class T> std::string toString(const T& p_arg)
2828
}
2929

3030

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-
}
3831

3932

4033
int
@@ -44,35 +37,29 @@ main(int argc, char** argv)
4437

4538
// parser keys
4639
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+
4944
CommandLineParser parser(argc, argv, keys);
50-
string res(parser.get<string>("resolution"));
5145
if (parser.has("help")) {
52-
usage();
46+
parser.printMessage();
5347
return 0;
5448
}
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");
6351

6452
// setup video capture
6553
cv::VideoCapture capture(0);
6654
if (!capture.isOpened()) {
6755
std::cout << "Could not open VideoCapture" << std::endl;
68-
return 3;
56+
return 1;
6957
}
7058

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);
7663
}
7764

7865

0 commit comments

Comments
 (0)