Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
testTrackDot.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 auto detection of dots.
33 *
34*****************************************************************************/
35
36#include <iomanip>
37#include <sstream>
38#include <stdio.h>
39#include <stdlib.h>
40#include <visp3/core/vpConfig.h>
41#include <visp3/core/vpDebug.h>
42#if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))
43
44#include <visp3/blob/vpDot2.h>
45#include <visp3/core/vpCameraParameters.h>
46#include <visp3/core/vpImage.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/gui/vpDisplayGDI.h>
49#include <visp3/gui/vpDisplayGTK.h>
50#include <visp3/gui/vpDisplayX.h>
51#include <visp3/io/vpImageIo.h>
52#include <visp3/io/vpParseArgv.h>
53#ifdef VISP_HAVE_MODULE_FEATURES
54#include <visp3/visual_features/vpFeatureBuilder.h>
55#include <visp3/visual_features/vpFeatureEllipse.h>
56#endif
57
64// List of allowed command line options
65#define GETOPTARGS "cdi:h"
66
67bool getOptions(int argc, const char **argv, std::string &ipath, bool &click_allowed, bool &display);
68
69void usage(const char *name, const char *badparam, std::string ipath);
79void usage(const char *name, const char *badparam, std::string ipath)
80{
81#if VISP_HAVE_DATASET_VERSION >= 0x030600
82 std::string ext("png");
83#else
84 std::string ext("pgm");
85#endif
86 fprintf(stdout, "\n\
87Test dot tracking.\n\
88\n\
89SYNOPSIS\n\
90 %s [-i <input image path>] [-c] [-d] [-h]\n",
91 name);
92
93 fprintf(stdout, "\n\
94OPTIONS: Default\n\
95 -i <input image path> %s\n\
96 Set image input path.\n\
97 From this path read image \n\
98 \"ellipse/ellipse.%s\"\n\
99 Setting the VISP_INPUT_IMAGE_PATH environment\n\
100 variable produces the same behaviour than using\n\
101 this option.\n\
102\n\
103 -c\n\
104 Disable the mouse click. Useful to automate the \n\
105 execution of this program without human intervention.\n\
106\n\
107 -d \n\
108 Turn off the display.\n\
109\n\
110 -h\n\
111 Print the help.\n",
112 ipath.c_str(), ext.c_str());
113
114 if (badparam)
115 fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
116}
129bool getOptions(int argc, const char **argv, std::string &ipath, bool &click_allowed, bool &display)
130{
131 const char *optarg_;
132 int c;
133 while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
134
135 switch (c) {
136 case 'c':
137 click_allowed = false;
138 break;
139 case 'd':
140 display = false;
141 break;
142 case 'i':
143 ipath = optarg_;
144 break;
145 case 'h':
146 usage(argv[0], NULL, ipath);
147 return false;
148 break;
149
150 default:
151 usage(argv[0], optarg_, ipath);
152 return false;
153 break;
154 }
155 }
156
157 if ((c == 1) || (c == -1)) {
158 // standalone param or error
159 usage(argv[0], NULL, ipath);
160 std::cerr << "ERROR: " << std::endl;
161 std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
162 return false;
163 }
164
165 return true;
166}
167
168int main(int argc, const char **argv)
169{
170 try {
171 std::string env_ipath;
172 std::string opt_ipath;
173 std::string ipath;
174 std::string dirname;
175 std::string filename;
176 bool opt_click_allowed = true;
177 bool opt_display = true;
178
179#if VISP_HAVE_DATASET_VERSION >= 0x030600
180 std::string ext("png");
181#else
182 std::string ext("pgm");
183#endif
184
185 // Get the visp-images-data package path or VISP_INPUT_IMAGE_PATH
186 // environment variable value
188
189 // Set the default input path
190 if (!env_ipath.empty())
191 ipath = env_ipath;
192
193 // Read the command line options
194 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) == false) {
195 return EXIT_FAILURE;
196 }
197
198 // Get the option values
199 if (!opt_ipath.empty())
200 ipath = opt_ipath;
201
202 // Compare ipath and env_ipath. If they differ, we take into account
203 // the input path comming from the command line option
204 if (!opt_ipath.empty() && !env_ipath.empty()) {
205 if (ipath != env_ipath) {
206 std::cout << std::endl << "WARNING: " << std::endl;
207 std::cout << " Since -i <visp image path=" << ipath << "> "
208 << " is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
209 << " we skip the environment variable." << std::endl;
210 }
211 }
212
213 // Test if an input path is set
214 if (opt_ipath.empty() && env_ipath.empty()) {
215 usage(argv[0], NULL, ipath);
216 std::cerr << std::endl << "ERROR:" << std::endl;
217 std::cerr << " Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
218 << " environment variable to specify the location of the " << std::endl
219 << " image path where test images are located." << std::endl
220 << std::endl;
221 return EXIT_FAILURE;
222 }
223
224 // Declare an image, this is a gray level image (unsigned char)
225 // it size is not defined yet, it will be defined when the image will
226 // read on the disk
228
229 // Set the path location of the image sequence
230 dirname = vpIoTools::createFilePath(ipath, "ellipse");
231
232 // Build the name of the image file
233 filename = vpIoTools::createFilePath(dirname, "ellipse." + ext);
234
235 // Read image named "filename" and put the bitmap in I
236 try {
237 vpCTRACE << "Load: " << filename << std::endl;
238
239 vpImageIo::read(I, filename);
240 } catch (...) {
241 std::cerr << std::endl << "ERROR:" << std::endl;
242 std::cerr << " Cannot read " << filename << std::endl;
243 std::cerr << " Check your -i " << ipath << " option " << std::endl
244 << " or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
245 return EXIT_FAILURE;
246 }
247
248// We open a window using either X11, GTK or GDI.
249#if defined(VISP_HAVE_X11)
250 vpDisplayX display;
251#elif defined(VISP_HAVE_GTK)
252 vpDisplayGTK display;
253#elif defined(VISP_HAVE_GDI)
254 vpDisplayGDI display;
255#endif
256
257 if (opt_display) {
258 // Display size is automatically defined by the image (I) size
259 display.init(I, 100, 100, "Display...");
260 // Display the image
261 // The image class has a member that specify a pointer toward
262 // the display that has been initialized in the display declaration
263 // therefore is is no longer necessary to make a reference to the
264 // display variable.
266 // Flush the display
268 }
269
270 vpDot2 dot;
271 std::cout << "debut 1\n";
272 // dot.setMaxDotSize(0.50); // dot max size = 50% of the image size
273 vpImagePoint ip;
274 ip.set_i(140);
275 ip.set_j(140);
276 dot.initTracking(I, ip);
277 if (opt_display) {
278 dot.setGraphics(true);
279 } else {
280 dot.setGraphics(false);
281 }
282 dot.setComputeMoments(true);
283 dot.track(I);
284
286
287#ifdef VISP_HAVE_MODULE_FEATURES
289 vpFeatureBuilder::create(e, cam, dot);
290#endif
291 if (opt_display) {
292#ifdef VISP_HAVE_MODULE_FEATURES
293 e.display(cam, I, vpColor::red);
294#endif
296 if (opt_click_allowed) {
297 std::cout << "A click to exit..." << std::endl;
299 }
300 }
301 return EXIT_SUCCESS;
302 } catch (const vpException &e) {
303 std::cout << "Catch an exception: " << e.getMessage() << std::endl;
304 return EXIT_FAILURE;
305 }
306}
307#else
308int main() { vpERROR_TRACE("You do not have X11, GTK or GDI display functionalities..."); }
309
310#endif
Generic class defining intrinsic camera parameters.
static const vpColor red
Definition vpColor.h:211
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...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition vpDisplayX.h:132
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)
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition vpDot2.h:124
void track(const vpImage< unsigned char > &I, bool canMakeTheWindowGrow=true)
Definition vpDot2.cpp:441
void setGraphics(bool activate)
Definition vpDot2.h:311
void setComputeMoments(bool activate)
Definition vpDot2.h:273
void initTracking(const vpImage< unsigned char > &I, unsigned int size=0)
Definition vpDot2.cpp:252
error that can be emitted by ViSP classes.
Definition vpException.h:59
const char * getMessage() const
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines 2D ellipse visual feature.
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
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 ...
void set_j(double jj)
void set_i(double ii)
Definition of the vpImage class member functions.
Definition vpImage.h:135
static std::string getViSPImagesDataPath()
static std::string createFilePath(const std::string &parent, const std::string &child)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
#define vpCTRACE
Definition vpDebug.h:333
#define vpERROR_TRACE
Definition vpDebug.h:388