added command line processing

This commit is contained in:
Alexey Ershov 2015-07-29 13:51:03 +03:00
parent b102bc6678
commit 0a4830b3d5

View File

@ -494,20 +494,64 @@ private:
cv::String m_oclDevName; cv::String m_oclDevName;
}; };
static void help()
{
printf(
"\nSample demonstrating interoperability of OpenGL and OpenCL with OpenCV.\n"
"Hot keys: \n"
" SPACE - turn processing on/off\n"
" 1 - process GL data through OpenCV on CPU\n"
" 2 - process GL data through OpenCV on GPU (via OpenCL)\n"
" 9 - toggle use of GL texture/GL buffer\n"
" ESC - exit\n\n");
}
static const char* keys =
{
"{c camera | true | use camera or not}"
"{f file | | movie file name }"
"{h help | false | print help info }"
};
using namespace cv; using namespace cv;
using namespace std;
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
cv::CommandLineParser parser(argc, argv, keys); \
bool useCamera = parser.has("camera"); \
string file = parser.get<string>("file"); \
bool showHelp = parser.get<bool>("help"); \
if (showHelp)
{
help();
return 0;
}
parser.printMessage();
cv::VideoCapture cap; cv::VideoCapture cap;
if (argc > 1) if (useCamera)
cap.open(argv[1]);
else
cap.open(0); cap.open(0);
else
cap.open(file.c_str());
if (!cap.isOpened())
{
printf("can not open camera or video file\n");
return -1;
}
int width = (int)cap.get(CAP_PROP_FRAME_WIDTH); int width = (int)cap.get(CAP_PROP_FRAME_WIDTH);
int height = (int)cap.get(CAP_PROP_FRAME_HEIGHT); int height = (int)cap.get(CAP_PROP_FRAME_HEIGHT);
std::string wndname = "WGL Window";
#if defined(WIN32) || defined(_WIN32)
string wndname = "WGL Window";
#elif defined(__linux__)
string wndname = "GLX Window";
#endif
GLWinApp app(width, height, wndname, cap); GLWinApp app(width, height, wndname, cap);
@ -518,12 +562,12 @@ int main(int argc, char** argv)
} }
catch (cv::Exception& e) catch (cv::Exception& e)
{ {
std::cerr << "Exception: " << e.what() << std::endl; cerr << "Exception: " << e.what() << endl;
return 10; return 10;
} }
catch (...) catch (...)
{ {
std::cerr << "FATAL ERROR: Unknown exception" << std::endl; cerr << "FATAL ERROR: Unknown exception" << endl;
return 11; return 11;
} }
} }