47 #include <visp3/core/vpCameraParameters.h> 48 #include <visp3/core/vpHomogeneousMatrix.h> 49 #include <visp3/core/vpImage.h> 50 #include <visp3/core/vpIoTools.h> 51 #include <visp3/core/vpMath.h> 52 #include <visp3/core/vpTime.h> 53 #include <visp3/core/vpVelocityTwistMatrix.h> 54 #include <visp3/gui/vpDisplayD3D.h> 55 #include <visp3/gui/vpDisplayGDI.h> 56 #include <visp3/gui/vpDisplayGTK.h> 57 #include <visp3/gui/vpDisplayOpenCV.h> 58 #include <visp3/gui/vpDisplayX.h> 59 #include <visp3/gui/vpPlot.h> 60 #include <visp3/io/vpImageIo.h> 61 #include <visp3/io/vpParseArgv.h> 62 #include <visp3/robot/vpSimulatorCamera.h> 63 #include <visp3/robot/vpWireFrameSimulator.h> 64 #include <visp3/visual_features/vpFeatureBuilder.h> 65 #include <visp3/visual_features/vpFeaturePoint.h> 66 #include <visp3/vs/vpServo.h> 68 #define GETOPTARGS "dhp" 70 #if defined(VISP_HAVE_DISPLAY) \ 71 && (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 82 void usage(
const char *name, std::string ipath,
const char *badparam)
85 Demonstration of the wireframe simulator with a simple visual servoing.\n\ 87 The visual servoing consists in bringing the camera at a desired \n\ 88 position from the object.\n\ 90 The visual features used to compute the pose of the camera and \n\ 91 thus the control law are four points.\n\ 93 This demonstration explains also how to move the object around a world\n\ 94 reference frame. Here, the movement is a rotation around the x and y axis\n\ 95 at a given distance from the world frame. In fact the object trajectory\n\ 96 is on a sphere whose center is the origin of the world frame.\n\ 99 %s [-d] [-p] [-h]\n", name);
103 -i <input image path> %s\n\ 104 Set mire.pgm image input path.\n\ 105 From this path read \"mire/mire.pgm\" image.\n\ 106 Setting the VISP_INPUT_IMAGE_PATH environment variable \n\ 107 produces the same behaviour than using this option.\n\ 110 Turn off the display.\n\ 113 Turn off the plotter.\n\ 116 Print the help.\n", ipath.c_str());
119 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
135 bool getOptions(
int argc,
const char **argv, std::string &ipath,
bool &display,
bool &plot)
152 usage(argv[0], ipath, NULL);
156 usage(argv[0], ipath, optarg_);
161 if ((c == 1) || (c == -1)) {
163 usage(argv[0], ipath, NULL);
164 std::cerr <<
"ERROR: " << std::endl;
165 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
172 int main(
int argc,
const char **argv)
175 bool opt_display =
true;
176 bool opt_plot =
true;
177 std::string opt_ipath;
178 std::string env_ipath;
180 std::string filename;
183 if (getOptions(argc, argv, opt_ipath, opt_display, opt_plot) ==
false) {
191 #if defined VISP_HAVE_X11 193 #elif defined VISP_HAVE_OPENCV 195 #elif defined VISP_HAVE_GDI 197 #elif defined VISP_HAVE_D3D9 199 #elif defined VISP_HAVE_GTK 205 display[0].
init(Iint, 100, 100,
"The internal view");
206 display[1].
init(Iext1, 100, 100,
"The first external view");
207 display[2].
init(Iext2, 100, 100,
"The second external view");
222 plotter =
new vpPlot(2, 480, 640, 750, 550,
"Real time curves plotter");
223 plotter->
setTitle(0,
"Visual features error");
224 plotter->
setTitle(1,
"Camera velocities");
227 plotter->
setLegend(0, 0,
"error_feat_p1_x");
228 plotter->
setLegend(0, 1,
"error_feat_p1_y");
229 plotter->
setLegend(0, 2,
"error_feat_p2_x");
230 plotter->
setLegend(0, 3,
"error_feat_p2_y");
231 plotter->
setLegend(0, 4,
"error_feat_p3_x");
232 plotter->
setLegend(0, 5,
"error_feat_p3_y");
233 plotter->
setLegend(0, 6,
"error_feat_p4_x");
234 plotter->
setLegend(0, 7,
"error_feat_p4_y");
245 float sampling_time = 0.020f;
271 for (
int i = 0; i < 4; i++)
276 for (
int i = 0; i < 4; i++)
280 for (
int i = 0; i < 4; i++)
281 point[i].track(cdMo);
284 for (
int i = 0; i < 4; i++)
298 for (
int i = 0; i < 4; i++)
303 std::list<vpImageSimulator> list;
307 for (
int i = 0; i < 4; i++)
329 if (!env_ipath.empty())
332 if (!opt_ipath.empty())
337 imsim.
init(filename.c_str(), X);
339 list.push_back(imsim);
394 std::cout <<
"Click on a display" << std::endl;
411 while (iter++ < max_iter && !stop) {
426 for (
int i = 0; i < 4; i++) {
447 camoMf.buildFrom(0, 0.0, 1.5, 0,
vpMath::rad(150), 0);
452 plotter->
plot(1, iter, v);
478 std::stringstream ss;
479 ss <<
"Loop time: " << t - t_prev <<
" ms";
492 std::cout <<
"|| s - s* || = " << (task.
getError()).sumSquare() << std::endl;
495 if (opt_plot && plotter != NULL) {
513 std::cout <<
"Catch an exception: " << e << std::endl;
517 #elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV)) 520 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
526 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface), or GTK functionalities to display images..." << std::endl;
527 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
528 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
529 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
530 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
void setPosition(const vpHomogeneousMatrix &wMc)
Implementation of a matrix and operations on matrices.
VISP_EXPORT int wait(double t0, double t)
void init(const vpImage< unsigned char > &I, vpColVector *X)
void setWorldCoordinates(double oX, double oY, double oZ)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines the simplest robot: a free flying camera.
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void set_fMo(const vpHomogeneousMatrix &fMo_)
Display for windows using GDI (available on any windows 32 platform).
void set_eJe(const vpMatrix &eJe_)
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...
static const vpColor none
error that can be emited by ViSP classes.
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void setExternalCameraPosition(const vpHomogeneousMatrix &cam_Mf)
void setDesiredCameraPosition(const vpHomogeneousMatrix &cdMo_)
void setLegend(unsigned int graphNum, unsigned int curveNum, const std::string &legend)
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void setMaxRotationVelocity(double maxVr)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
virtual void setSamplingTime(const double &delta_t)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
vpColVector getError() const
vpHomogeneousMatrix get_fMo() const
vpColVector computeControlLaw()
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Generic class defining intrinsic camera parameters.
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
Class which enables to project an image in the 3D space and get the view of a virtual camera...
void setTitle(unsigned int graphNum, const std::string &title)
void initScene(const vpSceneObject &obj, const vpSceneDesiredObject &desiredObject)
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
vpHomogeneousMatrix getPosition() const
void plot(unsigned int graphNum, unsigned int curveNum, double x, double y)
void getExternalImage(vpImage< unsigned char > &I)
Implementation of a wire frame simulator. Compared to the vpSimulator class, it does not require thir...
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
static double rad(double deg)
void setExternalCameraParameters(const vpCameraParameters &cam)
void setCameraPositionRelObj(const vpHomogeneousMatrix &cMo_)
void initGraph(unsigned int graphNum, unsigned int curveNbr)
void getInternalImage(vpImage< unsigned char > &I)
static void setWindowPosition(const vpImage< unsigned char > &I, int winx, int winy)
Implementation of column vector and the associated operations.
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
void set_cVe(const vpVelocityTwistMatrix &cVe_)
vpHomogeneousMatrix inverse() const
void setInternalCameraParameters(const vpCameraParameters &cam)
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void get_eJe(vpMatrix &eJe)
void setServo(const vpServoType &servo_type)
void setMaxTranslationVelocity(double maxVt)
vpHomogeneousMatrix getExternalCameraPosition() const