50 #include <visp3/core/vpConfig.h> 51 #include <visp3/core/vpDebug.h> 53 #if ((defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && \ 54 (VISP_HAVE_OPENCV_VERSION >= 0x020000) && (VISP_HAVE_OPENCV_VERSION < 0x030000)) 59 #include <visp3/core/vpConfig.h> 60 #include <visp3/core/vpImage.h> 61 #include <visp3/core/vpIoTools.h> 62 #include <visp3/core/vpTime.h> 63 #include <visp3/gui/vpDisplayGDI.h> 64 #include <visp3/gui/vpDisplayGTK.h> 65 #include <visp3/gui/vpDisplayX.h> 66 #include <visp3/io/vpImageIo.h> 67 #include <visp3/io/vpParseArgv.h> 68 #include <visp3/sensor/vp1394TwoGrabber.h> 69 #include <visp3/sensor/vpV4l2Grabber.h> 70 #include <visp3/vision/vpHomography.h> 71 #include <visp3/vision/vpPlanarObjectDetector.h> 73 #define GETOPTARGS "hlcdb:i:p" 75 void usage(
const char *name,
const char *badparam);
76 bool getOptions(
int argc,
const char **argv,
bool &isLearning, std::string &dataFile,
bool &click_allowed,
77 bool &display,
bool &displayPoints, std::string &ipath);
87 void usage(
const char *name,
const char *badparam)
90 Test of detection of planar surface using a Fern classifier. The object needs \ 91 first to be learned (-l option). This learning process will create a file used\ 92 to detect the object.\n\ 95 %s [-l] [-h] [-b] [-c] [-d] [-p] [-i] [-s]\n", name);
102 -i <input image path> \n\ 103 Set image input path.\n\ 104 From this path read \"line/image.%%04d.pgm\"\n\ 106 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 107 variable produces the same behaviour than using\n\ 111 database filename to use (default is ./dataPlanar).\n\ 114 Disable the mouse click. Useful to automaze the \n\ 115 execution of this program without humain intervention.\n\ 118 Turn off the display.\n\ 121 Turn off the use of the sequence and use a webcam.\n\ 124 display points of interest.\n\ 127 Print this help.\n");
130 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
149 bool getOptions(
int argc,
const char **argv,
bool &isLearning, std::string &dataFile,
bool &click_allowed,
150 bool &display,
bool &displayPoints, std::string &ipath)
158 click_allowed =
false;
167 usage(argv[0], NULL);
174 displayPoints =
true;
180 usage(argv[0], optarg_);
186 if ((c == 1) || (c == -1)) {
188 usage(argv[0], NULL);
189 std::cerr <<
"ERROR: " << std::endl;
190 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
197 int main(
int argc,
const char **argv)
200 bool isLearning =
false;
201 std::string dataFile(
"./dataPlanar");
202 bool opt_click_allowed =
true;
203 bool opt_display =
true;
204 std::string objectName(
"object");
205 bool displayPoints =
false;
206 std::string opt_ipath;
208 std::string env_ipath;
210 std::string filename;
217 if (!env_ipath.empty()) {
222 if (getOptions(argc, argv, isLearning, dataFile, opt_click_allowed, opt_display, displayPoints, opt_ipath) ==
228 if (!opt_ipath.empty()) {
234 if (!opt_ipath.empty() && !env_ipath.empty()) {
235 if (ipath != env_ipath) {
236 std::cout << std::endl <<
"WARNING: " << std::endl;
237 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 238 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
239 <<
" we skip the environment variable." << std::endl;
244 if (opt_ipath.empty() && env_ipath.empty()) {
245 usage(argv[0], NULL);
246 std::cerr << std::endl <<
"ERROR:" << std::endl;
247 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
248 <<
" environment variable to specify the location of the " << std::endl
249 <<
" image path where test images are located." << std::endl
263 std::ostringstream s;
264 s.setf(std::ios::right, std::ios::adjustfield);
265 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
275 std::cout <<
"Load: " << filename << std::endl;
283 std::cerr << std::endl <<
"ERROR:" << std::endl;
284 std::cerr <<
" Cannot read " << filename << std::endl;
285 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
286 <<
" or VISP_INPUT_IMAGE_PATH environment variable." << std::endl;
290 #if defined VISP_HAVE_X11 292 #elif defined VISP_HAVE_GTK 294 #elif defined VISP_HAVE_GDI 298 #if defined VISP_HAVE_X11 300 #elif defined VISP_HAVE_GTK 302 #elif defined VISP_HAVE_GDI 307 vpPlanarObjectDetector planar;
312 displayRef.
init(Iref, 100, 100,
"Reference image");
316 if (opt_display && opt_click_allowed) {
317 std::cout <<
"Click on the top left and the bottom right corners to " 318 "define the reference plane" 320 for (
int i = 0; i < 2; i++) {
322 std::cout << corners[i] << std::endl;
336 if (opt_click_allowed) {
337 std::cout <<
"Click on the image to continue" << std::endl;
341 vpRect roi(corners[0], corners[1]);
343 std::cout <<
"> train the classifier on the selected plane (may take " 344 "up to several minutes)." 351 planar.buildReference(Iref, roi);
354 planar.recordDetector(objectName, dataFile);
358 vpERROR_TRACE(
"cannot load the database with the specified name. Has " 359 "the object been learned with the -l option? ");
364 planar.load(dataFile, objectName);
366 vpERROR_TRACE(
"cannot load the database with the specified name. Has " 367 "the object been learned with the -l option? ");
373 display.
init(I, 110 + (
int)Iref.
getWidth(), 100,
"Current image");
378 if (opt_display && opt_click_allowed) {
379 std::cout <<
"Click on the reference image to continue" << std::endl;
392 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
403 bool isDetected = planar.matchPoint(I);
408 planar.getHomography(H);
409 std::cout <<
" > computed homography:" << std::endl << H << std::endl;
414 planar.display(Iref, I, displayPoints);
417 planar.display(I, displayPoints);
421 std::cout <<
" > reference is not detected in the image" << std::endl;
433 std::cout <<
"Catch an exception: " << e << std::endl;
441 #if (!(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI))) 442 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..." << std::endl;
443 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
444 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
445 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
446 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
448 std::cout <<
"You do not have OpenCV functionalities" << std::endl;
449 std::cout <<
"Tip:" << std::endl;
450 std::cout <<
"- Install OpenCV, configure again ViSP using cmake and build again this example" << std::endl;
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
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.
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Implementation of an homography and operations on homographies.
static void display(const vpImage< unsigned char > &I)
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)
void set_ij(double ii, double jj)
unsigned int getHeight() const
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
Defines a rectangle in the plane.
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const