54#include <visp3/core/vpConfig.h>
55#include <visp3/core/vpDebug.h>
57#if defined(VISP_HAVE_DISPLAY) && \
58 (defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
60#include <visp3/core/vpImage.h>
61#include <visp3/core/vpImagePoint.h>
62#include <visp3/core/vpIoTools.h>
63#include <visp3/io/vpImageIo.h>
65#include <visp3/gui/vpDisplayFactory.h>
67#include <visp3/blob/vpDot.h>
68#include <visp3/core/vpIoTools.h>
69#include <visp3/core/vpPixelMeterConversion.h>
70#include <visp3/io/vpParseArgv.h>
71#include <visp3/vision/vpPose.h>
74#define GETOPTARGS "cdi:p:hf:l:s:"
76#ifdef ENABLE_VISP_NAMESPACE
93void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath,
unsigned first,
94 unsigned last,
unsigned step)
96#if defined(VISP_HAVE_DATASET)
97#if VISP_HAVE_DATASET_VERSION >= 0x030600
98 std::string ext(
"png");
100 std::string ext(
"pgm");
104 std::string ext(
"png");
111 %s [-i <input image path>] [-p <personal image path>]\n\
112 [-f <first image>] [-l <last image>] [-s <step>][-c] [-d] [-h]\n",
117 -i <input image path> %s\n\
118 Set image input path.\n\
119 From this path read images \n\
120 \"cube/image.%%04d.%s\"\n\
121 Setting the VISP_INPUT_IMAGE_PATH environment\n\
122 variable produces the same behaviour than using\n\
125 -p <personal image path> %s\n\
126 Specify a personal sequence containing images \n\
128 By image sequence, we mean one file per image.\n\
129 The format is selected by analyzing the filename extension.\n\
130 Example : \"/Temp/visp-images/cube/image.%%04d.%s\"\n\
131 %%04d is for the image numbering.\n\
133 -f <first image> %u\n\
134 First image number of the sequence.\n\
136 -l <last image> %u\n\
137 Last image number of the sequence.\n\
140 Step between two images.\n\
143 Disable the mouse click. Useful to automate the \n\
144 execution of this program without human intervention.\n\
147 Turn off the display.\n\
151 ipath.c_str(), ext.c_str(), ppath.c_str(), ext.c_str(), first, last, step);
154 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
177bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
unsigned &first,
unsigned &last,
178 unsigned &step,
bool &click_allowed,
bool &display)
186 click_allowed =
false;
198 first =
static_cast<unsigned int>(atoi(optarg_));
201 last =
static_cast<unsigned int>(atoi(optarg_));
204 step =
static_cast<unsigned int>(atoi(optarg_));
207 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
211 usage(argv[0], optarg_, ipath, ppath, first, last, step);
216 if ((c == 1) || (c == -1)) {
218 usage(argv[0],
nullptr, ipath, ppath, first, last, step);
219 std::cerr <<
"ERROR: " << std::endl;
220 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
227int main(
int argc,
const char **argv)
230#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
231 std::shared_ptr<vpDisplay> display;
237 std::string env_ipath;
238 std::string opt_ipath;
240 std::string opt_ppath;
243 unsigned opt_first = 0;
244 unsigned opt_last = 80;
245 unsigned opt_step = 1;
246 bool opt_click_allowed =
true;
247 bool opt_display =
true;
250#if defined(VISP_HAVE_DATASET)
251#if VISP_HAVE_DATASET_VERSION >= 0x030600
252 std::string ext(
"png");
254 std::string ext(
"pgm");
258 std::string ext(
"png");
261 std::cout <<
"-------------------------------------------------------" << std::endl;
262 std::cout <<
" poseVirtualVS.cpp" << std::endl << std::endl;
264 std::cout <<
" Example of dots tracking in an image sequence and pose "
267 std::cout <<
"-------------------------------------------------------" << std::endl;
268 std::cout << std::endl;
275 if (!env_ipath.empty())
279 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_last, opt_step, opt_click_allowed,
280 opt_display) ==
false) {
285 if (!opt_ipath.empty())
290 if (opt_ipath.empty() && opt_ppath.empty()) {
291 if (ipath != env_ipath) {
292 std::cout << std::endl <<
"WARNING: " << std::endl;
293 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
294 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
295 <<
" we skip the environment variable." << std::endl;
299 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
300 usage(argv[0],
nullptr, ipath, opt_ppath, opt_first, opt_last, opt_step);
301 std::cerr << std::endl <<
"ERROR:" << std::endl;
302 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
303 <<
" environment variable to specify the location of the " << std::endl
304 <<
" image path where test images are located." << std::endl
305 <<
" Use -p <personal image path> option if you want to " << std::endl
306 <<
" use personal images" << std::endl
316 unsigned iter = opt_first;
318 if (opt_ppath.empty()) {
334 for (i = 0;
i < 4; ++
i) {
341 d[
i].setGraphics(
true);
344 d[
i].setGraphics(
false);
353 if (opt_ppath.empty()) {
354 std::cerr << std::endl <<
"ERROR:" << std::endl;
355 std::cerr <<
" Cannot read " <<
filename << std::endl;
356 std::cerr <<
" Check your -i " << ipath <<
" option, " << std::endl
357 <<
" or VISP_INPUT_IMAGE_PATH environment variable" << std::endl;
360 std::cerr << std::endl <<
"ERROR:" << std::endl;
361 std::cerr <<
" Cannot read " <<
filename << std::endl;
362 std::cerr <<
" or your -p " << opt_ppath <<
" option " << std::endl << std::endl;
372#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
389 if (opt_display && opt_click_allowed) {
391 std::cout <<
"Click the four white dots on the object corner clockwise" << std::endl;
392 for (i = 0;
i < 4; ++
i) {
400 d[
i].initTracking(I);
410 d[
i].track(I, cog[i]);
417 d[0].initTracking(I, cog[0]);
418 d[0].track(I, cog[0]);
423 d[1].initTracking(I, cog[1]);
424 d[1].track(I, cog[1]);
429 d[2].initTracking(I, cog[2]);
430 d[2].track(I, cog[2]);
435 d[3].initTracking(I, cog[3]);
436 d[3].track(I, cog[3]);
457 for (i = 0;
i < 4; ++
i) {
499 for (i = 0;
i < 4; ++
i) {
513 for (i = 0;
i < 4; ++
i) {
534 while (iter < opt_last) {
536 if (opt_ppath.empty()) {
544 std::cout <<
"Read image: " <<
filename << std::endl;
557 for (i = 0;
i < 4; ++
i) {
559 d[
i].track(I, cog[i]);
586 if (opt_click_allowed) {
602 if (opt_click_allowed) {
606#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
607 if (display !=
nullptr) {
614 std::cout <<
"Catch a ViSP exception: " <<
e << std::endl;
615#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
616 if (display !=
nullptr) {
623#elif !(defined(VISP_HAVE_LAPACK) || defined(VISP_HAVE_EIGEN3) || defined(VISP_HAVE_OPENCV))
626 std::cout <<
"Cannot run this example: install Lapack, Eigen3 or OpenCV" << std::endl;
632 std::cout <<
"You do not have X11, or GTK, or GDI (Graphical Device Interface) functionalities to display images..."
634 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
635 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
636 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
637 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Generic class defining intrinsic camera parameters.
static const vpColor none
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 displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
error that can be emitted by ViSP classes.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void set_x(double x)
Set the point x coordinate in the image plane.
void setWorldCoordinates(double oX, double oY, double oZ)
void set_y(double y)
Set the point y coordinate in the image plane.
Class used for pose computation from N points (pose from point only). Some of the algorithms implemen...
void addPoint(const vpPoint &P)
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
static void display(vpImage< unsigned char > &I, vpHomogeneousMatrix &cMo, vpCameraParameters &cam, double size, vpColor col=vpColor::none)
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.
VISP_EXPORT int wait(double t0, double t)