53 #include <visp/vpConfig.h>
54 #include <visp/vpDebug.h>
56 #if ((defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) && (VISP_HAVE_OPENCV_VERSION >= 0x020000))
60 #include <visp/vpPlanarObjectDetector.h>
61 #include <visp/vpParseArgv.h>
62 #include <visp/vpConfig.h>
63 #include <visp/vpOpenCVGrabber.h>
64 #include <visp/vpImage.h>
65 #include <visp/vpDisplayX.h>
66 #include <visp/vpDisplayGTK.h>
67 #include <visp/vpDisplayGDI.h>
68 #include <visp/vpHomography.h>
69 #include <visp/vpImageIo.h>
70 #include <visp/vpIoTools.h>
71 #include <visp/vpTime.h>
73 #include <visp/vpV4l2Grabber.h>
74 #include <visp/vp1394TwoGrabber.h>
76 #define GETOPTARGS "hlcdb:i:sp"
78 void usage(
const char *name,
const char *badparam);
79 bool getOptions(
int argc,
const char **argv,
bool &isLearning, std::string& dataFile,
bool& click_allowed,
80 bool& display,
bool& displayPoints,
bool& useSequence, std::string& ipath);
90 void usage(
const char *name,
const char *badparam)
93 Test of detection of planar surface using a Fern classifier. The object needs \
94 first to be learned (-l option). This learning process will create a file used\
95 to detect the object.\n\
98 %s [-l] [-h] [-b] [-c] [-d] [-p] [-i] [-s]\n", name);
105 -i <input image path> \n\
106 Set image input path.\n\
107 From this path read \"ViSP-images/line/image.%%04d.pgm\"\n\
109 Setting the VISP_INPUT_IMAGE_PATH environment\n\
110 variable produces the same behaviour than using\n\
114 database filename to use (default is ./dataPlanar).\n\
117 Disable the mouse click. Useful to automaze the \n\
118 execution of this program without humain intervention.\n\
121 Turn off the display.\n\
124 Turn off the use of the sequence and use a webcam.\n\
127 display points of interest.\n\
130 Print this help.\n");
133 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
154 bool getOptions(
int argc,
const char **argv,
bool &isLearning, std::string& dataFile,
bool& click_allowed,
155 bool& display,
bool& displayPoints,
bool& useSequence, std::string& ipath)
162 case 'c': click_allowed =
false;
break;
163 case 'd': display =
false;
break;
164 case 'l': isLearning =
true;
break;
165 case 'h': usage(argv[0], NULL);
return false;
break;
166 case 'b': dataFile = optarg_;
break;
167 case 'p': displayPoints =
true;
break;
168 case 's': useSequence =
false;
break;
169 case 'i': ipath = optarg_;
break;
171 usage(argv[0], optarg_);
176 if ((c == 1) || (c == -1)) {
178 usage(argv[0], NULL);
179 std::cerr <<
"ERROR: " << std::endl;
180 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
190 main(
int argc,
const char** argv)
193 bool isLearning =
false;
194 std::string dataFile(
"./dataPlanar");
195 bool opt_click_allowed =
true;
196 bool opt_display =
true;
197 std::string objectName(
"object");
198 bool displayPoints =
false;
199 bool useSequence =
true;
200 std::string opt_ipath;
202 std::string env_ipath;
204 std::string filename;
208 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
214 if (! env_ipath.empty()){
219 if (getOptions(argc, argv,
220 isLearning, dataFile, opt_click_allowed, opt_display, displayPoints, useSequence, opt_ipath) ==
false) {
225 if (useSequence && !opt_ipath.empty()){
231 if (useSequence && !opt_ipath.empty() && !env_ipath.empty()) {
232 if (ipath != env_ipath) {
233 std::cout << std::endl
234 <<
"WARNING: " << std::endl;
235 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
236 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
237 <<
" we skip the environment variable." << std::endl;
242 if (useSequence && opt_ipath.empty() && env_ipath.empty()){
243 usage(argv[0], NULL);
244 std::cerr << std::endl
245 <<
"ERROR:" << std::endl;
246 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
248 <<
" environment variable to specify the location of the " << std::endl
249 <<
" image path where test images are located." << std::endl << std::endl;
264 std::ostringstream s;
265 s.setf(std::ios::right, std::ios::adjustfield);
266 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
267 filename = dirname + s.str();
277 vpCTRACE <<
"Load: " << filename << std::endl;
288 std::cerr << std::endl
289 <<
"ERROR:" << std::endl;
290 std::cerr <<
" Cannot read " << filename << std::endl;
291 std::cerr <<
" Check your -i " << ipath <<
" option " << std::endl
292 <<
" or VISP_INPUT_IMAGE_PATH environment variable."
305 std::cout <<
"problem to initialise the framegrabber" << std::endl;
315 #if defined VISP_HAVE_X11
317 #elif defined VISP_HAVE_GTK
319 #elif defined VISP_HAVE_GDI
323 #if defined VISP_HAVE_X11
325 #elif defined VISP_HAVE_GTK
327 #elif defined VISP_HAVE_GDI
337 displayRef.
init(Iref, 100, 100,
"Reference image") ;
341 if (opt_display && opt_click_allowed){
342 std::cout <<
"Click on the top left and the bottom right corners to define the reference plane" << std::endl;
343 for (
int i=0 ; i < 2 ; i++){
345 std::cout << corners[i] << std::endl;
359 if (opt_click_allowed){
360 std::cout <<
"Click on the image to continue" << std::endl;
364 vpRect roi(corners[0], corners[1]);
366 std::cout <<
"> train the classifier on the selected plane (may take up to several minutes)." << std::endl;
380 vpERROR_TRACE(
"cannot load the database with the specified name. Has the object been learned with the -l option? ");
385 planar.
load(dataFile, objectName);
388 vpERROR_TRACE(
"cannot load the database with the specified name. Has the object been learned with the -l option? ");
394 display.
init(I, 110 + (
int)Iref.
getWidth(), 100,
"Current image") ;
399 if (opt_display && opt_click_allowed){
400 std::cout <<
"Click on the reference image to continue" << std::endl;
402 (
char*)
"Click on the reference image to continue",
vpColor::red);
415 s <<
"image." << std::setw(4) << std::setfill(
'0') << iter <<
".pgm";
416 filename = dirname + s.str();
436 std::cout <<
" > computed homography:" << std::endl << H << std::endl;
441 planar.
display(Iref, I, displayPoints);
444 planar.
display(I, displayPoints);
449 std::cout <<
" > reference is not detected in the image" << std::endl;
462 std::cout <<
"Catch an exception: " << e << std::endl;
471 #if ( ! (defined (VISP_HAVE_X11) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI)) )
472 vpERROR_TRACE(
"You do not have X11, GTK or GDI display functionalities...");
474 vpERROR_TRACE(
"You do not have OpenCV-2.0.0 or a more recent release...");
unsigned int getWidth() const
void getHomography(vpHomography &_H) const
Display for windows using GDI (available on any windows 32 platform).
Define the X11 console to display images.
void load(const std::string &dataFilename, const std::string &objName)
Load the Fern classifier.
error that can be emited by ViSP classes.
static double measureTimeMs()
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
bool matchPoint(const vpImage< unsigned char > &I)
This class aims to compute the homography wrt.two images.
void display(vpImage< unsigned char > &I, bool displayKpts=false)
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
unsigned int buildReference(const vpImage< unsigned char > &I)
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const char *title=NULL)
void recordDetector(const std::string &objectName, const std::string &dataFile)
Record the Ferns classifier in the text file.
virtual void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)=0
void acquire(vpImage< unsigned char > &I)
unsigned int getHeight() const
Defines a rectangle in the plane.
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 ...
Class used to detect a planar surface.
static void read(vpImage< unsigned char > &I, const char *filename)
Class for cameras video capture using OpenCV library.
void set_ij(const double ii, const double jj)