55 #include <visp3/core/vpConfig.h> 56 #include <visp3/core/vpDebug.h> 57 #if ((defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && \ 58 defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION < 0x030000)) 62 #include <visp3/core/vpImage.h> 63 #include <visp3/core/vpImagePoint.h> 64 #include <visp3/gui/vpDisplayGDI.h> 65 #include <visp3/gui/vpDisplayGTK.h> 66 #include <visp3/gui/vpDisplayX.h> 67 #include <visp3/io/vpImageIo.h> 69 #include <visp3/core/vpIoTools.h> 70 #include <visp3/io/vpParseArgv.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 \"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\ 113 Print the help.\n", ipath.c_str());
116 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
131 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
139 click_allowed =
false;
148 usage(argv[0], NULL, ipath);
153 usage(argv[0], optarg_, ipath);
159 if ((c == 1) || (c == -1)) {
161 usage(argv[0], NULL, ipath);
162 std::cerr <<
"ERROR: " << std::endl;
163 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
170 int main(
int argc,
const char **argv)
173 std::string env_ipath;
174 std::string opt_ipath;
177 std::string filename;
178 bool opt_click_allowed =
true;
179 bool opt_display =
true;
186 if (!env_ipath.empty())
190 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) ==
false) {
195 if (!opt_ipath.empty())
200 if (!opt_ipath.empty() && !env_ipath.empty()) {
201 if (ipath != env_ipath) {
202 std::cout << std::endl <<
"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 <<
"ERROR:" << std::endl;
213 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
214 <<
" environment variable to specify the location of the " << std::endl
215 <<
" image path where test images are located." << std::endl
230 unsigned int iter = 0;
231 std::ostringstream s;
232 s.setf(std::ios::right, std::ios::adjustfield);
233 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
243 vpCTRACE <<
"Load: " << filename << std::endl;
251 std::cerr << std::endl <<
"ERROR:" << std::endl;
252 std::cerr <<
" Cannot read " << filename << std::endl;
253 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
254 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
259 #if defined VISP_HAVE_X11 261 #elif defined VISP_HAVE_GTK 263 #elif defined VISP_HAVE_GDI 270 display[0].
init(Iref, 100, 100,
"Display reference image");
280 if (opt_display && opt_click_allowed) {
281 std::cout <<
"Click on the top left and the bottom right corners to " 282 "define the part of the image where the reference points " 285 for (
unsigned int i = 0; i < 2; i++) {
287 std::cout << corners[i] << std::endl;
290 corners[0].
set_ij(156, 209);
291 corners[1].
set_ij(272, 378);
301 if (opt_click_allowed) {
302 std::cout <<
"Click on the image to continue" << std::endl;
308 unsigned int height, width;
309 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
310 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
313 surf.buildReference(Iref, corners[0], height, width);
320 display[1].
init(Icur, (
int)(100 + Iref.
getWidth()), 100,
"Display current image");
329 for (iter = 1; iter < 30; iter++) {
330 std::cout <<
"----------------------------------------------------------" << std::endl;
333 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
343 unsigned int nbrPair = surf.matchPoint(Icur);
344 std::cout <<
"Number of matched point : " << nbrPair << std::endl;
348 surf.display(Iref, Icur, 7);
356 std::cout <<
"Catch an exception: " << e << std::endl;
364 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))) 365 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
366 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
367 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
368 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
369 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
371 std::cout <<
"You do not have OpenCV with non free module functionalities" << std::endl;
372 std::cout <<
"Tip:" << std::endl;
373 std::cout <<
"- Install OpenCV with non free module, configure again ViSP using cmake and build again this example" << std::endl;
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
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 3rd party library. Thus to enable this class G...
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
void set_ij(double ii, double jj)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const