34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpDebug.h>
41 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || \
42 defined(VISP_HAVE_OPENCV))
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpIoTools.h>
46 #include <visp3/io/vpImageIo.h>
47 #include <visp3/io/vpParseArgv.h>
49 #include <visp3/gui/vpDisplayD3D.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/gui/vpDisplayX.h>
63 #define GETOPTARGS "i:hlt:dc"
65 #ifdef ENABLE_VISP_NAMESPACE
69 typedef enum { vpX11, vpGTK, vpGDI, vpD3D, vpCV } vpDisplayType;
71 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype);
72 bool getOptions(
int argc,
const char **argv, std::string &ipath, vpDisplayType &dtype,
bool &list,
bool &click_allowed,
85 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype)
88 Test click functionalities in video devices or display.\n\
91 %s [-i <input image path>] \n\
92 [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
117 -i <input image path> %s\n\
118 Set image input path.\n\
119 From this path read \"Klimt/Klimt.pgm\"\n\
120 and \"Klimt/Klimt.ppm\" images.\n\
121 Setting the VISP_INPUT_IMAGE_PATH environment\n\
122 variable produces the same behaviour than using\n\
125 -t <type of video device> \"%s\"\n\
126 String specifying the video device to use.\n\
128 \"X11\": only on UNIX platforms,\n\
129 \"GTK\": on all plaforms,\n\
130 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
131 \"D3D\": only on Windows platform (Direct3D).\n\
132 \"CV\" : (OpenCV).\n\
135 Print the list of video-devices available and exit.\n\
138 Disable the mouse click. Useful to automate the \n\
139 execution of this program without human intervention.\n\
142 Turn off the display.\n\
145 Print the help.\n\n",
146 ipath.c_str(), display.c_str());
149 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
170 bool getOptions(
int argc,
const char **argv, std::string &ipath, vpDisplayType &dtype,
bool &list,
bool &click_allowed,
175 std::string sDisplayType;
186 sDisplayType = optarg_;
188 if (sDisplayType.compare(
"X11") == 0) {
191 else if (sDisplayType.compare(
"GTK") == 0) {
194 else if (sDisplayType.compare(
"GDI") == 0) {
197 else if (sDisplayType.compare(
"D3D") == 0) {
200 else if (sDisplayType.compare(
"CV") == 0) {
206 usage(argv[0],
nullptr, ipath, dtype);
210 click_allowed =
false;
217 usage(argv[0], optarg_, ipath, dtype);
223 if ((c == 1) || (c == -1)) {
225 usage(argv[0],
nullptr, ipath, dtype);
226 std::cerr <<
"ERROR: " << std::endl;
227 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
234 int main(
int argc,
const char **argv)
237 std::string env_ipath;
238 std::string opt_ipath;
239 bool opt_list =
false;
240 vpDisplayType opt_dtype;
242 std::string filename;
243 bool opt_click_allowed =
true;
244 bool opt_display =
true;
247 #if defined(VISP_HAVE_GTK)
249 #elif defined(VISP_HAVE_X11)
251 #elif defined(VISP_HAVE_GDI)
253 #elif defined(VISP_HAVE_D3D9)
255 #elif defined VISP_HAVE_OPENCV
264 if (!env_ipath.empty())
268 if (getOptions(argc, argv, opt_ipath, opt_dtype, opt_list, opt_click_allowed, opt_display) ==
false) {
274 unsigned nbDevices = 0;
275 std::cout <<
"List of video-devices available: \n";
276 #if defined(VISP_HAVE_GTK)
277 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
280 #if defined(VISP_HAVE_X11)
281 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
284 #if defined(VISP_HAVE_GDI)
286 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
289 #if defined(VISP_HAVE_D3D9)
290 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
293 #if defined VISP_HAVE_OPENCV
294 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
298 std::cout <<
" No display is available\n";
304 if (!opt_ipath.empty())
309 if (!opt_ipath.empty() && !env_ipath.empty()) {
310 if (ipath != env_ipath) {
311 std::cout << std::endl <<
"WARNING: " << std::endl;
312 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
313 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
314 <<
" we skip the environment variable." << std::endl;
319 if (opt_ipath.empty() && env_ipath.empty()) {
320 usage(argv[0],
nullptr, ipath, opt_dtype);
321 std::cerr << std::endl <<
"ERROR:" << std::endl;
322 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
323 <<
" environment variable to specify the location of the " << std::endl
324 <<
" image path where test images are located." << std::endl
334 vpCTRACE <<
"Load " << filename << std::endl;
342 std::cout <<
"Requested X11 display functionalities..." << std::endl;
343 #if defined(VISP_HAVE_X11)
344 display =
new vpDisplayX;
346 std::cout <<
" Sorry, X11 video device is not available.\n";
347 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
352 std::cout <<
"Requested GTK display functionalities..." << std::endl;
353 #if defined(VISP_HAVE_GTK)
356 std::cout <<
" Sorry, GTK video device is not available.\n";
357 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
362 std::cout <<
"Requested GDI display functionalities..." << std::endl;
363 #if defined(VISP_HAVE_GDI)
367 std::cout <<
" Sorry, GDI video device is not available.\n";
368 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
373 std::cout <<
"Requested D3D display functionalities..." << std::endl;
374 #if defined(VISP_HAVE_D3D9)
377 std::cout <<
" Sorry, D3D video device is not available.\n";
378 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
383 std::cout <<
"Requested OpenCV display functionalities..." << std::endl;
384 #if defined(HAVE_OPENCV_HIGHGUI)
387 std::cout <<
" Sorry, OpenCV video device is not available.\n";
388 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
398 display->init(I, 100, 100,
"Display...");
408 if (opt_click_allowed) {
409 std::cout <<
"Click on a pixel to get his coordinates...\n";
413 std::cout <<
" You click down on pixel (" << ip <<
") ";
416 std::cout <<
"with left button.\n";
419 std::cout <<
"with middle button.\n";
422 std::cout <<
"with right button.\n";
428 std::cout <<
" You click up on pixel (" << ip <<
") ";
431 std::cout <<
"with left button.\n";
434 std::cout <<
"with middle button.\n";
437 std::cout <<
"with right button.\n";
443 std::cout <<
" Pointer poisition : " << ip << std::endl;
444 std::cout <<
"A click to exit...\n";
451 vpERROR_TRACE(
"Error while displaying the image");
457 int main() { vpERROR_TRACE(
"You do not have display functionalities..."); }
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Class that defines generic functionalities for display.
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
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 getPointerPosition(const vpImage< unsigned char > &I, vpImagePoint &ip)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)