56 #include <visp/vpDebug.h>
57 #include <visp/vpConfig.h>
62 #if ((defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION >= 0x010100))
64 #include <visp/vpKeyPointSurf.h>
66 #include <visp/vpImage.h>
67 #include <visp/vpImageIo.h>
68 #include <visp/vpImagePoint.h>
69 #include <visp/vpDisplayX.h>
70 #include <visp/vpDisplayGTK.h>
71 #include <visp/vpDisplayGDI.h>
73 #include <visp/vpParseArgv.h>
74 #include <visp/vpIoTools.h>
77 #define GETOPTARGS "cdi:h"
79 void usage(
const char *name,
const char *badparam, std::string ipath);
80 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
91 void usage(
const char *name,
const char *badparam, std::string ipath)
94 Tracking of Surf key-points.\n\
97 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
101 -i <input image path> %s\n\
102 Set image input path.\n\
103 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\
105 Setting the VISP_INPUT_IMAGE_PATH environment\n\
106 variable produces the same behaviour than using\n\
110 Disable the mouse click. Useful to automaze the \n\
111 execution of this program without humain intervention.\n\
114 Turn off the display.\n\
121 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
136 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
143 case 'c': click_allowed =
false;
break;
144 case 'd': display =
false;
break;
145 case 'i': ipath = optarg_;
break;
146 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
149 usage(argv[0], optarg_, ipath);
154 if ((c == 1) || (c == -1)) {
156 usage(argv[0], NULL, ipath);
157 std::cerr <<
"ERROR: " << std::endl;
158 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
167 main(
int argc,
const char ** argv)
170 std::string env_ipath;
171 std::string opt_ipath;
174 std::string filename;
175 bool opt_click_allowed =
true;
176 bool opt_display =
true;
179 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
184 if (! env_ipath.empty())
188 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
189 opt_display) ==
false) {
194 if (!opt_ipath.empty())
199 if (!opt_ipath.empty() && !env_ipath.empty()) {
200 if (ipath != env_ipath) {
201 std::cout << std::endl
202 <<
"WARNING: " << std::endl;
203 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
204 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
205 <<
" we skip the environment variable." << std::endl;
210 if (opt_ipath.empty() && env_ipath.empty()){
211 usage(argv[0], NULL, ipath);
212 std::cerr << std::endl
213 <<
"ERROR:" << std::endl;
214 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
216 <<
" environment variable to specify the location of the " << std::endl
217 <<
" image path where test images are located." << std::endl << std::endl;
231 unsigned int iter = 0;
232 std::ostringstream s;
233 s.setf(std::ios::right, std::ios::adjustfield);
234 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
235 filename = dirname + s.str();
244 vpCTRACE <<
"Load: " << filename << std::endl;
254 std::cerr << std::endl
255 <<
"ERROR:" << std::endl;
256 std::cerr <<
" Cannot read " << filename << std::endl;
257 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
258 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
264 #if defined VISP_HAVE_X11
266 #elif defined VISP_HAVE_GTK
268 #elif defined VISP_HAVE_GDI
275 display[0].
init(Iref, 100, 100,
"Display reference image") ;
287 if (opt_display && opt_click_allowed)
289 std::cout <<
"Click on the top left and the bottom right corners to define the part of the image where the reference points will be computed" << std::endl;
290 for (
unsigned int i=0 ; i < 2 ; i++)
293 std::cout << corners[i] << std::endl;
298 corners[0].
set_ij(156,209);
299 corners[1].
set_ij(272,378);
309 if (opt_click_allowed)
311 std::cout <<
"Click on the image to continue" << std::endl;
317 unsigned int height, width;
318 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
319 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
324 unsigned int nbrPair = 0;
331 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Display current image") ;
342 for (iter = 1 ; iter < 30 ; iter++)
344 std::cout <<
"----------------------------------------------------------"<<std::endl;
347 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
348 filename = dirname + s.str();
358 std::cout <<
"Number of matched point : " << nbrPair <<std::endl;
372 std::cout <<
"Catch an exception: " << e << std::endl;
381 #if ( ! (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) )
382 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
384 vpERROR_TRACE(
"You do not have OpenCV-1.1.0 or a more recent release that contains opencv_nonfree component...");
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
error that can be emited by ViSP classes.
unsigned int matchPoint(const vpImage< unsigned char > &I)
void display(const vpImage< unsigned char > &Iref, const vpImage< unsigned char > &Icurrent, unsigned int size=3)
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that implements the SURF key points and technics thanks to the OpenCV library.
static void display(const vpImage< unsigned char > &I)
The vpDisplayGTK allows to display image using the GTK+ library version 1.2.
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
unsigned int buildReference(const vpImage< unsigned char > &I)
virtual bool getClick(bool blocking=true)=0
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static void read(vpImage< unsigned char > &I, const char *filename)
void set_ij(const double ii, const double jj)