38 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpDebug.h>
45 #if (defined (VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_OPENCV))
47 #include <visp3/core/vpImage.h>
48 #include <visp3/io/vpImageIo.h>
49 #include <visp3/io/vpParseArgv.h>
50 #include <visp3/core/vpIoTools.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/gui/vpDisplayGDI.h>
56 #include <visp3/gui/vpDisplayD3D.h>
66 #define GETOPTARGS "i:hlt:dc"
76 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype);
77 bool getOptions(
int argc,
const char **argv,
78 std::string &ipath, vpDisplayType &dtype,
bool &list,
79 bool &click_allowed,
bool &
display );
91 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype)
94 Test click functionnalities in video devices or display.\n\
97 %s [-i <input image path>] \n\
98 [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
103 case vpX11: display =
"X11";
break;
104 case vpGTK: display =
"GTK";
break;
105 case vpGDI: display =
"GDI";
break;
106 case vpD3D: display =
"D3D";
break;
107 case vpCV: display =
"CV";
break;
112 -i <input image path> %s\n\
113 Set image input path.\n\
114 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
115 and \"ViSP-images/Klimt/Klimt.ppm\" images.\n\
116 Setting the VISP_INPUT_IMAGE_PATH environment\n\
117 variable produces the same behaviour than using\n\
120 -t <type of video device> \"%s\"\n\
121 String specifying the video device to use.\n\
123 \"X11\": only on UNIX platforms,\n\
124 \"GTK\": on all plaforms,\n\
125 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
126 \"D3D\": only on Windows platform (Direct3D).\n\
127 \"CV\" : (OpenCV).\n\
130 Print the list of video-devices available and exit.\n\
133 Disable the mouse click. Useful to automaze the \n\
134 execution of this program without humain intervention.\n\
137 Turn off the display.\n\
140 Print the help.\n\n",
141 ipath.c_str(), display.c_str());
144 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";
288 if (!opt_ipath.empty())
293 if (!opt_ipath.empty() && !env_ipath.empty()) {
294 if (ipath != env_ipath) {
295 std::cout << std::endl
296 <<
"WARNING: " << std::endl;
297 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
298 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
299 <<
" we skip the environment variable." << std::endl;
304 if (opt_ipath.empty() && env_ipath.empty()){
305 usage(argv[0], NULL, ipath, opt_dtype);
306 std::cerr << std::endl
307 <<
"ERROR:" << std::endl;
308 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
310 <<
" environment variable to specify the location of the " << std::endl
311 <<
" image path where test images are located." << std::endl << std::endl;
320 vpCTRACE <<
"Load " << filename << std::endl;
328 std::cout <<
"Requested X11 display functionnalities..." << std::endl;
329 #if defined VISP_HAVE_X11
332 std::cout <<
" Sorry, X11 video device is not available.\n";
333 std::cout <<
"Use \"" << argv[0]
334 <<
" -l\" to print the list of available devices.\n";
339 std::cout <<
"Requested GTK display functionnalities..." << std::endl;
340 #if defined VISP_HAVE_GTK
343 std::cout <<
" Sorry, GTK video device is not available.\n";
344 std::cout <<
"Use \"" << argv[0]
345 <<
" -l\" to print the list of available devices.\n";
350 std::cout <<
"Requested GDI display functionnalities..." << std::endl;
351 #if defined VISP_HAVE_GDI
354 std::cout <<
" Sorry, GDI video device is not available.\n";
355 std::cout <<
"Use \"" << argv[0]
356 <<
" -l\" to print the list of available devices.\n";
361 std::cout <<
"Requested D3D display functionnalities..." << std::endl;
362 #if defined VISP_HAVE_D3D9
365 std::cout <<
" Sorry, D3D video device is not available.\n";
366 std::cout <<
"Use \"" << argv[0]
367 <<
" -l\" to print the list of available devices.\n";
372 std::cout <<
"Requested OpenCV display functionnalities..." << std::endl;
373 #if defined(VISP_HAVE_OPENCV)
376 std::cout <<
" Sorry, OpenCV video device is not available.\n";
377 std::cout <<
"Use \"" << argv[0]
378 <<
" -l\" to print the list of available devices.\n";
388 display->init(I, 100, 100,
"Display...") ;
398 if ( opt_click_allowed ){
399 std::cout <<
"Click on a pixel to get his coordinates...\n";
403 std::cout <<
" You click down on pixel (" << ip <<
") ";
411 std::cout <<
" You click up on pixel (" << ip <<
") ";
419 std::cout <<
" Pointer poisition : " << ip << std::endl;
420 std::cout <<
"A click to exit...\n";
Class that defines generic functionnalities for display.
static bool getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
vpDisplayGDI()
Basic constructor.
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClickUp(const vpImage< unsigned char > &I, vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
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 3rd party. Thus to enable this class Direct3D should be installed...
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void read(vpImage< unsigned char > &I, const std::string &filename)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...