43 #include <visp/vpConfig.h>
44 #include <visp/vpDebug.h>
49 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_OPENCV))
51 #include <visp/vpImage.h>
52 #include <visp/vpImageIo.h>
53 #include <visp/vpParseArgv.h>
54 #include <visp/vpIoTools.h>
56 #include <visp/vpDisplayOpenCV.h>
57 #include <visp/vpDisplayGTK.h>
58 #include <visp/vpDisplayX.h>
59 #include <visp/vpDisplayGDI.h>
60 #include <visp/vpDisplayD3D.h>
70 #define GETOPTARGS "i:hlt:dc"
90 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype)
93 Test video devices or display.\n\
96 %s [-i <input image path>] \n\
97 [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
102 case vpX11: display =
"X11";
break;
103 case vpGTK: display =
"GTK";
break;
104 case vpGDI: display =
"GDI";
break;
105 case vpD3D: display =
"D3D";
break;
106 case vpCV: display =
"CV";
break;
111 -i <input image path> %s\n\
112 Set image input path.\n\
113 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
114 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
115 Setting the VISP_INPUT_IMAGE_PATH environment\n\
116 variable produces the same behaviour than using\n\
119 -t <type of video device> \"%s\"\n\
120 String specifying the video device to use.\n\
122 \"X11\": only on UNIX platforms,\n\
123 \"GTK\": on all plaforms,\n\
124 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
125 \"D3D\": only on Windows platform (Direct3D).\n\
126 \"CV\" : (OpenCV).\n\
129 Disable the mouse click. Useful to automaze the \n\
130 execution of this program without humain intervention.\n\
133 Turn off the display.\n\
136 Print the list of video-devices available and exit.\n\
139 Print the help.\n\n",
140 ipath.c_str(), display.c_str());
143 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
160 bool getOptions(
int argc,
const char **argv,
161 std::string &ipath, vpDisplayType &dtype,
bool &list,
162 bool &click_allowed,
bool &display )
166 std::string sDisplayType;
170 case 'i': ipath = optarg;
break;
171 case 'l': list =
true;
break;
172 case 't': sDisplayType = optarg;
174 if (sDisplayType.compare(
"X11") == 0) {
177 else if (sDisplayType.compare(
"GTK") == 0) {
180 else if (sDisplayType.compare(
"GDI") == 0) {
183 else if (sDisplayType.compare(
"D3D") == 0) {
186 else if (sDisplayType.compare(
"CV") == 0) {
191 case 'h': usage(argv[0], NULL, ipath,dtype);
return false;
break;
192 case 'c': click_allowed =
false;
break;
193 case 'd': display =
false;
break;
196 usage(argv[0], optarg, ipath,dtype);
return false;
break;
201 if ((c == 1) || (c == -1)) {
203 usage(argv[0], NULL, ipath, dtype);
204 std::cerr <<
"ERROR: " << std::endl;
205 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
213 main(
int argc,
const char ** argv)
216 std::string env_ipath;
217 std::string opt_ipath;
218 bool opt_list =
false;
219 vpDisplayType opt_dtype;
221 std::string filename;
222 bool opt_click_allowed =
true;
223 bool opt_display =
true;
226 #if defined VISP_HAVE_GTK
228 #elif defined VISP_HAVE_X11
230 #elif defined VISP_HAVE_GDI
232 #elif defined VISP_HAVE_D3D9
234 #elif defined VISP_HAVE_OPENCV
239 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
244 if (! env_ipath.empty())
248 if (getOptions(argc, argv, opt_ipath, opt_dtype, opt_list,
249 opt_click_allowed, opt_display) ==
false) {
255 unsigned nbDevices = 0;
256 std::cout <<
"List of video-devices available: \n";
257 #if defined VISP_HAVE_GTK
258 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
261 #if defined VISP_HAVE_X11
262 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
265 #if defined VISP_HAVE_GDI
266 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
269 #if defined VISP_HAVE_D3D9
270 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
273 #if defined VISP_HAVE_OPENCV
274 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
278 std::cout <<
" No display is available\n";
285 if (!opt_ipath.empty())
290 if (!opt_ipath.empty() && !env_ipath.empty()) {
291 if (ipath != env_ipath) {
292 std::cout << std::endl
293 <<
"WARNING: " << std::endl;
294 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
295 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
296 <<
" we skip the environment variable." << std::endl;
301 if (opt_ipath.empty() && env_ipath.empty()){
302 usage(argv[0], NULL, ipath, opt_dtype);
303 std::cerr << std::endl
304 <<
"ERROR:" << std::endl;
305 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
307 <<
" environment variable to specify the location of the " << std::endl
308 <<
" image path where test images are located." << std::endl << std::endl;
319 vpCTRACE <<
"Load " << filename << std::endl;
324 vpCTRACE <<
"Load " << filename << std::endl;
333 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
334 #if defined VISP_HAVE_X11
337 std::cout <<
" Sorry, X11 video device is not available.\n";
338 std::cout <<
"Use \"" << argv[0]
339 <<
" -l\" to print the list of available devices.\n";
344 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
345 #if defined VISP_HAVE_GTK
348 std::cout <<
" Sorry, GTK video device is not available.\n";
349 std::cout <<
"Use \"" << argv[0]
350 <<
" -l\" to print the list of available devices.\n";
355 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
356 #if defined VISP_HAVE_GDI
359 std::cout <<
" Sorry, GDI video device is not available.\n";
360 std::cout <<
"Use \"" << argv[0]
361 <<
" -l\" to print the list of available devices.\n";
366 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
367 #if defined VISP_HAVE_D3D9
370 std::cout <<
" Sorry, D3D video device is not available.\n";
371 std::cout <<
"Use \"" << argv[0]
372 <<
" -l\" to print the list of available devices.\n";
377 std::cout <<
"Requested OpenCV display functionnalities..." << std::endl;
378 #if defined VISP_HAVE_OPENCV
381 std::cout <<
" Sorry, OpenCV video device is not available.\n";
382 std::cout <<
"Use \"" << argv[0]
383 <<
" -l\" to print the list of available devices.\n";
392 display->
init(I, 100, 100,
"Display...") ;
402 std::cout <<
"A click to continue...\n";
403 if ( opt_click_allowed )
412 display->
init(I, 100, 100);
422 std::cout <<
"A click to continue...\n";
423 if ( opt_click_allowed )
431 display->
init(Irgba, 100, 100,
"Color display...");
442 std::cout <<
"A click to continue...\n";
443 if ( opt_click_allowed )
446 display->
close(Irgba);
452 display->
init(Irgba, 100, 100);
463 std::cout <<
"A click to exit...\n";
464 if ( opt_click_allowed )