39 #include <visp3/core/vpImage.h>
40 #include <visp3/core/vpImageTools.h>
41 #include <visp3/io/vpImageIo.h>
43 #include <visp3/core/vpCameraParameters.h>
44 #include <visp3/core/vpTime.h>
45 #include <visp3/robot/vpSimulatorCamera.h>
47 #include <visp3/core/vpHomogeneousMatrix.h>
48 #include <visp3/core/vpMath.h>
49 #include <visp3/gui/vpDisplayD3D.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/visual_features/vpFeatureLuminance.h>
57 #include <visp3/vs/vpServo.h>
60 #include <visp3/robot/vpImageSimulator.h>
63 #include <visp3/core/vpIoTools.h>
64 #include <visp3/io/vpParseArgv.h>
67 #define GETOPTARGS "cdi:n:h"
69 void usage(
const char *name,
const char *badparam, std::string ipath,
int niter);
70 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter);
82 void usage(
const char *name,
const char *badparam, std::string ipath,
int niter)
85 Tracking of Surf key-points.\n\
88 %s [-i <input image path>] [-c] [-d] [-n <number of iterations>] [-h]\n",
93 -i <input image path> %s\n\
94 Set image input path.\n\
95 From this path read \"doisneau/doisneau.jpg\"\n\
97 Setting the VISP_INPUT_IMAGE_PATH environment\n\
98 variable produces the same behaviour than using\n\
102 Disable the mouse click. Useful to automate the \n\
103 execution of this program without human intervention.\n\
106 Turn off the display.\n\
109 Number of iterations.\n\
113 ipath.c_str(), niter);
116 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
132 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &click_allowed,
bool &display,
int &niter)
140 click_allowed =
false;
149 niter = atoi(optarg_);
152 usage(argv[0],
nullptr, ipath, niter);
156 usage(argv[0], optarg_, ipath, niter);
161 if ((c == 1) || (c == -1)) {
163 usage(argv[0],
nullptr, ipath, niter);
164 std::cerr <<
"ERROR: " << std::endl;
165 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
172 int main(
int argc,
const char **argv)
174 #if (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
176 std::string env_ipath;
177 std::string opt_ipath;
179 std::string filename;
180 bool opt_click_allowed =
true;
181 bool opt_display =
true;
189 if (!env_ipath.empty())
193 if (getOptions(argc, argv, opt_ipath, opt_click_allowed, opt_display, opt_niter) ==
false) {
198 if (!opt_ipath.empty())
203 if (!opt_ipath.empty() && !env_ipath.empty()) {
204 if (ipath != env_ipath) {
205 std::cout << std::endl <<
"WARNING: " << std::endl;
206 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
207 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
208 <<
" we skip the environment variable." << std::endl;
213 if (opt_ipath.empty() && env_ipath.empty()) {
214 usage(argv[0],
nullptr, ipath, opt_niter);
215 std::cerr << std::endl <<
"ERROR:" << std::endl;
216 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
217 <<
" environment variable to specify the location of the " << std::endl
218 <<
" image path where test images are located." << std::endl
228 for (
int i = 0; i < 4; i++)
253 sim.
init(Itexture, X);
272 #if defined(VISP_HAVE_X11)
274 #elif defined(VISP_HAVE_GDI)
276 #elif defined(VISP_HAVE_GTK)
278 #elif defined(HAVE_OPENCV_HIGHGUI)
282 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_OPENCV)
284 d.
init(I, 20, 10,
"Photometric visual servoing : s");
288 if (opt_display && opt_click_allowed) {
289 std::cout <<
"Click in the image to continue..." << std::endl;
309 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
314 if (opt_display && opt_click_allowed) {
315 std::cout <<
"Click in the image to continue..." << std::endl;
326 #if defined(VISP_HAVE_X11)
328 #elif defined(VISP_HAVE_GDI)
330 #elif defined(VISP_HAVE_GTK)
333 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
335 d1.
init(Idiff, 40 +
static_cast<int>(I.
getWidth()), 10,
"photometric visual servoing : s-s* ");
342 robot.setSamplingTime(0.04);
344 robot.setPosition(wMc);
381 double normError = 0;
387 std::cout <<
"--------------------------------------------" << iter++ << std::endl;
392 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
399 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK)
411 std::cout <<
" |e| = " << normError << std::endl;
412 std::cout <<
" |v| = " << sqrt(v.
sumSquare()) << std::endl;
416 wMc = robot.getPosition();
418 }
while (normError > 10000 && iter < opt_niter);
421 std::cout <<
"Time to convergence: " << chrono.
getDurationMs() <<
" ms" << std::endl;
429 std::cout <<
"Catch an exception: " << e << std::endl;
435 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...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_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.
void init(unsigned int _nbr, unsigned int _nbc, double _Z)
void setCameraParameters(vpCameraParameters &_cam)
void buildFrom(vpImage< unsigned char > &I)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
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.
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.