43 #include <visp/vpConfig.h>
44 #include <visp/vpImage.h>
45 #include <visp/vpDisplay.h>
46 #include <visp/vpDisplayOpenCV.h>
47 #include <visp/vpDisplayGTK.h>
48 #include <visp/vpDisplayX.h>
49 #include <visp/vpDisplayGDI.h>
50 #include <visp/vpDisplayD3D.h>
51 #include <visp/vpParseArgv.h>
54 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_OPENCV))
65 #define GETOPTARGS "hlt:dc"
75 void usage(
const char *name,
const char *badparam, vpDisplayType &dtype);
76 bool getOptions(
int argc,
const char **argv, vpDisplayType &dtype,
bool &list,
bool &click_allowed,
bool &display);
87 void usage(
const char *name,
const char *badparam, vpDisplayType &dtype)
90 Test to open video devices or display.\n\
93 %s [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
98 case vpX11: display =
"X11";
break;
99 case vpGTK: display =
"GTK";
break;
100 case vpGDI: display =
"GDI";
break;
101 case vpD3D: display =
"D3D";
break;
102 case vpCV: display =
"CV";
break;
107 -t <type of video device> \"%s\"\n\
108 String specifying the video device to use.\n\
110 \"X11\": only on UNIX platforms,\n\
111 \"GTK\": on all plaforms,\n\
112 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
113 \"D3D\": only on Windows platform (Direct3D).\n\
114 \"CV\" : (OpenCV).\n\
117 Disable the mouse click. Useful to automaze the \n\
118 execution of this program without humain intervention.\n\
121 Turn off the display.\n\
124 Print the list of video-devices available and exit.\n\
127 Print the help.\n\n",
131 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
147 bool getOptions(
int argc,
const char **argv,
148 vpDisplayType &dtype,
bool &list,
149 bool &click_allowed,
bool &display)
153 std::string sDisplayType;
157 case 'l': list =
true;
break;
158 case 't': sDisplayType = optarg_;
160 if (sDisplayType.compare(
"X11") == 0) {
163 else if (sDisplayType.compare(
"GTK") == 0) {
166 else if (sDisplayType.compare(
"GDI") == 0) {
169 else if (sDisplayType.compare(
"D3D") == 0) {
172 else if (sDisplayType.compare(
"CV") == 0) {
177 case 'h': usage(argv[0], NULL, dtype);
return false;
break;
178 case 'c': click_allowed =
false;
break;
179 case 'd': display =
false;
break;
182 usage(argv[0], optarg_, dtype);
return false;
break;
186 if ((c == 1) || (c == -1)) {
188 usage(argv[0], NULL, dtype);
189 std::cerr <<
"ERROR: " << std::endl;
190 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
197 int main(
int argc,
const char ** argv)
200 bool opt_list =
false;
201 vpDisplayType opt_dtype;
202 bool opt_click_allowed =
true;
203 bool opt_display =
true;
206 #if defined VISP_HAVE_GTK
208 #elif defined VISP_HAVE_X11
210 #elif defined VISP_HAVE_GDI
212 #elif defined VISP_HAVE_D3D9
214 #elif defined VISP_HAVE_OPENCV
219 if (getOptions(argc, argv, opt_dtype, opt_list,
220 opt_click_allowed, opt_display) ==
false) {
226 unsigned nbDevices = 0;
227 std::cout <<
"List of video-devices available: \n";
228 #if defined VISP_HAVE_GTK
229 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
232 #if defined VISP_HAVE_X11
233 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
236 #if defined VISP_HAVE_GDI
237 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
240 #if defined VISP_HAVE_D3D9
241 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
244 #if defined VISP_HAVE_OPENCV
245 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
249 std::cout <<
" No display is available\n";
265 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
266 #if defined VISP_HAVE_X11
270 std::cout <<
" Sorry, X11 video device is not available.\n";
271 std::cout <<
"Use \"" << argv[0]
272 <<
" -l\" to print the list of available devices.\n";
277 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
278 #if defined VISP_HAVE_GTK
282 std::cout <<
" Sorry, GTK video device is not available.\n";
283 std::cout <<
"Use \"" << argv[0]
284 <<
" -l\" to print the list of available devices.\n";
289 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
290 #if defined VISP_HAVE_GDI
294 std::cout <<
" Sorry, GDI video device is not available.\n";
295 std::cout <<
"Use \"" << argv[0]
296 <<
" -l\" to print the list of available devices.\n";
301 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
302 #if defined VISP_HAVE_D3D9
306 std::cout <<
" Sorry, D3D video device is not available.\n";
307 std::cout <<
"Use \"" << argv[0]
308 <<
" -l\" to print the list of available devices.\n";
313 std::cout <<
"Requested OpenCV display functionnalities..." << std::endl;
314 #if defined(VISP_HAVE_OPENCV)
318 std::cout <<
" Sorry, OpenCV video device is not available.\n";
319 std::cout <<
"Use \"" << argv[0]
320 <<
" -l\" to print the list of available devices.\n";
327 int winx1 = 100, winy1 = 200;
328 d1->
init(I1, winx1, winy1,
"Display 1");
330 int winx2 = winx1+10+(int)I1.getWidth(), winy2 = winy1;
331 d2->init(I2, winx2, winy2,
"Display 2");
340 std::cout <<
"A click in display 1 to exit..." << std::endl;
341 if ( opt_click_allowed )
348 std::cout <<
"Catch an exception: " << e << std::endl;
virtual void init(vpImage< unsigned char > &I, int x=-1, int y=-1, const char *title=NULL)=0
Class that defines generic functionnalities for display.
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Display for windows using Direct3D.
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the opencv library.
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
virtual bool getClick(bool blocking=true)=0