Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testDisplayRoi.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 roi display.
33 *
34*****************************************************************************/
35
43#include <stdlib.h>
44
45#include <visp3/core/vpImage.h>
46#include <visp3/core/vpRect.h>
47#include <visp3/gui/vpDisplayD3D.h>
48#include <visp3/gui/vpDisplayGDI.h>
49#include <visp3/gui/vpDisplayGTK.h>
50#include <visp3/gui/vpDisplayOpenCV.h>
51#include <visp3/gui/vpDisplayX.h>
52#include <visp3/io/vpParseArgv.h>
53
54// List of allowed command line options
55#define GETOPTARGS "cdh"
56
57void usage(const char *name, const char *badparam);
58bool getOptions(int argc, const char **argv, bool &click_allowed, bool &display);
59
68void usage(const char *name, const char *badparam)
69{
70 fprintf(stdout, "\n\
71Read an image on the disk, display it using X11, display some\n\
72features (line, circle, characters) in overlay and finally write \n\
73the image and the overlayed features in an image on the disk.\n\
74\n\
75SYNOPSIS\n\
76 %s [-c] [-d] [-h]\n",
77 name);
78
79 fprintf(stdout, "\n\
80OPTIONS: Default\n\
81 -c\n\
82 Disable the mouse click. Useful to automate the \n\
83 execution of this program without human intervention.\n\
84\n\
85 -d \n\
86 Disable the image display. This can be useful \n\
87 for automatic tests using crontab under Unix or \n\
88 using the task manager under Windows.\n\
89\n\
90 -h\n\
91 Print the help.\n\n");
92
93 if (badparam) {
94 fprintf(stderr, "ERROR: \n");
95 fprintf(stderr, "\nBad parameter [%s]\n", badparam);
96 }
97}
98
114bool getOptions(int argc, const char **argv, 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 'c':
122 click_allowed = false;
123 break;
124 case 'd':
125 display = false;
126 break;
127 case 'h':
128 usage(argv[0], NULL);
129 return false;
130 break;
131
132 default:
133 usage(argv[0], optarg_);
134 return false;
135 break;
136 }
137 }
138
139 if ((c == 1) || (c == -1)) {
140 // standalone param or error
141 usage(argv[0], NULL);
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
150int main(int argc, const char **argv)
151{
152#ifdef VISP_HAVE_DISPLAY
153 bool opt_click_allowed = true;
154 bool opt_display = true;
155
156 // Read the command line options
157 if (getOptions(argc, argv, opt_click_allowed, opt_display) == false) {
158 return EXIT_FAILURE;
159 }
160
161 if (opt_display) {
162
163 vpImage<unsigned char> I(480, 640, 255);
164
165#if defined(VISP_HAVE_X11)
166 vpDisplayX d;
167#elif defined(VISP_HAVE_GTK)
168 vpDisplayGTK d;
169#elif defined(VISP_HAVE_GDI)
170 vpDisplayGDI d;
171#elif defined(VISP_HAVE_D3D9)
172 vpDisplayD3D d;
173#elif defined(HAVE_OPENCV_HIGHGUI)
175#endif
176 d.init(I);
179
180 I = 0;
181
182 vpRect roi(I.getWidth() / 4, I.getHeight() / 4, I.getWidth() / 2, I.getHeight() / 2);
183 vpDisplay::displayROI(I, roi);
185 if (opt_click_allowed) {
186 std::cout << "A click in the image to continue..." << std::endl;
188 }
190
191 vpImage<vpRGBa> C(480, 640, vpRGBa(255, 0, 0, 0));
192
193 // vpDisplayX d;
194 d.init(C);
197
198 C = vpRGBa(0, 255, 0, 0);
199
200 vpDisplay::displayROI(C, roi);
201 vpDisplay::flushROI(C, roi);
202 if (opt_click_allowed) {
203 std::cout << "A click in the image to exit..." << std::endl;
205 }
206 }
207#else
208 (void)argc;
209 (void)argv;
210#endif
211 return EXIT_SUCCESS;
212}
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...
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 void close(vpImage< unsigned char > &I)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void displayROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void display(const vpImage< unsigned char > &I)
static void flushROI(const vpImage< unsigned char > &I, const vpRect &roi)
static void flush(const vpImage< unsigned char > &I)
Definition of the vpImage class member functions.
Definition vpImage.h:135
unsigned int getWidth() const
Definition vpImage.h:242
unsigned int getHeight() const
Definition vpImage.h:184
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Defines a rectangle in the plane.
Definition vpRect.h:76