42#include <visp3/core/vpCameraParameters.h>
43#include <visp3/core/vpHomogeneousMatrix.h>
44#include <visp3/core/vpPixelMeterConversion.h>
45#include <visp3/core/vpPlane.h>
46#include <visp3/core/vpPoint.h>
47#include <visp3/core/vpRGBa.h>
55#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
60#include <visp3/core/vpUniRand.h>
132#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
140 VP_EXPLICIT
vpPose(
const std::vector<vpPoint> &lP);
165 void addPoints(
const std::vector<vpPoint> &lP);
269 bool coplanar(
int &coplanar_plane_type,
double *p_a =
nullptr,
double *p_b =
nullptr,
double *p_c =
nullptr,
double *p_d =
nullptr);
308 double *p_c =
nullptr,
double *p_d =
nullptr);
405 if (t > std::numeric_limits<double>::epsilon()) {
452 if (!computeCovariance) {
453 std::cout <<
"Warning: The covariance matrix has not been computed. See setCovarianceComputation() to do it." << std::endl;
455 return covarianceMatrix;
509 std::vector<vpPoint> vectorOfPoints(
listP.begin(),
listP.end());
510 return vectorOfPoints;
533 static bool computePlanarObjectPoseFromRGBD(
const vpImage<float> &depthMap,
const std::vector<vpImagePoint> &corners,
536 double *confidence_index =
nullptr);
570 static bool computePlanarObjectPoseFromRGBD(
const vpImage<float> &depthMap,
571 const std::vector<std::vector<vpImagePoint> > &corners,
573 const std::vector<std::vector<vpPoint> > &point3d,
575 bool coplanar_points =
true);
596 static int computeRansacIterations(
double probability,
double epsilon,
const int sampleSize = 4,
597 int maxIterations = 2000);
655 static void findMatch(std::vector<vpPoint> &p2D, std::vector<vpPoint> &p3D,
656 const unsigned int &numberOfInlierToReachAConsensus,
const double &threshold,
658 const int &maxNbTrials = 10000,
bool useParallelRansac =
true,
unsigned int nthreads = 0,
659 FuncCheckValidityPose func =
nullptr);
661#ifdef VISP_HAVE_HOMOGRAPHY
689#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
707 template <
typename DataId>
709 const vpPlane &plane_in_camera_frame,
const std::map<DataId, vpPoint> &pts,
710 const std::map<DataId, vpImagePoint> &ips,
const vpCameraParameters &camera_intrinsics,
711 std::optional<vpHomogeneousMatrix> cMo_init = std::nullopt,
bool enable_vvs =
true)
713 if (cMo_init && (!enable_vvs)) {
716 "It doesn't make sense to use an initialized pose without enabling VVS to compute the pose from 4 points"));
728 for (
const auto &[ip_id, ip_unused] : ips) {
730 if (pts.find(ip_id) == end(pts)) {
732 "Cannot compute pose with points and image points which do not have the same IDs"));
736 std::vector<vpPoint> P {}, Q {};
740 for (
const auto &pt_map : pts) {
741 if (ips.find(pt_map.first) != end(ips)) {
745 const auto Z = plane_in_camera_frame.
computeZ(x, y);
752 P.emplace_back(x * Z, y * Z, Z);
761 if (!cMo.isValid()) {
777 static std::optional<vpHomogeneousMatrix> poseVirtualVSWithDepth(
const std::vector<vpPoint> &points,
807 std::vector<vpPoint> c3d;
809 bool computeCovariance;
814 unsigned int ransacNbInlierConsensus;
818 std::vector<vpPoint> ransacInliers;
820 std::vector<unsigned int> ransacInlierIndex;
822 double ransacThreshold;
825 double distToPlaneForCoplanarityTest;
830 std::vector<vpPoint> listOfPoints;
832 bool useParallelRansac;
834 int nbParallelRansacThreads;
842 class vpRansacFunctor
848 vpRansacFunctor(
const vpHomogeneousMatrix &cMo_,
unsigned int ransacNbInlierConsensus_,
const int ransacMaxTrials_,
849 double ransacThreshold_,
unsigned int initial_seed_,
bool checkDegeneratePoints_,
851 : m_best_consensus(), m_checkDegeneratePoints(checkDegeneratePoints_), m_cMo(cMo_), m_foundSolution(false),
852 m_func(func_), m_listOfUniquePoints(listOfUniquePoints_), m_nbInliers(0), m_ransacMaxTrials(ransacMaxTrials_),
853 m_ransacNbInlierConsensus(ransacNbInlierConsensus_), m_ransacThreshold(ransacThreshold_),
854 m_uniRand(initial_seed_)
860 void operator()() { m_foundSolution = poseRansacImpl(); }
865 bool getResult()
const {
return m_foundSolution; }
870 std::vector<unsigned int> getBestConsensus()
const {
return m_best_consensus; }
875 vpHomogeneousMatrix getEstimatedPose()
const {
return m_cMo; }
880 unsigned int getNbInliers()
const {
return m_nbInliers; }
883 std::vector<unsigned int> m_best_consensus;
884 bool m_checkDegeneratePoints;
885 vpHomogeneousMatrix m_cMo;
886 bool m_foundSolution;
887 FuncCheckValidityPose m_func;
888 std::vector<vpPoint> m_listOfUniquePoints;
889 unsigned int m_nbInliers;
890 int m_ransacMaxTrials;
891 unsigned int m_ransacNbInlierConsensus;
892 double m_ransacThreshold;
899 bool poseRansacImpl();
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
static const vpColor none
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
Implementation of an homogeneous matrix and operations on such kind of matrices.
static vpHomogeneousMatrix compute3d3dTransformation(const std::vector< vpPoint > &p, const std::vector< vpPoint > &q)
Definition of the vpImage class member functions.
Implementation of a matrix and operations on matrices.
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
This class defines the container for a plane geometrical structure.
double computeZ(double x, double y) const
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 set_Z(double cZ)
Set the point cZ coordinate in the camera frame.
void set_y(double y)
Set the point y coordinate in the image plane.
vpPose(const vpPose &)=default
std::vector< vpPoint > getPoints() const
void setRansacMaxTrials(const int &rM)
double m_lambda
Parameters use for the virtual visual servoing approach.
void addPoint(const vpPoint &P)
void setRansacNbInliersToReachConsensus(const unsigned int &nbC)
vpMatrix getCovarianceMatrix() const
std::vector< unsigned int > getRansacInlierIndex() const
double computeResidualDementhon(const vpHomogeneousMatrix &cMo)
bool getUseParallelRansac() const
vpPoseMethodType
Methods that could be used to estimate the pose from points.
@ DEMENTHON_LAGRANGE_VIRTUAL_VS
void setCovarianceComputation(const bool &flag)
unsigned int npt
Number of point used in pose computation.
bool computePose(vpPoseMethodType method, vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
int getNbParallelRansacThreads() const
std::vector< vpPoint > getRansacInliers() const
void setDistToPlaneForCoplanTest(double d)
void addPoints(const std::vector< vpPoint > &lP)
void poseLagrangePlan(vpHomogeneousMatrix &cMo, bool *p_isPlan=nullptr, double *p_a=nullptr, double *p_b=nullptr, double *p_c=nullptr, double *p_d=nullptr)
void poseDementhonNonPlan(vpHomogeneousMatrix &cMo)
double m_dementhonSvThresh
SVD threshold use for the pseudo-inverse computation in poseDementhonPlan.
std::list< vpPoint > listP
Array of point (use here class vpPoint).
double computeResidual(const vpHomogeneousMatrix &cMo) const
Compute and return the sum of squared residuals expressed in meter^2 for the pose matrix cMo.
void poseLagrangeNonPlan(vpHomogeneousMatrix &cMo)
bool(* FuncCheckValidityPose)(const vpHomogeneousMatrix &)
static std::optional< vpHomogeneousMatrix > computePlanarObjectPoseWithAtLeast3Points(const vpPlane &plane_in_camera_frame, const std::map< DataId, vpPoint > &pts, const std::map< DataId, vpImagePoint > &ips, const vpCameraParameters &camera_intrinsics, std::optional< vpHomogeneousMatrix > cMo_init=std::nullopt, bool enable_vvs=true)
void setRansacFilterFlag(const RANSAC_FILTER_FLAGS &flag)
bool coplanar(int &coplanar_plane_type, double *p_a=nullptr, double *p_b=nullptr, double *p_c=nullptr, double *p_d=nullptr)
int calculArbreDementhon(vpMatrix &b, vpColVector &U, vpHomogeneousMatrix &cMo)
void setVvsIterMax(int nb)
void poseLowe(vpHomogeneousMatrix &cMo)
Compute the pose using the Lowe non linear approach it consider the minimization of a residual using ...
@ CHECK_DEGENERATE_POINTS
@ PREFILTER_DEGENERATE_POINTS
@ NO_FILTER
No filter is applied.
unsigned int getRansacNbInliers() const
void setUseParallelRansac(bool use)
static std::optional< vpHomogeneousMatrix > poseVirtualVSWithDepth(const std::vector< vpPoint > &points, const vpHomogeneousMatrix &cMo)
bool computePoseDementhonLagrangeVVS(vpHomogeneousMatrix &cMo)
Method that first computes the pose cMo using the linear approaches of Dementhon and Lagrange and the...
void displayModel(vpImage< unsigned char > &I, vpCameraParameters &cam, vpColor col=vpColor::none)
void setLambda(double lambda)
void setVvsEpsilon(const double eps)
void setNbParallelRansacThreads(int nb)
double residual
Residual in meter.
vpPose & operator=(const vpPose &)=default
bool poseRansac(vpHomogeneousMatrix &cMo, FuncCheckValidityPose func=nullptr)
void poseVirtualVS(vpHomogeneousMatrix &cMo)
void poseDementhonPlan(vpHomogeneousMatrix &cMo)
void setDementhonSvThreshold(const double &svThresh)
void poseVirtualVSrobust(vpHomogeneousMatrix &cMo)
void setRansacThreshold(const double &t)