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 < 0x030000)) // Require opencv >= 1.1.0 < 3.0.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;
180 if (! env_ipath.empty())
185 if (getOptions(argc, argv, opt_ipath,
186 opt_click_allowed, opt_display) ==
false) {
191 if (!opt_ipath.empty())
196 if (!opt_ipath.empty() && !env_ipath.empty()) {
197 if (ipath != env_ipath) {
198 std::cout << std::endl
199 <<
"WARNING: " << std::endl;
200 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
201 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
202 <<
" we skip the environment variable." << std::endl;
207 if (opt_ipath.empty() && env_ipath.empty()){
208 usage(argv[0], NULL, ipath);
209 std::cerr << std::endl
210 <<
"ERROR:" << std::endl;
211 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
213 <<
" environment variable to specify the location of the " << std::endl
214 <<
" image path where test images are located." << std::endl << std::endl;
239 vpCTRACE <<
"Load: " << filenameRef << std::endl;
243 vpCTRACE <<
"Load: " << filenameCur << std::endl;
253 std::cerr << std::endl
254 <<
"ERROR:" << std::endl;
255 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur <<std::endl;
256 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
257 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
263 #if defined VISP_HAVE_X11
265 #elif defined VISP_HAVE_GTK
267 #elif defined VISP_HAVE_GDI
273 display[0].
init(Iref, 100, 100,
"Reference image") ;
287 if (opt_click_allowed && opt_display)
289 std::cout <<
"Select a part of the image where the reference points will be computed. This part is a rectangle." << std::endl;
290 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
292 for (
int i=0 ; i < 2 ; i++)
299 unsigned int height, width;
300 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
301 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
319 unsigned int nbrPair;
321 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Current image") ;
328 if (opt_click_allowed && opt_display)
330 std::cout <<
"Select a part of the current image where the reference will be search. This part is a rectangle." << std::endl;
331 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
333 for (
int i=0 ; i < 2 ; i++)
339 unsigned int height, width;
340 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
341 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
344 nbrPair = surf.
matchPoint(Icur, corners[0], height, width);
362 if (opt_click_allowed)
364 std::cout <<
"A click on the reference image to exit..." << std::endl;
371 std::cout <<
"Catch an exception: " << e << std::endl;
379 #if ( ! (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) )
380 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
382 vpERROR_TRACE(
"You do not have 1.1.0 <= OpenCV < 2.4.8 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)