33 #include <visp3/core/vpConfig.h>
34 #include <visp3/core/vpCameraParameters.h>
35 #include <visp3/core/vpGaussRand.h>
36 #include <visp3/core/vpHomogeneousMatrix.h>
37 #include <visp3/core/vpMeterPixelConversion.h>
38 #include <visp3/core/vpPixelMeterConversion.h>
40 #ifdef VISP_HAVE_DISPLAY
41 #include <visp3/gui/vpPlot.h>
42 #include <visp3/gui/vpDisplayFactory.h>
45 #include <visp3/vision/vpPose.h>
48 #include <visp3/core/vpUKSigmaDrawerMerwe.h>
49 #include <visp3/core/vpUnscentedKalman.h>
52 #ifdef ENABLE_VISP_NAMESPACE
56 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
68 x_kPlus1[0] = x[0] * std::cos(x[3]) - x[1] * std::sin(x[3]);
69 x_kPlus1[1] = x[0] * std::sin(x[3]) + x[1] * std::cos(x[3]);
107 wX[0] = m_R * std::cos(m_w * t + m_phi);
108 wX[1] = m_R * std::sin(m_w * t + m_phi);
139 const std::vector<vpColVector> &markers,
const double &noise_stdev,
const long &seed)
144 , m_rng(noise_stdev, 0., seed)
156 unsigned int nbMarkers =
static_cast<unsigned int>(m_markers.size());
161 for (
unsigned int i = 0; i < nbMarkers; ++i) {
163 double u = 0., v = 0.;
182 unsigned int nbMarkers =
static_cast<unsigned int>(m_markers.size());
187 for (
unsigned int i = 0; i < nbMarkers; ++i) {
189 double u = 0., v = 0.;
210 unsigned int sizeMeasurement = measurementsGT.
size();
211 for (
unsigned int i = 0; i < sizeMeasurement; ++i) {
212 measurementsNoisy[i] += m_rng();
214 return measurementsNoisy;
222 std::vector<vpColVector> m_markers;
241 for (
unsigned int i = 0; i < point.size(); i++) {
257 const double dt = 0.001;
258 const double sigmaMeasurements = 2.;
259 const double radius = 0.25;
260 const double w = 2 * M_PI * 10;
261 const double phi = 2;
264 const std::vector<vpColVector> markers = {
vpColVector({-0.05, 0.05, 0., 1.}),
268 const unsigned int nbMarkers =
static_cast<unsigned int>(markers.size());
269 std::vector<vpPoint> markersAsVpPoint;
270 for (
unsigned int i = 0; i < nbMarkers; ++i) {
272 markersAsVpPoint.push_back(
vpPoint(marker[0], marker[1], marker[2]));
275 const long seed = 42;
277 cMw[0][0] = 1.; cMw[0][1] = 0.; cMw[0][2] = 0.; cMw[0][3] = 0.2;
278 cMw[1][0] = 0.; cMw[1][1] = -1.; cMw[1][2] = 0.; cMw[1][3] = 0.3;
279 cMw[2][0] = 0.; cMw[2][1] = 0.; cMw[2][2] = -1.; cMw[2][3] = 1.;
282 wMo[0][0] = 1.; wMo[0][1] = 0.; wMo[0][2] = 0.; wMo[0][3] = radius;
283 wMo[1][0] = 0.; wMo[1][1] = 1.; wMo[1][2] = 0.; wMo[1][3] = 0;
284 wMo[2][0] = 0.; wMo[2][1] = 0.; wMo[2][2] = 1.; wMo[2][3] = 0.2;
287 const double wZ = wMo[2][3];
293 double px = 600;
double py = 600;
double u0 = 320;
double v0 = 240;
300 std::shared_ptr<vpUKSigmaDrawerAbstract> drawer = std::make_shared<vpUKSigmaDrawerMerwe>(4, 0.001, 2., -1);
305 R1landmark[0][0] = sigmaMeasurements*sigmaMeasurements;
306 R1landmark[1][1] = sigmaMeasurements*sigmaMeasurements;
307 vpMatrix R(2*nbMarkers, 2 * nbMarkers);
308 for (
unsigned int i = 0; i < nbMarkers; ++i) {
309 R.insert(R1landmark, 2*i, 2*i);
314 const double processVariance = 0.000025;
317 Q = Q * processVariance;
332 X0[3] = 0.75 * w * dt;
338 using std::placeholders::_1;
349 #ifdef VISP_HAVE_DISPLAY
352 plot.initGraph(0, 3);
353 plot.setTitle(0,
"Position of the robot wX");
354 plot.setUnitX(0,
"Position along x(m)");
355 plot.setUnitY(0,
"Position along y (m)");
356 plot.setLegend(0, 0,
"GT");
357 plot.setLegend(0, 1,
"Filtered");
358 plot.setLegend(0, 2,
"Measure");
359 plot.initRange(0, -1.25 * radius, 1.25 * radius, -1.25 * radius, 1.25 * radius);
370 #ifdef VISP_HAVE_DISPLAY
384 for (
unsigned int i = 0; i < 200; ++i) {
387 object_pos =
object.move(dt *
static_cast<double>(i));
392 vpColVector z = markerMeas.measureWithNoise(object_pos);
401 #ifdef VISP_HAVE_DISPLAY
405 std::vector<vpImagePoint> ip;
406 for (
unsigned int id = 0;
id < nbMarkers; ++id) {
408 ip.push_back(markerProjNoisy);
414 double wXnoisy = wMo_noisy[0][3];
415 double wYnoisy = wMo_noisy[1][3];
420 plot.plot(0, 0, object_pos[0], object_pos[1]);
424 plot.plot(0, 1, Xest[0], Xest[1]);
427 plot.plot(0, 2, wXnoisy, wYnoisy);
433 vpColVector zGT = markerMeas.measureGT(object_pos);
434 vpColVector zFilt = markerMeas.state_to_measurement(Xest);
435 for (
unsigned int id = 0;
id < nbMarkers; ++id) {
439 vpImagePoint markerProjFilt(zFilt[2*
id + 1], zFilt[2*
id]);
448 ipText.set_i(ipText.get_i() + 20);
450 ipText.set_i(ipText.get_i() + 20);
459 std::cout <<
"Press Enter to quit..." << std::endl;
467 std::cout <<
"This example is only available if you compile ViSP in C++11 standard or higher." << std::endl;
unsigned int size() const
Return the number of elements of the 2D array.
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
Implementation of column vector and the associated operations.
static const vpColor blue
static const vpColor black
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)
Class for generating random number with normal probability density.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
vpColVector state_to_measurement(const vpColVector &x)
[Measurement_function]
vpMarkersMeasurements(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMw, const vpRotationMatrix &wRo, const std::vector< vpColVector > &markers, const double &noise_stdev, const long &seed)
Construct a new vpMarkersMeasurements object.
vpColVector measureGT(const vpColVector &wX)
[Measurement_function]
vpColVector measureWithNoise(const vpColVector &wX)
[GT_measurements]
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
vpColVector move(const double &t) const
Move the object to its new position, expressed in the world frame.
vpObjectSimulator(const double &R, const double &w, const double &phi, const double &wZ)
Construct a new vpObjectSimulator object.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
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)
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.
std::function< vpColVector(const vpColVector &)> vpMeasurementFunction
Measurement function, which converts the prior points in the measurement space. The argument is a poi...
std::function< vpColVector(const vpColVector &, const double &)> vpProcessFunction
Process model function, which projects the sigma points forward in time. The first argument is a sigm...
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT int wait(double t0, double t)