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"
80 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype);
81 bool getOptions(
int argc,
const char **argv,
82 std::string &ipath, vpDisplayType &dtype,
bool &list,
83 bool &click_allowed,
bool &display );
95 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype)
98 Test video devices or display.\n\
101 %s [-i <input image path>] \n\
102 [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
107 case vpX11: display =
"X11";
break;
108 case vpGTK: display =
"GTK";
break;
109 case vpGDI: display =
"GDI";
break;
110 case vpD3D: display =
"D3D";
break;
111 case vpCV: display =
"CV";
break;
116 -i <input image path> %s\n\
117 Set image input path.\n\
118 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
119 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
120 Setting the VISP_INPUT_IMAGE_PATH environment\n\
121 variable produces the same behaviour than using\n\
124 -t <type of video device> \"%s\"\n\
125 String specifying the video device to use.\n\
127 \"X11\": only on UNIX platforms,\n\
128 \"GTK\": on all plaforms,\n\
129 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
130 \"D3D\": only on Windows platform (Direct3D).\n\
131 \"CV\" : (OpenCV).\n\
134 Disable the mouse click. Useful to automaze the \n\
135 execution of this program without humain intervention.\n\
138 Turn off the display.\n\
141 Print the list of video-devices available and exit.\n\
144 Print the help.\n\n",
145 ipath.c_str(), display.c_str());
148 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
165 bool getOptions(
int argc,
const char **argv,
166 std::string &ipath, vpDisplayType &dtype,
bool &list,
167 bool &click_allowed,
bool &display )
171 std::string sDisplayType;
175 case 'i': ipath = optarg_;
break;
176 case 'l': list =
true;
break;
177 case 't': sDisplayType = optarg_;
179 if (sDisplayType.compare(
"X11") == 0) {
182 else if (sDisplayType.compare(
"GTK") == 0) {
185 else if (sDisplayType.compare(
"GDI") == 0) {
188 else if (sDisplayType.compare(
"D3D") == 0) {
191 else if (sDisplayType.compare(
"CV") == 0) {
196 case 'h': usage(argv[0], NULL, ipath,dtype);
return false;
break;
197 case 'c': click_allowed =
false;
break;
198 case 'd': display =
false;
break;
201 usage(argv[0], optarg_, ipath,dtype);
return false;
break;
206 if ((c == 1) || (c == -1)) {
208 usage(argv[0], NULL, ipath, dtype);
209 std::cerr <<
"ERROR: " << std::endl;
210 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
218 main(
int argc,
const char ** argv)
221 std::string env_ipath;
222 std::string opt_ipath;
223 bool opt_list =
false;
224 vpDisplayType opt_dtype;
226 std::string filename;
227 bool opt_click_allowed =
true;
228 bool opt_display =
true;
231 #if defined VISP_HAVE_GTK
233 #elif defined VISP_HAVE_X11
235 #elif defined VISP_HAVE_GDI
237 #elif defined VISP_HAVE_D3D9
239 #elif defined VISP_HAVE_OPENCV
247 if (! env_ipath.empty())
251 if (getOptions(argc, argv, opt_ipath, opt_dtype, opt_list,
252 opt_click_allowed, opt_display) ==
false) {
258 unsigned nbDevices = 0;
259 std::cout <<
"List of video-devices available: \n";
260 #if defined VISP_HAVE_GTK
261 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
264 #if defined VISP_HAVE_X11
265 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
268 #if defined VISP_HAVE_GDI
269 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
272 #if defined VISP_HAVE_D3D9
273 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
276 #if defined VISP_HAVE_OPENCV
277 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
281 std::cout <<
" No display is available\n";
287 if (!opt_ipath.empty())
292 if (!opt_ipath.empty() && !env_ipath.empty()) {
293 if (ipath != env_ipath) {
294 std::cout << std::endl
295 <<
"WARNING: " << std::endl;
296 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
297 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
298 <<
" we skip the environment variable." << std::endl;
303 if (opt_ipath.empty() && env_ipath.empty()){
304 usage(argv[0], NULL, ipath, opt_dtype);
305 std::cerr << std::endl
306 <<
"ERROR:" << std::endl;
307 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
309 <<
" environment variable to specify the location of the " << std::endl
310 <<
" image path where test images are located." << std::endl << std::endl;
321 vpCTRACE <<
"Load " << filename << std::endl;
326 vpCTRACE <<
"Load " << filename << std::endl;
335 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
336 #if defined VISP_HAVE_X11
339 std::cout <<
" Sorry, X11 video device is not available.\n";
340 std::cout <<
"Use \"" << argv[0]
341 <<
" -l\" to print the list of available devices.\n";
346 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
347 #if defined VISP_HAVE_GTK
350 std::cout <<
" Sorry, GTK video device is not available.\n";
351 std::cout <<
"Use \"" << argv[0]
352 <<
" -l\" to print the list of available devices.\n";
357 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
358 #if defined VISP_HAVE_GDI
361 std::cout <<
" Sorry, GDI video device is not available.\n";
362 std::cout <<
"Use \"" << argv[0]
363 <<
" -l\" to print the list of available devices.\n";
368 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
369 #if defined VISP_HAVE_D3D9
372 std::cout <<
" Sorry, D3D video device is not available.\n";
373 std::cout <<
"Use \"" << argv[0]
374 <<
" -l\" to print the list of available devices.\n";
379 std::cout <<
"Requested OpenCV display functionnalities..." << std::endl;
380 #if defined(VISP_HAVE_OPENCV)
383 std::cout <<
" Sorry, OpenCV video device is not available.\n";
384 std::cout <<
"Use \"" << argv[0]
385 <<
" -l\" to print the list of available devices.\n";
394 display->
init(I, 100, 100,
"Display...") ;
404 std::cout <<
"A click to continue...\n";
405 if ( opt_click_allowed )
414 display->
init(I, 100, 100);
424 std::cout <<
"A click to continue...\n";
425 if ( opt_click_allowed )
433 display->
init(Irgba, 100, 100,
"Color display...");
444 std::cout <<
"A click to continue...\n";
445 if ( opt_click_allowed )
448 display->
close(Irgba);
454 display->
init(Irgba, 100, 100);
465 std::cout <<
"A click to exit...\n";
466 if ( opt_click_allowed )
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.
static void close(vpImage< unsigned char > &I)
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
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
static void read(vpImage< unsigned char > &I, const char *filename)