52 #include <visp3/core/vpDebug.h> 53 #include <visp3/core/vpConfig.h> 58 #if ((defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION < 0x030000)) 60 #include <visp3/vision/vpKeyPointSurf.h> 62 #include <visp3/core/vpImage.h> 63 #include <visp3/io/vpImageIo.h> 64 #include <visp3/core/vpImagePoint.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/gui/vpDisplayGTK.h> 67 #include <visp3/gui/vpDisplayGDI.h> 69 #include <visp3/io/vpParseArgv.h> 70 #include <visp3/core/vpIoTools.h> 73 #define GETOPTARGS "cdi:h" 75 void usage(
const char *name,
const char *badparam, std::string ipath);
76 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
87 void usage(
const char *name,
const char *badparam, std::string ipath)
90 Tracking of Surf key-points.\n\ 93 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
97 -i <input image path> %s\n\ 98 Set image input path.\n\ 99 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\ 101 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 102 variable produces the same behaviour than using\n\ 106 Disable the mouse click. Useful to automaze the \n\ 107 execution of this program without humain intervention.\n\ 110 Turn off the display.\n\ 117 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
132 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
139 case 'c': click_allowed =
false;
break;
140 case 'd': display =
false;
break;
141 case 'i': ipath = optarg_;
break;
142 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
145 usage(argv[0], optarg_, ipath);
150 if ((c == 1) || (c == -1)) {
152 usage(argv[0], NULL, ipath);
153 std::cerr <<
"ERROR: " << std::endl;
154 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
163 main(
int argc,
const char ** argv)
166 std::string env_ipath;
167 std::string opt_ipath;
170 std::string filename;
171 bool opt_click_allowed =
true;
172 bool opt_display =
true;
178 if (! env_ipath.empty())
182 if (getOptions(argc, argv, opt_ipath, opt_click_allowed,
183 opt_display) ==
false) {
188 if (!opt_ipath.empty())
193 if (!opt_ipath.empty() && !env_ipath.empty()) {
194 if (ipath != env_ipath) {
195 std::cout << std::endl
196 <<
"WARNING: " << std::endl;
197 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 198 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
199 <<
" we skip the environment variable." << std::endl;
204 if (opt_ipath.empty() && env_ipath.empty()){
205 usage(argv[0], NULL, ipath);
206 std::cerr << std::endl
207 <<
"ERROR:" << std::endl;
208 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 210 <<
" environment variable to specify the location of the " << std::endl
211 <<
" image path where test images are located." << std::endl << std::endl;
225 unsigned int iter = 0;
226 std::ostringstream s;
227 s.setf(std::ios::right, std::ios::adjustfield);
228 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
238 vpCTRACE <<
"Load: " << filename << std::endl;
248 std::cerr << std::endl
249 <<
"ERROR:" << std::endl;
250 std::cerr <<
" Cannot read " << filename << std::endl;
251 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
252 <<
" or VISP_INPUT_IMAGE_PATH environment variable." 258 #if defined VISP_HAVE_X11 260 #elif defined VISP_HAVE_GTK 262 #elif defined VISP_HAVE_GDI 269 display[0].
init(Iref, 100, 100,
"Display reference image") ;
281 if (opt_display && opt_click_allowed)
283 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;
284 for (
unsigned int i=0 ; i < 2 ; i++)
287 std::cout << corners[i] << std::endl;
292 corners[0].
set_ij(156,209);
293 corners[1].
set_ij(272,378);
303 if (opt_click_allowed)
305 std::cout <<
"Click on the image to continue" << std::endl;
311 unsigned int height, width;
312 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
313 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
318 unsigned int nbrPair = 0;
325 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Display current image") ;
336 for (iter = 1 ; iter < 30 ; iter++)
338 std::cout <<
"----------------------------------------------------------"<<std::endl;
341 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
352 std::cout <<
"Number of matched point : " << nbrPair <<std::endl;
366 std::cout <<
"Catch an exception: " << e << std::endl;
375 #if ( ! (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) ) 376 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
378 vpERROR_TRACE(
"You do not have 1.1.0 <= OpenCV < 3.0.0 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 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)