45 #include <visp3/core/vpConfig.h>
47 #if (defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION < 0x030000))
49 #include <visp3/core/vpCameraParameters.h>
50 #include <visp3/core/vpImage.h>
51 #include <visp3/core/vpIoTools.h>
52 #include <visp3/gui/vpDisplayGDI.h>
53 #include <visp3/gui/vpDisplayGTK.h>
54 #include <visp3/gui/vpDisplayOpenCV.h>
55 #include <visp3/gui/vpDisplayX.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/io/vpParseArgv.h>
67 #define GETOPTARGS "cdi:h"
69 void usage(
const char *name,
const char *badparam, std::string ipath);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display);
81 void usage(
const char *name,
const char *badparam, std::string ipath)
83 #if VISP_HAVE_DATASET_VERSION >= 0x030600
84 std::string ext(
"png");
86 std::string ext(
"pgm");
92 %s [-i <input image path>] [-c] [-d] [-h]\n",
97 -i <input image path> %s\n\
98 Set image input path.\n\
99 From this path read image \n\
100 \"cube/image.0000.%s\"\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\
114 ipath.c_str(), ext.c_str());
117 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 filenameRef;
178 std::string filenameCur;
179 bool opt_click_allowed =
true;
180 bool opt_display =
true;
182 #if VISP_HAVE_DATASET_VERSION >= 0x030600
183 std::string ext(
"png");
185 std::string ext(
"pgm");
192 if (!env_ipath.empty())
196 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) ==
false) {
201 if (!opt_ipath.empty())
206 if (!opt_ipath.empty() && !env_ipath.empty()) {
207 if (ipath != env_ipath) {
208 std::cout << std::endl <<
"WARNING: " << std::endl;
209 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
210 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
211 <<
" we skip the environment variable." << std::endl;
216 if (opt_ipath.empty() && env_ipath.empty()) {
217 usage(argv[0], NULL, ipath);
218 std::cerr << std::endl <<
"ERROR:" << std::endl;
219 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
220 <<
" environment variable to specify the location of the " << std::endl
221 <<
" image path where test images are located." << std::endl
241 std::cout <<
"Load: " << filenameRef << std::endl;
245 std::cout <<
"Load: " << filenameCur << std::endl;
249 std::cerr << std::endl <<
"ERROR:" << std::endl;
250 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur << std::endl;
251 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
252 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
257 #if defined VISP_HAVE_X11
259 #elif defined VISP_HAVE_GTK
261 #elif defined VISP_HAVE_GDI
269 display[0].init(Iref, 100, 100,
"Reference image");
283 if (opt_click_allowed && opt_display) {
284 std::cout <<
"Select a part of the image where the reference points "
285 "will be computed. This part is a rectangle."
287 std::cout <<
"Click first on the top left corner and then on the "
288 "bottom right corner."
291 for (
int i = 0; i < 2; i++) {
297 unsigned int height, width;
298 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
299 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
302 nbrRef = surf.buildReference(Iref, corners[0], height, width);
306 nbrRef = surf.buildReference(Iref);
310 std::cerr <<
"No reference point" << std::endl;
314 unsigned int nbrPair;
316 display[1].init(Icur, (
int)(100 + Iref.
getWidth()), 100,
"Current image");
323 if (opt_click_allowed && opt_display) {
324 std::cout <<
"Select a part of the current image where the reference "
325 "will be search. This part is a rectangle."
327 std::cout <<
"Click first on the top left corner and then on the "
328 "bottom right corner."
331 for (
int i = 0; i < 2; i++) {
336 unsigned int height, width;
337 height = (
unsigned int)(corners[1].get_i() - corners[0].
get_i());
338 width = (
unsigned int)(corners[1].get_j() - corners[0].
get_j());
341 nbrPair = surf.matchPoint(Icur, corners[0], height, width);
345 nbrPair = surf.matchPoint(Icur);
349 std::cout <<
"No point matched" << std::endl;
353 surf.display(Iref, Icur, 7);
356 if (opt_click_allowed) {
357 std::cout <<
"A click on the reference image to exit..." << std::endl;
362 std::cout <<
"Catch an exception: " << e << std::endl;
370 std::cerr <<
"You do not have 1.1.0 <= OpenCV < 2.3.0 that contains "
371 "opencv_nonfree component..."
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
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)
error that can be emited by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
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.