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"
83 void usage(
const char *name,
const char *badparam, std::string ipath)
89 %s [-i <input image path>] [-c] [-d] [-h]\n", name);
93 -i <input image path> %s\n\
94 Set image input path.\n\
95 From this path read image \n\
96 \"ViSP-images/ellipse/ellipse.pgm\"\n\
97 Setting the VISP_INPUT_IMAGE_PATH environment\n\
98 variable produces the same behaviour than using\n\
102 Disable the mouse click. Useful to automaze the \n\
103 execution of this program without humain intervention.\n\
106 Turn off the display.\n\
113 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
128 bool getOptions(
int argc,
const char **argv, std::string &ipath,
129 bool &click_allowed,
bool &display)
136 case 'c': click_allowed =
false;
break;
137 case 'd': display =
false;
break;
138 case 'i': ipath = optarg;
break;
139 case 'h': usage(argv[0], NULL, ipath);
return false;
break;
142 usage(argv[0], optarg, ipath);
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, ipath);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
160 main(
int argc,
const char ** argv)
162 std::string env_ipath;
163 std::string opt_ipath;
166 std::string filenameRef;
167 std::string filenameCur;
168 bool opt_click_allowed =
true;
169 bool opt_display =
true;
172 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
177 if (! env_ipath.empty())
182 if (getOptions(argc, argv, opt_ipath,
183 opt_click_allowed, 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;
226 filenameRef = dirname +
"image.0000.pgm";
227 filenameCur = dirname +
"image.0079.pgm";
236 vpCTRACE <<
"Load: " << filenameRef << std::endl;
240 vpCTRACE <<
"Load: " << filenameCur << std::endl;
250 std::cerr << std::endl
251 <<
"ERROR:" << std::endl;
252 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur <<std::endl;
253 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
254 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
260 #if defined VISP_HAVE_X11
262 #elif defined VISP_HAVE_GTK
264 #elif defined VISP_HAVE_GDI
271 display[0].
init(Iref, 100, 100,
"Reference image") ;
291 if (opt_click_allowed && opt_display)
293 std::cout <<
"Select a part of the image where the reference points will be computed. This part is a rectangle." << std::endl;
294 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
296 for (
int i=0 ; i < 2 ; i++)
303 unsigned int height, width;
304 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
305 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
323 unsigned int nbrPair;
325 display[1].
init(Icur, (
int)(100+Iref.
getWidth()), 100,
"Current image") ;
332 if (opt_click_allowed && opt_display)
334 std::cout <<
"Select a part of the current image where the reference will be search. This part is a rectangle." << std::endl;
335 std::cout <<
"Click first on the top left corner and then on the bottom right corner." << std::endl;
337 for (
int i=0 ; i < 2 ; i++)
343 unsigned int height, width;
344 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
345 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
348 nbrPair = surf.
matchPoint(Icur, corners[0], height, width);
366 if (opt_click_allowed)
368 std::cout <<
"A click on the reference image to exit..." << 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 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.
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)