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/vpDisplayFactory.h>
50#include <visp3/io/vpParseArgv.h>
51#include <visp3/visual_features/vpFeatureLuminance.h>
52#include <visp3/vs/vpServo.h>
55#include <visp3/robot/vpImageSimulator.h>
58#include <visp3/core/vpIoTools.h>
59#include <visp3/io/vpParseArgv.h>
62#define GETOPTARGS "cdi:n:h"
64#ifdef ENABLE_VISP_NAMESPACE
68void usage(
const char *name,
const char *badparam,
const std::string &ipath,
int niter);
69bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter);
81void usage(
const char *name,
const char *badparam,
const std::string &ipath,
int niter)
84Tracking of Surf key-points.\n\
87 %s [-i <input image path>] [-c] [-d] [-n <number of iterations>] [-h]\n",
92 -i <input image path> %s\n\
93 Set image input path.\n\
94 From this path read \"doisneau/doisneau.jpg\"\n\
96 Setting the VISP_INPUT_IMAGE_PATH environment\n\
97 variable produces the same behaviour than using\n\
101 Disable the mouse click. Useful to automate the \n\
102 execution of this program without human intervention.\n\
105 Turn off the display.\n\
108 Number of iterations.\n\
112 ipath.c_str(), niter);
115 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
131bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter)
139 click_allowed =
false;
148 niter = atoi(optarg_);
151 usage(argv[0],
nullptr, ipath, niter);
155 usage(argv[0], optarg_, ipath, niter);
160 if ((c == 1) || (c == -1)) {
162 usage(argv[0],
nullptr, ipath, niter);
163 std::cerr <<
"ERROR: " << std::endl;
164 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
171int main(
int argc,
const char **argv)
173#if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
174#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
175 std::shared_ptr<vpDisplay>
d, d1;
181 std::string env_ipath;
182 std::string opt_ipath;
185 bool opt_click_allowed =
true;
186 bool opt_display =
true;
194 if (!env_ipath.empty())
198 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_niter) ==
false) {
203 if (!opt_ipath.empty())
208 if (!opt_ipath.empty() && !env_ipath.empty()) {
209 if (ipath != env_ipath) {
210 std::cout << std::endl <<
"WARNING: " << std::endl;
211 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
212 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
213 <<
" we skip the environment variable." << std::endl;
218 if (opt_ipath.empty() && env_ipath.empty()) {
219 usage(argv[0],
nullptr, ipath, opt_niter);
220 std::cerr << std::endl <<
"ERROR:" << std::endl;
221 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
222 <<
" environment variable to specify the location of the " << std::endl
223 <<
" image path where test images are located." << std::endl
233 for (
int i = 0;
i < 4;
i++)
258 sim.
init(Itexture, X);
276#if defined(VISP_HAVE_DISPLAY)
278#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
286 if (opt_display && opt_click_allowed) {
287 std::cout <<
"Click in the image to continue..." << std::endl;
307#if defined(VISP_HAVE_DISPLAY)
312 if (opt_display && opt_click_allowed) {
313 std::cout <<
"Click in the image to continue..." << std::endl;
324#if defined(VISP_HAVE_DISPLAY)
326#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
338 wMc = wMo *
cMo.inverse();
339 robot.setPosition(wMc);
349 sI.
init(I.getHeight(), I.getWidth(), Z);
355 sId.
init(I.getHeight(), I.getWidth(), Z);
376 double normError = 0;
382 std::cout <<
"--------------------------------------------" <<
iter++ << std::endl;
387#if defined(VISP_HAVE_DISPLAY)
394#if defined(VISP_HAVE_DISPLAY)
406 std::cout <<
" |e| = " << normError << std::endl;
407 std::cout <<
" |v| = " << sqrt(
v.sumSquare()) << std::endl;
411 wMc = robot.getPosition();
413 }
while (normError > 10000 && iter < opt_niter);
416 std::cout <<
"Time to convergence: " << chrono.
getDurationMs() <<
" ms" << std::endl;
421#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
432 std::cout <<
"Catch an exception: " <<
e << std::endl;
433#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
446 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.
Class that defines generic functionalities for display.
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 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)
Definition of the vpImage class member functions.
static double rad(double deg)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
virtual void setSamplingTime(const double &delta_t)
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
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.
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.