45 #include <visp3/core/vpConfig.h> 47 #if (defined(VISP_HAVE_OPENCV_NONFREE) && (VISP_HAVE_OPENCV_VERSION < 0x030000)) // Require opencv >= 1.1.0 < 3.0.0 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> 58 #include <visp3/vision/vpKeyPointSurf.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)
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 \"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\ 107 Print the help.\n", ipath.c_str());
110 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
124 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display)
132 click_allowed =
false;
141 usage(argv[0], NULL, ipath);
146 usage(argv[0], optarg_, ipath);
152 if ((c == 1) || (c == -1)) {
154 usage(argv[0], NULL, ipath);
155 std::cerr <<
"ERROR: " << std::endl;
156 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
163 int main(
int argc,
const char **argv)
166 std::string env_ipath;
167 std::string opt_ipath;
170 std::string filenameRef;
171 std::string filenameCur;
172 bool opt_click_allowed =
true;
173 bool opt_display =
true;
180 if (!env_ipath.empty())
184 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display) ==
false) {
189 if (!opt_ipath.empty())
194 if (!opt_ipath.empty() && !env_ipath.empty()) {
195 if (ipath != env_ipath) {
196 std::cout << std::endl <<
"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 <<
"ERROR:" << std::endl;
207 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
208 <<
" environment variable to specify the location of the " << std::endl
209 <<
" image path where test images are located." << std::endl
234 std::cout <<
"Load: " << filenameRef << std::endl;
238 std::cout <<
"Load: " << filenameCur << std::endl;
246 std::cerr << std::endl <<
"ERROR:" << std::endl;
247 std::cerr <<
" Cannot read " << filenameRef <<
"or" << filenameCur << std::endl;
248 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
249 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
254 #if defined VISP_HAVE_X11 256 #elif defined VISP_HAVE_GTK 258 #elif defined VISP_HAVE_GDI 266 display[0].
init(Iref, 100, 100,
"Reference image");
280 if (opt_click_allowed && opt_display) {
281 std::cout <<
"Select a part of the image where the reference points " 282 "will be computed. This part is a rectangle." 284 std::cout <<
"Click first on the top left corner and then on the " 285 "bottom right corner." 288 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());
299 nbrRef = surf.buildReference(Iref, corners[0], height, width);
303 nbrRef = surf.buildReference(Iref);
307 std::cerr <<
"No reference point" << std::endl;
311 unsigned int nbrPair;
313 display[1].
init(Icur, (
int)(100 + Iref.
getWidth()), 100,
"Current image");
320 if (opt_click_allowed && opt_display) {
321 std::cout <<
"Select a part of the current image where the reference " 322 "will be search. This part is a rectangle." 324 std::cout <<
"Click first on the top left corner and then on the " 325 "bottom right corner." 328 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);
342 nbrPair = surf.matchPoint(Icur);
346 std::cout <<
"No point matched" << std::endl;
350 surf.display(Iref, Icur, 7);
353 if (opt_click_allowed) {
354 std::cout <<
"A click on the reference image to exit..." << std::endl;
360 std::cout <<
"Catch an exception: " << e << std::endl;
367 std::cerr <<
"You do not have 1.1.0 <= OpenCV < 2.3.0 that contains " 368 "opencv_nonfree component..." 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.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
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)
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 ...