Commit a2769e15 authored by Hamdi Sahloul's avatar Hamdi Sahloul

CVV - Replace getopt with CommandLineParser

parent bccbec79
// system includes // system includes
#include <getopt.h>
#include <iostream> #include <iostream>
// library includes // library includes
...@@ -16,6 +15,7 @@ ...@@ -16,6 +15,7 @@
#include <opencv2/cvv/dmatch.hpp> #include <opencv2/cvv/dmatch.hpp>
#include <opencv2/cvv/final_show.hpp> #include <opencv2/cvv/final_show.hpp>
using namespace std;
using namespace cv; using namespace cv;
template<class T> std::string toString(const T& p_arg) template<class T> std::string toString(const T& p_arg)
...@@ -42,30 +42,24 @@ main(int argc, char** argv) ...@@ -42,30 +42,24 @@ main(int argc, char** argv)
{ {
cv::Size* resolution = nullptr; cv::Size* resolution = nullptr;
// parse options // parser keys
const char* optstring = "hr:"; const char *keys =
int opt; "{ help h usage ? | | show this message }"
while ((opt = getopt(argc, argv, optstring)) != -1) { "{ resolution r |0x0| resolution to width and height in the format WxH }";
switch (opt) { CommandLineParser parser(argc, argv, keys);
case 'h': string res(parser.get<string>("resolution"));
if (parser.has("help")) {
usage(); usage();
return 0; return 0;
break; }
case 'r': if (res != "0x0") {
{
char dummych; char dummych;
resolution = new cv::Size(); resolution = new cv::Size();
if (sscanf(optarg, "%d%c%d", &resolution->width, &dummych, &resolution->height) != 3) { if (sscanf(res.c_str(), "%d%c%d", &resolution->width, &dummych, &resolution->height) != 3) {
printf("%s not a valid resolution\n", optarg); cout << res << " not a valid resolution" << endl;
return 1; return 1;
} }
} }
break;
default: /* '?' */
usage();
return 2;
}
}
// setup video capture // setup video capture
cv::VideoCapture capture(0); cv::VideoCapture capture(0);
...@@ -78,6 +72,7 @@ main(int argc, char** argv) ...@@ -78,6 +72,7 @@ main(int argc, char** argv)
printf("Setting resolution to %dx%d\n", resolution->width, resolution->height); printf("Setting resolution to %dx%d\n", resolution->width, resolution->height);
capture.set(CV_CAP_PROP_FRAME_WIDTH, resolution->width); capture.set(CV_CAP_PROP_FRAME_WIDTH, resolution->width);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, resolution->height); capture.set(CV_CAP_PROP_FRAME_HEIGHT, resolution->height);
delete resolution;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment