44 #include <visp/vpDebug.h>
45 #include <visp/vpConfig.h>
50 #if ((defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION >= 0x010100)) // Require opencv >= 1.1.0
52 #include <visp/vpKeyPointSurf.h>
53 #include <visp/vpImage.h>
54 #include <visp/vpImageIo.h>
55 #include <visp/vpDisplayX.h>
56 #include <visp/vpDisplayGTK.h>
57 #include <visp/vpDisplayGDI.h>
60 #include <visp/vpCameraParameters.h>
62 #include <visp/vpParseArgv.h>
63 #include <visp/vpIoTools.h>
72 #define GETOPTARGS "cdi:h"
74 void usage(
const char *name,
const char *badparam, std::string ipath);
75 bool getOptions(
int argc,
const char **argv, std::string &ipath,
76 bool &click_allowed,
bool &display);
87 void usage(
const char *name,
const char *badparam, std::string ipath)
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 image \n\
100 \"ViSP-images/ellipse/ellipse.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,
133 bool &click_allowed,
bool &display)
140 case 'c': click_allowed =
false;
break;
141 case 'd': display =
false;
break;
142 case 'i': ipath = optarg_;
break;
143 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
146 usage(argv[0], optarg_, ipath);
151 if ((c == 1) || (c == -1)) {
153 usage(argv[0], NULL, ipath);
154 std::cerr <<
"ERROR: " << std::endl;
155 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
164 main(
int argc,
const char ** argv)
167 std::string env_ipath;
168 std::string opt_ipath;
171 std::string filenameRef;
172 std::string filenameCur;
173 bool opt_click_allowed =
true;
174 bool opt_display =
true;
177 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
182 if (! env_ipath.empty())
187 if (getOptions(argc, argv, opt_ipath,
188 opt_click_allowed, opt_display) ==
false) {
193 if (!opt_ipath.empty())
198 if (!opt_ipath.empty() && !env_ipath.empty()) {
199 if (ipath != env_ipath) {
200 std::cout << std::endl
201 <<
"WARNING: " << std::endl;
202 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
203 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
204 <<
" we skip the environment variable." << std::endl;
209 if (opt_ipath.empty() && env_ipath.empty()){
210 usage(argv[0], NULL, ipath);
211 std::cerr << std::endl
212 <<
"ERROR:" << std::endl;
213 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
215 <<
" environment variable to specify the location of the " << std::endl
216 <<
" image path where test images are located." << std::endl << std::endl;
231 filenameRef = dirname +
"image.0000.pgm";
232 filenameCur = dirname +
"image.0079.pgm";
241 vpCTRACE <<
"Load: " << filenameRef << std::endl;
245 vpCTRACE <<
"Load: " << filenameCur << std::endl;
255 std::cerr << std::endl
256 <<
"ERROR:" << std::endl;
257 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur <<std::endl;
258 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
259 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
265 #if defined VISP_HAVE_X11
267 #elif defined VISP_HAVE_GTK
269 #elif defined VISP_HAVE_GDI
275 display[0].
init(Iref, 100, 100,
"Reference image") ;
289 if (opt_click_allowed && opt_display)
291 std::cout <<
"Select a part of the image where the reference points will be computed. This part is a rectangle." << std::endl;
292 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
294 for (
int i=0 ; i < 2 ; i++)
301 unsigned int height, width;
302 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
303 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
321 unsigned int nbrPair;
323 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Current image") ;
330 if (opt_click_allowed && opt_display)
332 std::cout <<
"Select a part of the current image where the reference will be search. This part is a rectangle." << std::endl;
333 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
335 for (
int i=0 ; i < 2 ; i++)
341 unsigned int height, width;
342 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
343 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
346 nbrPair = surf.
matchPoint(Icur, corners[0], height, width);
364 if (opt_click_allowed)
366 std::cout <<
"A click on the reference image to exit..." << std::endl;
373 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)