提交 af806bc8 编写于 作者: V Vladimir Dudnik

replaced macros with template func

上级 f0197006
......@@ -296,4 +296,8 @@ private:
// main func
ENTRY_POINT(D3D10WinApp, "D3D10 interop sample");
int main(int argc, char** argv)
{
std::string title = "D3D10 interop sample";
return d3d_app<D3D10WinApp>(argc, argv, title);
}
......@@ -302,4 +302,8 @@ private:
// main func
ENTRY_POINT(D3D11WinApp, "D3D11 interop sample");
int main(int argc, char** argv)
{
std::string title = "D3D11 interop sample";
return d3d_app<D3D11WinApp>(argc, argv, title);
}
......@@ -294,4 +294,8 @@ private:
// main func
ENTRY_POINT(D3D9WinApp, "D3D9 interop sample");
int main(int argc, char** argv)
{
std::string title = "D3D9 interop sample";
return d3d_app<D3D9WinApp>(argc, argv, title);
}
......@@ -295,4 +295,8 @@ private:
// main func
ENTRY_POINT(D3D9ExWinApp, "D3D9Ex interop sample");
int main(int argc, char** argv)
{
std::string title = "D3D9Ex interop sample";
return d3d_app<D3D9ExWinApp>(argc, argv, title);
}
......@@ -113,73 +113,74 @@ protected:
};
#define ENTRY_POINT(type, title) \
static void help() \
{ \
printf( \
"\nSample demonstrating interoperability of DirectX and OpenCL with OpenCV.\n" \
"Hot keys: \n" \
" 0 - no processing\n" \
" 1 - blur DX surface on CPU through OpenCV\n" \
" 2 - blur DX surface on GPU through OpenCV using OpenCL\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 }" \
}; \
\
\
int main(int argc, char** argv) \
{ \
static void help()
{
printf(
"\nSample demonstrating interoperability of DirectX and OpenCL with OpenCV.\n"
"Hot keys: \n"
" 0 - no processing\n"
" 1 - blur DX surface on CPU through OpenCV\n"
" 2 - blur DX surface on GPU through OpenCV using OpenCL\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 }"
};
template <typename TApp>
int d3d_app(int argc, char** argv, std::string& title)
{
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(); \
\
parser.printMessage(); \
\
cv::VideoCapture cap; \
\
if (useCamera) \
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 height = (int)cap.get(CAP_PROP_FRAME_HEIGHT); \
\
std::string wndname = title; \
\
type app(width, height, wndname, cap); \
\
try \
{ \
app.create(); \
return app.run(); \
} \
\
catch (cv::Exception& e) \
{ \
std::cerr << "Exception: " << e.what() << std::endl; \
return 10; \
} \
\
catch (...) \
{ \
std::cerr << "FATAL ERROR: Unknown exception" << std::endl; \
return 11; \
} \
if (showHelp)
help();
parser.printMessage();
cv::VideoCapture cap;
if (useCamera)
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 height = (int)cap.get(CAP_PROP_FRAME_HEIGHT);
std::string wndname = title;
TApp app(width, height, wndname, cap);
try
{
app.create();
return app.run();
}
catch (cv::Exception& e)
{
std::cerr << "Exception: " << e.what() << std::endl;
return 10;
}
catch (...)
{
std::cerr << "FATAL ERROR: Unknown exception" << std::endl;
return 11;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册