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"
88 void usage(
const char *name,
const char *badparam, std::string ipath)
91 Tracking of Surf key-points.\n\
94 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
98 -i <input image path> %s\n\
99 Set image input path.\n\
100 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\
102 Setting the VISP_INPUT_IMAGE_PATH environment\n\
103 variable produces the same behaviour than using\n\
107 Disable the mouse click. Useful to automaze the \n\
108 execution of this program without humain intervention.\n\
111 Turn off the display.\n\
118 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
133 bool getOptions(
int argc,
const char **argv, std::string &ipath,
134 bool &click_allowed,
bool &display)
141 case 'c': click_allowed =
false;
break;
142 case 'd': display =
false;
break;
143 case 'i': ipath = optarg;
break;
144 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
147 usage(argv[0], optarg, ipath);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0], NULL, ipath);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
165 main(
int argc,
const char ** argv)
167 std::string env_ipath;
168 std::string opt_ipath;
171 std::string filename;
172 bool opt_click_allowed =
true;
173 bool opt_display =
true;
176 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
181 if (! env_ipath.empty())
186 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
187 opt_display) ==
false) {
192 if (!opt_ipath.empty())
197 if (!opt_ipath.empty() && !env_ipath.empty()) {
198 if (ipath != env_ipath) {
199 std::cout << std::endl
200 <<
"WARNING: " << std::endl;
201 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
202 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
203 <<
" we skip the environment variable." << std::endl;
208 if (opt_ipath.empty() && env_ipath.empty()){
209 usage(argv[0], NULL, ipath);
210 std::cerr << std::endl
211 <<
"ERROR:" << std::endl;
212 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
214 <<
" environment variable to specify the location of the " << std::endl
215 <<
" image path where test images are located." << std::endl << std::endl;
230 std::ostringstream s;
231 s.setf(std::ios::right, std::ios::adjustfield);
232 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
233 filename = dirname + s.str();
242 vpCTRACE <<
"Load: " << filename << std::endl;
252 std::cerr << std::endl
253 <<
"ERROR:" << std::endl;
254 std::cerr <<
" Cannot read " << filename << std::endl;
255 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
256 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
262 #if defined VISP_HAVE_X11
264 #elif defined VISP_HAVE_GTK
266 #elif defined VISP_HAVE_GDI
273 display[0].
init(Iref, 100, 100,
"Display reference image") ;
285 if (opt_display && opt_click_allowed)
287 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;
288 for (
unsigned int i=0 ; i < 2 ; i++)
291 std::cout << corners[i] << std::endl;
296 corners[0].
set_ij(156,209);
297 corners[1].
set_ij(272,378);
307 if (opt_click_allowed)
309 std::cout <<
"Click on the image to continue" << std::endl;
315 unsigned int height, width;
316 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
317 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
322 unsigned int nbrPair = 0;
329 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Display current image") ;
340 for (
int iter = 1 ; iter < 30 ; iter++)
342 std::cout <<
"----------------------------------------------------------"<<std::endl;
345 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
346 filename = dirname + s.str();
356 std::cout <<
"Number of matched point : " << nbrPair <<std::endl;
373 #if ( ! (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) )
374 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
376 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.
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)
void set_ij(const double i, const double j)
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)