Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testDisplays.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Test for image display.
33 *
34 * Authors:
35 * Anthony Saunier
36 *
37*****************************************************************************/
38
39#include <visp3/core/vpConfig.h>
40#include <visp3/core/vpDebug.h>
41
42#include <iostream>
43#include <stdlib.h>
44#include <string>
45
46#if defined(VISP_HAVE_GTK) || defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_D3D9) || defined(VISP_HAVE_OPENCV)
47
48#include <visp3/core/vpImage.h>
49#include <visp3/core/vpIoTools.h>
50#include <visp3/core/vpRect.h>
51#include <visp3/io/vpImageIo.h>
52#include <visp3/io/vpParseArgv.h>
53
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>
59
66// List of allowed command line options
67#define GETOPTARGS "hldc"
68
75static void usage(const char *name, const char *badparam)
76{
77 fprintf(stdout, "\n\
78Test video devices or display.\n\
79\n\
80SYNOPSIS\n\
81 %s [-l] [-c] [-d] [-h]\n\
82",
83 name);
84
85 fprintf(stdout, "\n\
86OPTIONS: Default\n\
87 -c\n\
88 Disable the mouse click. Useful to automate the \n\
89 execution of this program without human intervention.\n\
90\n\
91 -d \n\
92 Turn off the display.\n\
93\n\
94 -l\n\
95 Print the list of video-devices available and exit.\n\
96\n\
97 -h\n\
98 Print the help.\n\n");
99
100 if (badparam)
101 fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
102}
103
114static bool getOptions(int argc, const char **argv, bool &list, bool &click_allowed, bool &display)
115{
116 const char *optarg_;
117 int c;
118 while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
119
120 switch (c) {
121 case 'l':
122 list = true;
123 break;
124 case 'h':
125 usage(argv[0], NULL);
126 return false;
127 break;
128 case 'c':
129 click_allowed = false;
130 break;
131 case 'd':
132 display = false;
133 break;
134
135 default:
136 usage(argv[0], optarg_);
137 return false;
138 break;
139 }
140 }
141
142 if ((c == 1) || (c == -1)) {
143 // standalone param or error
144 usage(argv[0], NULL);
145 std::cerr << "ERROR: " << std::endl;
146 std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
147 return false;
148 }
149
150 return true;
151}
152
153template <typename Type> static void draw(vpImage<Type> &I)
154{
155 vpImagePoint iP1, iP2;
156 unsigned int w, h;
157
158 iP1.set_i(20);
159 iP1.set_j(10);
160 iP2.set_i(20);
161 iP2.set_j(30);
162 vpDisplay::displayArrow(I, iP1, iP2, vpColor::green, 4, 2, 3);
163
164 iP1.set_i(20);
165 iP1.set_j(60);
166 vpDisplay::displayText(I, iP1, "Test...", vpColor::black);
167
168 iP1.set_i(80);
169 iP1.set_j(220);
170 iP2.set_i(80);
171 iP2.set_j(480);
172 vpDisplay::displayCircle(I, iP1, 30, vpColor::red, false, 3);
173 vpDisplay::displayCircle(I, iP2, 30, vpColor::red, true, 3);
174
175 iP1.set_i(20);
176 iP1.set_j(220);
178
179 iP1.set_i(140);
180 iP1.set_j(10);
181 iP2.set_i(140);
182 iP2.set_j(50);
184
185 iP1.set_i(120);
186 iP1.set_j(180);
187 iP2.set_i(160);
188 iP2.set_j(250);
190
191 iP1.set_i(160);
192 iP1.set_j(280);
193 iP2.set_i(120);
194 iP2.set_j(340);
196
197 iP1.set_i(220);
198 iP1.set_j(400);
199 iP2.set_i(120);
200 iP2.set_j(400);
202
203 iP1.set_i(220);
204 iP1.set_j(480);
205 iP2.set_i(120);
206 iP2.set_j(450);
208
209 vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
210 vpCameraParameters cam(600, 600, 320, 240);
211 vpDisplay::displayFrame(I, cMo, cam, 0.05, vpColor::none, 3);
212
213 iP1.set_i(140);
214 iP1.set_j(80);
215 iP2.set_i(140);
216 iP2.set_j(150);
218
219 iP1.set_i(140);
220 iP1.set_j(400);
222
223 iP1.set_i(350);
224 iP1.set_j(20);
225 w = 60;
226 h = 50;
227 vpDisplay::displayRectangle(I, iP1, w, h, vpColor::red, false, 3);
228
229 iP1.set_i(350);
230 iP1.set_j(110);
231 vpDisplay::displayRectangle(I, iP1, w, h, vpColor::red, true, 3);
232
233 iP1.set_i(350);
234 iP1.set_j(200);
235 iP2.set_i(400);
236 iP2.set_j(260);
237 vpDisplay::displayRectangle(I, iP1, iP2, vpColor::orange, false, 3);
238
239 iP1.set_i(350);
240 iP1.set_j(290);
241 iP2.set_i(400);
242 iP2.set_j(350);
243 vpRect rectangle(iP1, iP2);
244 vpDisplay::displayRectangle(I, rectangle, vpColor::yellow, false, 3);
245
246 iP1.set_i(380);
247 iP1.set_j(400);
248 vpDisplay::displayRectangle(I, iP1, 45, w, h, vpColor::green, 3);
249
250 std::vector<vpImagePoint> polygon;
251 polygon.push_back(vpImagePoint(250, 500));
252 polygon.push_back(vpImagePoint(350, 600));
253 polygon.push_back(vpImagePoint(450, 500));
254 polygon.push_back(vpImagePoint(350, 400));
256
257 polygon.clear();
258 polygon.push_back(vpImagePoint(300, 500));
259 polygon.push_back(vpImagePoint(350, 550));
260 polygon.push_back(vpImagePoint(400, 500));
261 polygon.push_back(vpImagePoint(350, 450));
262 vpDisplay::displayPolygon(I, polygon, vpColor::cyan, 3, false);
263}
264
265template <typename Type> static void runTest(bool opt_display, bool opt_click_allowed)
266{
267 vpImage<Type> Ix;
268 vpImage<Type> Igtk;
269 vpImage<Type> Icv;
270 vpImage<Type> Igdi;
271 vpImage<Type> Id3d;
272
273#if defined(VISP_HAVE_X11)
274 vpDisplayX *displayX = new vpDisplayX;
275 Ix.init(480, 640, 255);
276 if (opt_display) {
277 displayX->init(Ix, 100, 100, "Display X11");
279 draw(Ix);
281 if (opt_click_allowed)
283 }
284#endif
285
286#if defined(HAVE_OPENCV_HIGHGUI)
287 vpDisplayOpenCV *displayCv = new vpDisplayOpenCV;
288 Icv.init(480, 640, 255);
289 if (opt_display) {
290 displayCv->init(Icv, 100, 100, "Display OpenCV");
292 draw(Icv);
293 vpDisplay::flush(Icv);
294 if (opt_click_allowed)
296 }
297#endif
298
299#if defined(VISP_HAVE_GTK)
300 vpDisplayGTK *displayGtk = new vpDisplayGTK;
301 Igtk.init(480, 640, 255);
302 if (opt_display) {
303 displayGtk->init(Igtk, 100, 100, "Display GTK");
304 vpDisplay::display(Igtk);
305 draw(Igtk);
306 vpDisplay::flush(Igtk);
307 if (opt_click_allowed)
309 }
310#endif
311
312#if defined(VISP_HAVE_GDI)
313
314 vpDisplayGDI *displayGdi = new vpDisplayGDI;
315 Igdi.init(480, 640, 255);
316 if (opt_display) {
317 displayGdi->init(Igdi, 100, 100, "Display GDI");
318 vpDisplay::display(Igdi);
319 draw(Igdi);
320 vpDisplay::flush(Igdi);
321 if (opt_click_allowed)
323 }
324#endif
325
326#if defined(VISP_HAVE_D3D9)
327 vpDisplayD3D *displayD3d = new vpDisplayD3D;
328 Id3d.init(480, 640, 255);
329 if (opt_display) {
330 displayD3d->init(Id3d, 100, 100, "Display Direct 3D");
331 vpDisplay::display(Id3d);
332 draw(Id3d);
333 vpDisplay::flush(Id3d);
334 if (opt_click_allowed)
336 }
337#endif
338
339#if defined(VISP_HAVE_X11)
340 delete displayX;
341#endif
342
343#if defined(VISP_HAVE_GTK)
344 delete displayGtk;
345#endif
346
347#if defined(HAVE_OPENCV_HIGHGUI)
348 delete displayCv;
349#endif
350
351#if defined(VISP_HAVE_GDI)
352
353 delete displayGdi;
354#endif
355
356#if defined(VISP_HAVE_D3D9)
357 delete displayD3d;
358#endif
359}
360
361int main(int argc, const char **argv)
362{
363 try {
364 bool opt_list = false; // To print the list of video devices
365 bool opt_click_allowed = true;
366 bool opt_display = true;
367
368 // Read the command line options
369 if (getOptions(argc, argv, opt_list, opt_click_allowed, opt_display) == false) {
370 return EXIT_FAILURE;
371 }
372
373 // Print the list of video-devices available
374 if (opt_list) {
375 unsigned nbDevices = 0;
376 std::cout << "List of video-devices available: \n";
377#if defined(VISP_HAVE_GTK)
378 std::cout << " GTK\n";
379 nbDevices++;
380#endif
381#if defined(VISP_HAVE_X11)
382 std::cout << " X11\n";
383 nbDevices++;
384#endif
385#if defined(VISP_HAVE_GDI)
386
387 std::cout << " GDI\n";
388 nbDevices++;
389#endif
390#if defined(VISP_HAVE_D3D9)
391 std::cout << " D3D\n";
392 nbDevices++;
393#endif
394#if defined VISP_HAVE_OPENCV
395 std::cout << " OpenCV\n";
396 nbDevices++;
397#endif
398 if (!nbDevices) {
399 std::cout << " No display is available\n";
400 }
401 return EXIT_FAILURE;
402 }
403
404 // Create a color image for each display.
405 runTest<vpRGBa>(opt_display, opt_click_allowed);
406
407 // Create a grayscale image for each display.
408 runTest<unsigned char>(opt_display, opt_click_allowed);
409
410 return EXIT_SUCCESS;
411 } catch (const vpException &e) {
412 std::cout << "Catch an exception: " << e.getMessage() << std::endl;
413 return EXIT_FAILURE;
414 }
415}
416#else
417int main()
418{
419 std::cout << "You do not have display functionalities..." << std::endl;
420 return EXIT_SUCCESS;
421}
422#endif
Generic class defining intrinsic camera parameters.
static const vpColor red
Definition vpColor.h:211
static const vpColor black
Definition vpColor.h:205
static const vpColor cyan
Definition vpColor.h:220
static const vpColor none
Definition vpColor.h:223
static const vpColor orange
Definition vpColor.h:221
static const vpColor blue
Definition vpColor.h:217
static const vpColor yellow
Definition vpColor.h:219
static const vpColor green
Definition vpColor.h:214
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...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayCircle(const vpImage< unsigned char > &I, const vpImageCircle &circle, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void displayDotLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static void displayPolygon(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, const vpColor &color, unsigned int thickness=1, bool closed=true)
error that can be emitted by ViSP classes.
Definition vpException.h:59
const char * getMessage() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
void set_j(double jj)
void set_i(double ii)
Definition of the vpImage class member functions.
Definition vpImage.h:135
void init(unsigned int height, unsigned int width)
Set the size of the image.
Definition vpImage.h:639
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.
Definition vpRect.h:76
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
Class that consider the case of a translation vector.