37 #include <visp3/core/vpConfig.h>
38 #include <visp3/core/vpImage.h>
39 #include <visp3/core/vpImageTools.h>
40 #include <visp3/io/vpImageIo.h>
42 #include <visp3/core/vpCameraParameters.h>
43 #include <visp3/core/vpTime.h>
44 #include <visp3/robot/vpSimulatorCamera.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/core/vpMath.h>
48 #include <visp3/gui/vpDisplayD3D.h>
49 #include <visp3/gui/vpDisplayGDI.h>
50 #include <visp3/gui/vpDisplayGTK.h>
51 #include <visp3/gui/vpDisplayOpenCV.h>
52 #include <visp3/gui/vpDisplayX.h>
54 #include <visp3/io/vpParseArgv.h>
55 #include <visp3/visual_features/vpFeatureLuminance.h>
56 #include <visp3/vs/vpServo.h>
59 #include <visp3/robot/vpImageSimulator.h>
62 #include <visp3/core/vpIoTools.h>
63 #include <visp3/io/vpParseArgv.h>
66 #define GETOPTARGS "cdi:n:h"
68 #ifdef ENABLE_VISP_NAMESPACE
72 void usage(
const char *name,
const char *badparam, std::string ipath,
int niter);
73 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter);
85 void usage(
const char *name,
const char *badparam, std::string ipath,
int niter)
88 Tracking of Surf key-points.\n\
91 %s [-i <input image path>] [-c] [-d] [-n <number of iterations>] [-h]\n",
96 -i <input image path> %s\n\
97 Set image input path.\n\
98 From this path read \"doisneau/doisneau.jpg\"\n\
100 Setting the VISP_INPUT_IMAGE_PATH environment\n\
101 variable produces the same behaviour than using\n\
105 Disable the mouse click. Useful to automate the \n\
106 execution of this program without human intervention.\n\
109 Turn off the display.\n\
112 Number of iterations.\n\
116 ipath.c_str(), niter);
119 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
135 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter)
143 click_allowed =
false;
152 niter = atoi(optarg_);
155 usage(argv[0],
nullptr, ipath, niter);
159 usage(argv[0], optarg_, ipath, niter);
164 if ((c == 1) || (c == -1)) {
166 usage(argv[0],
nullptr, ipath, niter);
167 std::cerr <<
"ERROR: " << std::endl;
168 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
175 int main(
int argc,
const char **argv)
177 #if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
179 std::string env_ipath;
180 std::string opt_ipath;
182 std::string filename;
183 bool opt_click_allowed =
true;
184 bool opt_display =
true;
192 if (!env_ipath.empty())
196 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_niter) ==
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],
nullptr, ipath, opt_niter);
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
231 for (
int i = 0; i < 4; i++)
256 sim.
init(Itexture, X);
275 #if defined(VISP_HAVE_X11)
277 #elif defined(VISP_HAVE_GDI)
279 #elif defined(VISP_HAVE_GTK)
281 #elif defined(HAVE_OPENCV_HIGHGUI)
285 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_OPENCV)
287 d.
init(I, 20, 10,
"Photometric visual servoing : s");
291 if (opt_display && opt_click_allowed) {
292 std::cout <<
"Click in the image to continue..." << std::endl;
312 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
317 if (opt_display && opt_click_allowed) {
318 std::cout <<
"Click in the image to continue..." << std::endl;
329 #if defined(VISP_HAVE_X11)
331 #elif defined(VISP_HAVE_GDI)
333 #elif defined(VISP_HAVE_GTK)
336 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
338 d1.
init(Idiff, 40 +
static_cast<int>(I.
getWidth()), 10,
"photometric visual servoing : s-s* ");
345 robot.setSamplingTime(0.04);
347 robot.setPosition(wMc);
384 double normError = 0;
390 std::cout <<
"--------------------------------------------" << iter++ << std::endl;
395 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
402 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
414 std::cout <<
" |e| = " << normError << std::endl;
415 std::cout <<
" |v| = " << sqrt(v.
sumSquare()) << std::endl;
419 wMc = robot.getPosition();
421 }
while (normError > 10000 && iter < opt_niter);
424 std::cout <<
"Time to convergence: " << chrono.
getDurationMs() <<
" ms" << std::endl;
432 std::cout <<
"Catch an exception: " << e << std::endl;
438 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
Generic class defining intrinsic camera parameters.
void start(bool reset=true)
Implementation of column vector and the associated operations.
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...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") VP_OVERRIDE
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="") VP_OVERRIDE
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)
error that can be emitted by ViSP classes.
Class that defines the image luminance visual feature.
vpFeatureLuminance & buildFrom(vpImage< unsigned char > &I)
void init(unsigned int _nbr, unsigned int _nbc, double _Z)
void setCameraParameters(const vpCameraParameters &_cam)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class which enables to project an image in the 3D space and get the view of a virtual camera.
void getImage(vpImage< unsigned char > &I, const vpCameraParameters &cam)
void init(const vpImage< unsigned char > &I, vpColVector *X)
void setInterpolationType(const vpInterpolationType interplt)
void setCameraPosition(const vpHomogeneousMatrix &cMt)
unsigned int getWidth() const
unsigned int getHeight() const
static double rad(double deg)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
Class that defines the simplest robot: a free flying camera.