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