44 #include <visp3/core/vpConfig.h>
46 #if (defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION < 0x030000)) // Require opencv >= 1.1.0 < 3.0.0
48 #include <visp3/core/vpCameraParameters.h>
49 #include <visp3/gui/vpDisplayX.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/gui/vpDisplayGDI.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/vision/vpKeyPointSurf.h>
54 #include <visp3/core/vpIoTools.h>
55 #include <visp3/core/vpImage.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/io/vpParseArgv.h>
66 #define GETOPTARGS "cdi:h"
68 void usage(
const char *name,
const char *badparam, std::string ipath);
69 bool getOptions(
int argc,
const char **argv, std::string &ipath,
70 bool &click_allowed,
bool &display);
81 void usage(
const char *name,
const char *badparam, std::string ipath)
87 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
91 -i <input image path> %s\n\
92 Set image input path.\n\
93 From this path read image \n\
94 \"ViSP-images/ellipse/ellipse.pgm\"\n\
95 Setting the VISP_INPUT_IMAGE_PATH environment\n\
96 variable produces the same behaviour than using\n\
100 Disable the mouse click. Useful to automaze the \n\
101 execution of this program without humain intervention.\n\
104 Turn off the display.\n\
111 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
126 bool getOptions(
int argc,
const char **argv, std::string &ipath,
127 bool &click_allowed,
bool &display)
134 case 'c': click_allowed =
false;
break;
135 case 'd': display =
false;
break;
136 case 'i': ipath = optarg_;
break;
137 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
140 usage(argv[0], optarg_, ipath);
145 if ((c == 1) || (c == -1)) {
147 usage(argv[0], NULL, ipath);
148 std::cerr <<
"ERROR: " << std::endl;
149 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
158 main(
int argc,
const char ** argv)
161 std::string env_ipath;
162 std::string opt_ipath;
165 std::string filenameRef;
166 std::string filenameCur;
167 bool opt_click_allowed =
true;
168 bool opt_display =
true;
174 if (! env_ipath.empty())
178 if (getOptions(argc, argv, opt_ipath,
179 opt_click_allowed, opt_display) ==
false) {
184 if (!opt_ipath.empty())
189 if (!opt_ipath.empty() && !env_ipath.empty()) {
190 if (ipath != env_ipath) {
191 std::cout << std::endl
192 <<
"WARNING: " << std::endl;
193 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
194 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
195 <<
" we skip the environment variable." << std::endl;
200 if (opt_ipath.empty() && env_ipath.empty()){
201 usage(argv[0], NULL, ipath);
202 std::cerr << std::endl
203 <<
"ERROR:" << std::endl;
204 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
206 <<
" environment variable to specify the location of the " << std::endl
207 <<
" image path where test images are located." << std::endl << std::endl;
232 std::cout <<
"Load: " << filenameRef << std::endl;
236 std::cout <<
"Load: " << filenameCur << std::endl;
246 std::cerr << std::endl
247 <<
"ERROR:" << std::endl;
248 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur <<std::endl;
249 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
250 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
256 #if defined VISP_HAVE_X11
258 #elif defined VISP_HAVE_GTK
260 #elif defined VISP_HAVE_GDI
268 display[0].
init(Iref, 100, 100,
"Reference image") ;
282 if (opt_click_allowed && opt_display)
284 std::cout <<
"Select a part of the image where the reference points will be computed. This part is a rectangle." << std::endl;
285 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
287 for (
int i=0 ; i < 2 ; i++)
294 unsigned int height, width;
295 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
296 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
309 std::cerr <<
"No reference point" << std::endl;
313 unsigned int nbrPair;
315 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Current image") ;
322 if (opt_click_allowed && opt_display)
324 std::cout <<
"Select a part of the current image where the reference will be search. This part is a rectangle." << std::endl;
325 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
327 for (
int i=0 ; i < 2 ; i++)
333 unsigned int height, width;
334 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
335 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
338 nbrPair = surf.
matchPoint(Icur, corners[0], height, width);
348 std::cout <<
"No point matched" << std::endl;
356 if (opt_click_allowed)
358 std::cout <<
"A click on the reference image to exit..." << std::endl;
365 std::cout <<
"Catch an exception: " << e << std::endl;
373 std::cerr <<
"You do not have 1.1.0 <= OpenCV < 2.3.0 that contains opencv_nonfree component..." << std::endl;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
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.
unsigned int matchPoint(const vpImage< unsigned char > &I)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
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 vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
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)
unsigned int buildReference(const vpImage< unsigned char > &I)
static void read(vpImage< unsigned char > &I, const std::string &filename)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...