40 #include <visp3/core/vpConfig.h>
41 #include <visp3/core/vpDebug.h>
46 #if (defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || \
47 defined(VISP_HAVE_OPENCV))
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpIoTools.h>
51 #include <visp3/io/vpImageIo.h>
52 #include <visp3/io/vpParseArgv.h>
54 #include <visp3/gui/vpDisplayD3D.h>
55 #include <visp3/gui/vpDisplayGDI.h>
56 #include <visp3/gui/vpDisplayGTK.h>
57 #include <visp3/gui/vpDisplayOpenCV.h>
58 #include <visp3/gui/vpDisplayX.h>
61 #define GETOPTARGS "i:hlt:dc"
63 #ifdef ENABLE_VISP_NAMESPACE
67 typedef enum { vpX11, vpGTK, vpGDI, vpD3D, vpCV } vpDisplayType;
69 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath, vpDisplayType &dtype,
bool &list,
bool &click_allowed,
83 void usage(
const char *name,
const char *badparam, std::string ipath, vpDisplayType &dtype)
86 Test video devices or display.\n\
89 %s [-i <input image path>] \n\
90 [-t <type of video device>] [-l] [-c] [-d] [-h]\n\
115 -i <input image path> %s\n\
116 Set image input path.\n\
117 From this path read \"Klimt/Klimt.pgm\"\n\
118 and \"Klimt/Klimt.ppm\" images.\n\
119 Setting the VISP_INPUT_IMAGE_PATH environment\n\
120 variable produces the same behaviour than using\n\
123 -t <type of video device> \"%s\"\n\
124 String specifying the video device to use.\n\
126 \"X11\": only on UNIX platforms,\n\
127 \"GTK\": on all plaforms,\n\
128 \"GDI\": only on Windows platform (Graphics Device Interface),\n\
129 \"D3D\": only on Windows platform (Direct3D).\n\
130 \"CV\" : (OpenCV).\n\
133 Disable the mouse click. Useful to automate the \n\
134 execution of this program without human intervention.\n\
137 Turn off the display.\n\
140 Print the list of video-devices available and exit.\n\
143 Print the help.\n\n",
144 ipath.c_str(), display.c_str());
147 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
164 bool getOptions(
int argc,
const char **argv, std::string &ipath, vpDisplayType &dtype,
bool &list,
bool &click_allowed,
169 std::string sDisplayType;
180 sDisplayType = optarg_;
182 if (sDisplayType.compare(
"X11") == 0) {
185 else if (sDisplayType.compare(
"GTK") == 0) {
188 else if (sDisplayType.compare(
"GDI") == 0) {
191 else if (sDisplayType.compare(
"D3D") == 0) {
194 else if (sDisplayType.compare(
"CV") == 0) {
200 usage(argv[0],
nullptr, ipath, dtype);
204 click_allowed =
false;
211 usage(argv[0], optarg_, ipath, dtype);
217 if ((c == 1) || (c == -1)) {
219 usage(argv[0],
nullptr, ipath, dtype);
220 std::cerr <<
"ERROR: " << std::endl;
221 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
228 int main(
int argc,
const char **argv)
231 std::string env_ipath;
232 std::string opt_ipath;
233 bool opt_list =
false;
234 vpDisplayType opt_dtype;
236 std::string filename;
237 bool opt_click_allowed =
true;
238 bool opt_display =
true;
241 #if defined(VISP_HAVE_GTK)
243 #elif defined(VISP_HAVE_X11)
245 #elif defined(VISP_HAVE_GDI)
247 #elif defined(VISP_HAVE_D3D9)
249 #elif defined VISP_HAVE_OPENCV
258 if (!env_ipath.empty())
262 if (getOptions(argc, argv, opt_ipath, opt_dtype, opt_list, opt_click_allowed, opt_display) ==
false) {
268 unsigned nbDevices = 0;
269 std::cout <<
"List of video-devices available: \n";
270 #if defined(VISP_HAVE_GTK)
271 std::cout <<
" GTK (use \"-t GTK\" option to use it)\n";
274 #if defined(VISP_HAVE_X11)
275 std::cout <<
" X11 (use \"-t X11\" option to use it)\n";
278 #if defined(VISP_HAVE_GDI)
280 std::cout <<
" GDI (use \"-t GDI\" option to use it)\n";
283 #if defined(VISP_HAVE_D3D9)
284 std::cout <<
" D3D (use \"-t D3D\" option to use it)\n";
287 #if defined VISP_HAVE_OPENCV
288 std::cout <<
" CV (use \"-t CV\" option to use it)\n";
292 std::cout <<
" No display is available\n";
298 if (!opt_ipath.empty())
303 if (!opt_ipath.empty() && !env_ipath.empty()) {
304 if (ipath != env_ipath) {
305 std::cout << std::endl <<
"WARNING: " << std::endl;
306 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
307 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
308 <<
" we skip the environment variable." << std::endl;
313 if (opt_ipath.empty() && env_ipath.empty()) {
314 usage(argv[0],
nullptr, ipath, opt_dtype);
315 std::cerr << std::endl <<
"ERROR:" << std::endl;
316 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
317 <<
" environment variable to specify the location of the " << std::endl
318 <<
" image path where test images are located." << std::endl
330 vpCTRACE <<
"Load " << filename << std::endl;
335 vpCTRACE <<
"Load " << filename << std::endl;
343 std::cout <<
"Requested X11 display functionalities..." << std::endl;
344 #if defined(VISP_HAVE_X11)
345 display =
new vpDisplayX;
347 std::cout <<
" Sorry, X11 video device is not available.\n";
348 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
353 std::cout <<
"Requested GTK display functionalities..." << std::endl;
354 #if defined(VISP_HAVE_GTK)
357 std::cout <<
" Sorry, GTK video device is not available.\n";
358 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
363 std::cout <<
"Requested GDI display functionalities..." << std::endl;
364 #if defined(VISP_HAVE_GDI)
368 std::cout <<
" Sorry, GDI video device is not available.\n";
369 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
374 std::cout <<
"Requested D3D display functionalities..." << std::endl;
375 #if defined(VISP_HAVE_D3D9)
378 std::cout <<
" Sorry, D3D video device is not available.\n";
379 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
384 std::cout <<
"Requested OpenCV display functionalities..." << std::endl;
385 #if defined(HAVE_OPENCV_HIGHGUI)
388 std::cout <<
" Sorry, OpenCV video device is not available.\n";
389 std::cout <<
"Use \"" << argv[0] <<
" -l\" to print the list of available devices.\n";
398 display->init(I, 100, 100,
"Display...");
408 std::cout <<
"A click to continue...\n";
409 if (opt_click_allowed)
418 display->init(I, 100, 100);
428 std::cout <<
"A click to continue...\n";
429 if (opt_click_allowed)
437 display->init(Irgba, 100, 100,
"Color display...");
448 std::cout <<
"A click to continue...\n";
449 if (opt_click_allowed)
452 display->close(Irgba);
458 display->init(Irgba, 100, 100);
469 std::cout <<
"A click to exit...\n";
470 if (opt_click_allowed)
476 vpERROR_TRACE(
"Error while displaying the image");
482 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 void flush(const vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)