39 #ifndef _vpMbGenericTracker_h_
40 #define _vpMbGenericTracker_h_
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/mbt/vpMbDepthDenseTracker.h>
44 #include <visp3/mbt/vpMbDepthNormalTracker.h>
45 #include <visp3/mbt/vpMbEdgeTracker.h>
46 #include <visp3/mbt/vpMbKltTracker.h>
48 #ifdef VISP_HAVE_NLOHMANN_JSON
49 #include <nlohmann/json_fwd.hpp>
50 #include <visp3/core/vpJsonParsing.h>
204 EDGE_TRACKER = 1 << 0,
205 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO))
206 KLT_TRACKER = 1 << 1,
208 DEPTH_NORMAL_TRACKER = 1 << 2,
209 DEPTH_DENSE_TRACKER = 1 << 3
215 vpMbGenericTracker(
const std::vector<std::string> &cameraNames,
const std::vector<int> &trackerTypes);
225 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) vp_override;
227 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) vp_override;
229 virtual
void display(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
232 bool displayFullModel = false);
235 const
vpColor &color,
unsigned int thickness = 1,
bool displayFullModel = false);
237 virtual
void display(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
240 unsigned int thickness = 1,
bool displayFullModel = false);
241 virtual
void display(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfImages,
244 unsigned int thickness = 1,
bool displayFullModel = false);
246 virtual std::vector<std::
string> getCameraNames() const;
251 virtual
void getCameraParameters(std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters) const;
253 virtual std::map<std::
string,
int> getCameraTrackerTypes() const;
256 virtual
void getClipping(
unsigned int &clippingFlag1,
unsigned int &clippingFlag2) const;
257 virtual
void getClipping(std::map<std::
string,
unsigned int> &mapOfClippingFlags) const;
259 virtual inline
vpColVector getError() const vp_override {
return m_error; }
264 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
265 virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
266 virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
267 virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
270 virtual std::vector<std::vector<double> > getFeaturesForDisplay();
271 virtual void getFeaturesForDisplay(std::map<std::string, std::vector<std::vector<double> > > &mapOfFeatures);
273 virtual double getGoodMovingEdgesRatioThreshold()
const;
275 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
276 virtual std::vector<vpImagePoint> getKltImagePoints()
const;
277 virtual std::map<int, vpImagePoint> getKltImagePointsWithId()
const;
279 virtual unsigned int getKltMaskBorder()
const;
280 virtual int getKltNbPoints()
const;
284 virtual void getKltOpencv(std::map<std::string, vpKltOpencv> &mapOfKlts)
const;
286 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
287 virtual std::vector<cv::Point2f> getKltPoints()
const;
290 virtual double getKltThresholdAcceptation()
const;
293 virtual void getLcircle(std::list<vpMbtDistanceCircle *> &circlesList,
unsigned int level = 0)
const;
294 virtual void getLcircle(
const std::string &cameraName, std::list<vpMbtDistanceCircle *> &circlesList,
295 unsigned int level = 0)
const;
296 virtual void getLcylinder(std::list<vpMbtDistanceCylinder *> &cylindersList,
unsigned int level = 0)
const;
297 virtual void getLcylinder(
const std::string &cameraName, std::list<vpMbtDistanceCylinder *> &cylindersList,
298 unsigned int level = 0)
const;
299 virtual void getLline(std::list<vpMbtDistanceLine *> &linesList,
unsigned int level = 0)
const;
300 virtual void getLline(
const std::string &cameraName, std::list<vpMbtDistanceLine *> &linesList,
301 unsigned int level = 0)
const;
303 virtual std::vector<std::vector<double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
306 bool displayFullModel =
false) vp_override;
307 virtual
void getModelForDisplay(std::map<std::
string, std::vector<std::vector<
double> > > &mapOfModels,
308 const std::map<std::
string,
unsigned int> &mapOfwidths,
309 const std::map<std::
string,
unsigned int> &mapOfheights,
312 bool displayFullModel = false);
314 virtual
vpMe getMovingEdge() const;
315 virtual
void getMovingEdge(
vpMe &me1,
vpMe &me2) const;
316 virtual
void getMovingEdge(std::map<std::
string,
vpMe> &mapOfMovingEdges) const;
321 virtual inline
unsigned int getNbFeaturesDepthDense()
const {
return m_nb_feat_depthDense; }
340 virtual unsigned int getNbPoints(
unsigned int level = 0)
const;
341 virtual void getNbPoints(std::map<std::string, unsigned int> &mapOfNbPoints,
unsigned int level = 0)
const;
344 virtual
void getNbPolygon(std::map<std::
string,
unsigned int> &mapOfNbPolygons) const;
346 virtual
vpMbtPolygon *getPolygon(
unsigned int index) vp_override;
347 virtual
vpMbtPolygon *getPolygon(const std::
string &cameraName,
unsigned int index);
349 virtual std::pair<std::vector<
vpPolygon>, std::vector<std::vector<
vpPoint> > >
350 getPolygonFaces(
bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false) vp_override;
351 virtual
void getPolygonFaces(std::map<std::
string, std::vector<
vpPolygon> > &mapOfPolygons,
352 std::map<std::
string, std::vector<std::vector<
vpPoint> > > &mapOfPoints,
353 bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false);
360 virtual std::
string getReferenceCameraName() const;
362 virtual inline
vpColVector getRobustWeights() const vp_override {
return m_w; }
364 virtual int getTrackerType()
const;
368 #ifdef VISP_HAVE_MODULE_GUI
371 const std::string &initFile1,
const std::string &initFile2,
bool displayHelp =
false,
375 const std::string &initFile2,
bool displayHelp =
false,
381 const std::map<std::string, std::string> &mapOfInitFiles,
bool displayHelp =
false,
382 const std::map<std::string, vpHomogeneousMatrix> &mapOfT = std::map<std::string, vpHomogeneousMatrix>());
385 const std::map<std::string, std::string> &mapOfInitFiles,
bool displayHelp =
false,
386 const std::map<std::string, vpHomogeneousMatrix> &mapOfT = std::map<std::string, vpHomogeneousMatrix>());
391 const std::string &initFile1,
const std::string &initFile2);
393 const std::string &initFile1,
const std::string &initFile2);
396 const std::map<std::string, std::string> &mapOfInitPoints);
398 const std::map<std::string, std::string> &mapOfInitPoints);
403 const std::string &initFile1,
const std::string &initFile2);
405 const std::string &initFile1,
const std::string &initFile2);
408 const std::map<std::string, std::string> &mapOfInitPoses);
410 const std::map<std::string, std::string> &mapOfInitPoses);
418 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
420 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
422 virtual void loadConfigFile(
const std::string &configFile,
bool verbose =
true) vp_override;
423 virtual
void loadConfigFile(const std::
string &configFile1, const std::
string &configFile2,
bool verbose = true);
424 virtual
void loadConfigFile(const std::map<std::
string, std::
string> &mapOfConfigFiles,
bool verbose = true);
426 #ifdef VISP_HAVE_NLOHMANN_JSON
427 virtual void saveConfigFile(
const std::string &settingsFile)
const;
430 virtual void loadModel(
const std::string &modelFile,
bool verbose =
false,
432 virtual
void loadModel(const std::
string &modelFile1, const std::
string &modelFile2,
bool verbose = false,
437 loadModel(const std::map<std::
string, std::
string> &mapOfModelFiles,
bool verbose = false,
445 virtual
void reInitModel(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
446 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
451 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
457 reInitModel(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
458 const std::map<std::
string, std::
string> &mapOfModelFiles,
462 reInitModel(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
463 const std::map<std::
string, std::
string> &mapOfModelFiles,
467 virtual
void resetTracker() vp_override;
469 virtual
void setAngleAppear(const
double &a) vp_override;
470 virtual
void setAngleAppear(const
double &a1, const
double &a2);
471 virtual
void setAngleAppear(const std::map<std::
string,
double> &mapOfAngles);
473 virtual
void setAngleDisappear(const
double &a) vp_override;
474 virtual
void setAngleDisappear(const
double &a1, const
double &a2);
475 virtual
void setAngleDisappear(const std::map<std::
string,
double> &mapOfAngles);
479 virtual
void setCameraParameters(const std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters);
481 virtual
void setCameraTransformationMatrix(const std::
string &cameraName,
484 setCameraTransformationMatrix(const std::map<std::
string,
vpHomogeneousMatrix> &mapOfTransformationMatrix);
486 virtual
void setClipping(const
unsigned int &flags) vp_override;
487 virtual
void setClipping(const
unsigned int &flags1, const
unsigned int &flags2);
488 virtual
void setClipping(const std::map<std::
string,
unsigned int> &mapOfClippingFlags);
490 virtual
void setDepthDenseFilteringMaxDistance(
double maxDistance);
491 virtual
void setDepthDenseFilteringMethod(
int method);
492 virtual
void setDepthDenseFilteringMinDistance(
double minDistance);
493 virtual
void setDepthDenseFilteringOccupancyRatio(
double occupancyRatio);
494 virtual
void setDepthDenseSamplingStep(
unsigned int stepX,
unsigned int stepY);
496 virtual
void setDepthNormalFaceCentroidMethod(const
vpMbtFaceDepthNormal::vpFaceCentroidType &method);
497 virtual
void setDepthNormalFeatureEstimationMethod(const
vpMbtFaceDepthNormal::vpFeatureEstimationType &method);
498 virtual
void setDepthNormalPclPlaneEstimationMethod(
int method);
499 virtual
void setDepthNormalPclPlaneEstimationRansacMaxIter(
int maxIter);
500 virtual
void setDepthNormalPclPlaneEstimationRansacThreshold(
double threshold);
501 virtual
void setDepthNormalSamplingStep(
unsigned int stepX,
unsigned int stepY);
503 virtual
void setDisplayFeatures(
bool displayF) vp_override;
505 virtual
void setFarClippingDistance(const
double &dist) vp_override;
506 virtual
void setFarClippingDistance(const
double &dist1, const
double &dist2);
507 virtual
void setFarClippingDistance(const std::map<std::
string,
double> &mapOfClippingDists);
509 virtual
void setFeatureFactors(const std::map<vpTrackerType,
double> &mapOfFeatureFactors);
511 virtual
void setGoodMovingEdgesRatioThreshold(
double threshold);
513 #ifdef VISP_HAVE_OGRE
518 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
519 virtual void setKltMaskBorder(
const unsigned int &e);
520 virtual void setKltMaskBorder(
const unsigned int &e1,
const unsigned int &e2);
521 virtual void setKltMaskBorder(
const std::map<std::string, unsigned int> &mapOfErosions);
525 virtual void setKltOpencv(
const std::map<std::string, vpKltOpencv> &mapOfKlts);
527 virtual void setKltThresholdAcceptation(
double th);
530 virtual void setLod(
bool useLod,
const std::string &name =
"") vp_override;
532 virtual
void setMask(const
vpImage<
bool> &mask) vp_override;
534 virtual
void setMinLineLengthThresh(
double minLineLengthThresh, const std::
string &name = "") vp_override;
535 virtual
void setMinPolygonAreaThresh(
double minPolygonAreaThresh, const std::
string &name = "") vp_override;
537 virtual
void setMovingEdge(const
vpMe &me);
538 virtual
void setMovingEdge(const
vpMe &me1, const
vpMe &me2);
539 virtual
void setMovingEdge(const std::map<std::
string,
vpMe> &mapOfMe);
541 virtual
void setNearClippingDistance(const
double &dist) vp_override;
542 virtual
void setNearClippingDistance(const
double &dist1, const
double &dist2);
543 virtual
void setNearClippingDistance(const std::map<std::
string,
double> &mapOfDists);
545 virtual
void setOgreShowConfigDialog(
bool showConfigDialog) vp_override;
546 virtual
void setOgreVisibilityTest(const
bool &v) vp_override;
548 virtual
void setOptimizationMethod(const vpMbtOptimizationMethod &opt) vp_override;
553 virtual
void setPose(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
558 virtual
void setPose(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
560 virtual
void setPose(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
563 virtual
void setProjectionErrorComputation(const
bool &flag) vp_override;
565 virtual
void setProjectionErrorDisplay(
bool display) vp_override;
566 virtual
void setProjectionErrorDisplayArrowLength(
unsigned int length) vp_override;
567 virtual
void setProjectionErrorDisplayArrowThickness(
unsigned int thickness) vp_override;
569 virtual
void setReferenceCameraName(const std::
string &referenceCameraName);
571 virtual
void setScanLineVisibilityTest(const
bool &v) vp_override;
573 virtual
void setTrackerType(
int type);
574 virtual
void setTrackerType(const std::map<std::
string,
int> &mapOfTrackerTypes);
576 virtual
void setUseDepthDenseTracking(const std::
string &name, const
bool &useDepthDenseTracking);
577 virtual
void setUseDepthNormalTracking(const std::
string &name, const
bool &useDepthNormalTracking);
578 virtual
void setUseEdgeTracking(const std::
string &name, const
bool &useEdgeTracking);
579 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
580 virtual void setUseKltTracking(
const std::string &name,
const bool &useKltTracking);
585 virtual
void track(const
vpImage<
unsigned char> &I) vp_override;
586 virtual
void track(const
vpImage<
vpRGBa> &I_color) vp_override;
588 virtual
void track(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2);
591 virtual
void track(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
592 virtual
void track(std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages);
594 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
596 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
598 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
602 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
603 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
604 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
606 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
607 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
608 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
611 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
612 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
613 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
615 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
616 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
617 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
620 virtual void computeProjectionError();
625 virtual
void computeVVSInit(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
626 virtual
void computeVVSInteractionMatrixAndResidu() vp_override;
627 virtual
void computeVVSInteractionMatrixAndResidu(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
630 virtual
void computeVVSWeights();
632 virtual
void initCircle(const
vpPoint &p1, const
vpPoint &p2, const
vpPoint &p3,
double radius,
int idFace = 0,
633 const std::
string &name = "") vp_override;
635 virtual
void initCylinder(const
vpPoint &p1, const
vpPoint &p2,
double radius,
int idFace = 0,
636 const std::
string &name = "") vp_override;
638 virtual
void initFaceFromCorners(
vpMbtPolygon &polygon) vp_override;
640 virtual
void initFaceFromLines(
vpMbtPolygon &polygon) vp_override;
642 virtual
void loadConfigFileXML(const std::
string &configFile,
bool verbose = true);
643 #ifdef VISP_HAVE_NLOHMANN_JSON
644 virtual void loadConfigFileJSON(
const std::string &configFile,
bool verbose =
true);
647 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
649 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
652 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
653 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
654 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
656 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
657 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
658 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
662 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
669 #ifdef VISP_HAVE_NLOHMANN_JSON
670 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
671 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
687 explicit TrackerWrapper(
int trackerType);
693 virtual inline int getTrackerType()
const {
return m_trackerType; }
696 const vpColor &col,
unsigned int thickness = 1,
bool displayFullModel =
false) vp_override;
698 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) vp_override;
702 virtual std::vector<std::vector<
double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
705 bool displayFullModel = false) vp_override;
707 virtual
void init(const
vpImage<
unsigned char> &I) vp_override;
709 virtual
void loadConfigFile(const std::
string &configFile,
bool verbose = true) vp_override;
711 virtual
void reInitModel(const
vpImage<
unsigned char> &I, const std::
string &cad_name,
722 virtual
void setClipping(const
unsigned int &flags) vp_override;
741 virtual
void track(const
vpImage<
unsigned char> &I) vp_override;
743 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
746 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
752 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
766 const std::
string &name = "") vp_override;
769 const std::
string &name = "") vp_override;
774 virtual
void initMbtTracking(const
vpImage<
unsigned char> *const ptr_I);
776 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
778 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
780 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
782 virtual void postTracking(
const vpImage<unsigned char> *
const ptr_I =
nullptr,
const unsigned int pointcloud_width = 0,
783 const unsigned int pointcloud_height = 0);
785 const std::vector<vpColVector> *
const point_cloud =
nullptr,
786 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
788 const vpMatrix *
const point_cloud =
nullptr,
789 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
795 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
798 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
803 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
811 #ifdef VISP_HAVE_NLOHMANN_JSON
812 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
813 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
852 #ifdef VISP_HAVE_NLOHMANN_JSON
854 #define MBT_JSON_SETTINGS_VERSION "1.0"
857 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
878 inline void to_json(nlohmann::json &j,
const vpMbGenericTracker::TrackerWrapper &t)
881 const static std::vector<vpMbGenericTracker::vpTrackerType> trackerTypes = {
883 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
891 {
"type", flagsToJSON(t.m_trackerType, trackerTypes)},
893 {
"angleDisappear",
vpMath::deg(t.getAngleDisappear())},
895 {
"useLod", t.useLodGeneral},
896 {
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral},
897 {
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral}
900 {
"features", t.displayFeatures},
901 {
"projectionError", t.m_projectionErrorDisplay}
905 {
"scanline", t.useScanLine}
908 {
"flags", clippingFlagsToJSON(t.getClipping())},
909 {
"near", t.getNearClippingDistance()},
910 {
"far", t.getFarClippingDistance()},
919 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
921 nlohmann::json klt = nlohmann::json {
922 {
"maxFeatures", t.tracker.getMaxFeatures()},
923 {
"windowSize", t.tracker.getWindowSize()},
924 {
"quality", t.tracker.getQuality()},
925 {
"minDistance", t.tracker.getMinDistance()},
926 {
"harris", t.tracker.getHarrisFreeParameter()},
927 {
"blockSize", t.tracker.getBlockSize()},
928 {
"pyramidLevels", t.tracker.getPyramidLevels()}
930 klt[
"maskBorder"] = t.maskBorder;
936 j[
"normals"] = nlohmann::json {
937 {
"featureEstimationMethod", t.m_depthNormalFeatureEstimationMethod},
939 {
"method", t.m_depthNormalPclPlaneEstimationMethod},
940 {
"ransacMaxIter", t.m_depthNormalPclPlaneEstimationRansacMaxIter},
941 {
"ransacThreshold", t.m_depthNormalPclPlaneEstimationRansacThreshold}
944 {
"x", t.m_depthNormalSamplingStepX},
945 {
"y", t.m_depthNormalSamplingStepY}
953 {
"x", t.m_depthDenseSamplingStepX},
954 {
"y", t.m_depthDenseSamplingStepY}
979 inline void from_json(
const nlohmann::json &j, vpMbGenericTracker::TrackerWrapper &t)
981 t.setCameraParameters(j.at(
"camera"));
982 t.setTrackerType(flagsFromJSON<vpMbGenericTracker::vpTrackerType>(j.at(
"type")));
984 if (j.contains(
"angleAppear")) {
985 t.setAngleAppear(
vpMath::rad(
static_cast<double>(j.at(
"angleAppear"))));
987 if (j.contains(
"angleDisappear")) {
988 t.setAngleDisappear(
vpMath::rad(
static_cast<double>(j.at(
"angleDisappear"))));
990 if (j.contains(
"clipping")) {
991 const nlohmann::json clipping = j[
"clipping"];
992 t.setNearClippingDistance(clipping.value(
"near", t.getNearClippingDistance()));
993 t.setFarClippingDistance(clipping.value(
"far", t.getFarClippingDistance()));
994 if (clipping.contains(
"flags")) {
995 t.setClipping(flagsFromJSON<vpPolygon3D::vpPolygon3DClippingType>(clipping.at(
"flags")));
998 if (j.contains(
"lod")) {
999 const nlohmann::json lod = j[
"lod"];
1000 t.useLodGeneral = lod.value(
"useLod", t.useLodGeneral);
1001 t.minLineLengthThresholdGeneral = lod.value(
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral);
1002 t.minPolygonAreaThresholdGeneral = lod.value(
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral);
1003 t.applyLodSettingInConfig =
false;
1004 if (t.getNbPolygon() > 0) {
1005 t.applyLodSettingInConfig =
true;
1006 t.setLod(t.useLodGeneral);
1007 t.setMinLineLengthThresh(t.minLineLengthThresholdGeneral);
1008 t.setMinPolygonAreaThresh(t.minPolygonAreaThresholdGeneral);
1011 if (j.contains(
"display")) {
1012 const nlohmann::json displayJson = j[
"display"];
1013 t.setDisplayFeatures(displayJson.value(
"features", t.displayFeatures));
1014 t.setProjectionErrorDisplay(displayJson.value(
"projectionError", t.m_projectionErrorDisplay));
1016 if (j.contains(
"visibilityTest")) {
1017 const nlohmann::json visJson = j[
"visibilityTest"];
1018 t.setOgreVisibilityTest(visJson.value(
"ogre", t.useOgre));
1019 t.setScanLineVisibilityTest(visJson.value(
"scanline", t.useScanLine));
1026 t.setMovingEdge(t.me);
1029 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
1031 const nlohmann::json klt = j.at(
"klt");
1032 auto &ktrack = t.tracker;
1033 ktrack.setMaxFeatures(klt.value(
"maxFeatures", 10000));
1034 ktrack.setWindowSize(klt.value(
"windowSize", 5));
1035 ktrack.setQuality(klt.value(
"quality", 0.01));
1036 ktrack.setMinDistance(klt.value(
"minDistance", 5));
1037 ktrack.setHarrisFreeParameter(klt.value(
"harris", 0.01));
1038 ktrack.setBlockSize(klt.value(
"blockSize", 3));
1039 ktrack.setPyramidLevels(klt.value(
"pyramidLevels", 3));
1040 t.setMaskBorder(klt.value(
"maskBorder", t.maskBorder));
1041 t.faces.getMbScanLineRenderer().setMaskBorder(t.maskBorder);
1044 if (j.contains(
"klt")) {
1045 std::cerr <<
"Trying to load a KLT tracker, but the ViSP dependency requirements are not met. Ignoring." << std::endl;
1050 const nlohmann::json n = j.at(
"normals");
1051 t.setDepthNormalFeatureEstimationMethod(n.at(
"featureEstimationMethod"));
1052 if (n.contains(
"pcl")) {
1053 const nlohmann::json pcl = n[
"pcl"];
1054 t.setDepthNormalPclPlaneEstimationMethod(pcl.at(
"method"));
1055 t.setDepthNormalPclPlaneEstimationRansacMaxIter(pcl.at(
"ransacMaxIter"));
1056 t.setDepthNormalPclPlaneEstimationRansacThreshold(pcl.at(
"ransacThreshold"));
1058 if (n.contains(
"sampling")) {
1059 const nlohmann::json sampling = n.at(
"sampling");
1060 t.setDepthNormalSamplingStep(sampling.at(
"x"), sampling.at(
"y"));
1065 const nlohmann::json dense = j.at(
"dense");
1066 if (dense.contains(
"sampling")) {
1067 const nlohmann::json sampling = dense.at(
"sampling");
1068 t.setDepthDenseSamplingStep(sampling.at(
"x"), sampling.at(
"y"));
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
static double rad(double deg)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
virtual void track(const vpImage< unsigned char > &) vp_override
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
virtual void track(const vpImage< unsigned char > &) vp_override
Make the complete tracking of an object by using its CAD model.
virtual void track(const vpImage< unsigned char > &I) vp_override
Real-time 6D object pose tracking using its CAD model.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
virtual std::vector< std::vector< double > > getFeaturesForDisplay()
virtual int getTrackerType() const
std::map< std::string, TrackerWrapper * > m_mapOfTrackers
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) vp_override
unsigned int m_nb_feat_edge
Number of moving-edges features.
virtual unsigned int getNbFeaturesEdge() const
std::map< std::string, vpHomogeneousMatrix > m_mapOfCameraTransformationMatrix
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) vp_override
friend void to_json(nlohmann::json &j, const TrackerWrapper &t)
Serialize a tracker wrapper's settings into a JSON representation.
vpColVector m_w
Robust weights.
virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override
virtual unsigned int getNbFeaturesKlt() const
unsigned int m_nb_feat_depthDense
Number of depth dense features.
virtual void setOgreVisibilityTest(const bool &v) vp_override
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void preTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, const std::vector< vpColVector > * > &mapOfPointClouds, std::map< std::string, unsigned int > &mapOfPointCloudWidths, std::map< std::string, unsigned int > &mapOfPointCloudHeights)
virtual void computeVVSInteractionMatrixAndResidu() vp_override
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false) vp_override
virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override
virtual void computeVVSInit() vp_override
vpColVector m_weightedError
Weighted error.
virtual void init(const vpImage< unsigned char > &I) vp_override
vpMatrix m_L
Interaction matrix.
virtual void setFarClippingDistance(const double &dist) vp_override
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="") vp_override
virtual void computeVVSWeights()
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="") vp_override
virtual void testTracking() vp_override
virtual void setNearClippingDistance(const double &dist) vp_override
virtual void setScanLineVisibilityTest(const bool &v) vp_override
virtual unsigned int getNbFeaturesDepthNormal() const
vpColVector m_error
(s - s*)
std::map< vpTrackerType, double > m_mapOfFeatureFactors
Ponderation between each feature type in the VVS stage.
double m_thresholdOutlier
virtual void computeVVS(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages)
virtual void resetTracker() vp_override
virtual void setCameraParameters(const vpCameraParameters &camera) vp_override
virtual void setTrackerType(int type)
unsigned int m_nb_feat_klt
Number of klt features.
unsigned int m_nb_feat_depthNormal
Number of depth normal features.
virtual void setClipping(const unsigned int &flags) vp_override
virtual void setProjectionErrorComputation(const bool &flag) vp_override
virtual vpColVector getError() const vp_override
virtual void track(const vpImage< unsigned char > &I) vp_override
std::string m_referenceCameraName
Name of the reference camera.
friend void from_json(const nlohmann::json &j, TrackerWrapper &t)
Load configuration settings from a JSON object for a tracker wrapper.
virtual vpColVector getRobustWeights() const vp_override
Model based tracker using only KLT.
Main methods for a model-based tracker.
virtual void track(const vpImage< unsigned char > &I)=0
virtual void init(const vpImage< unsigned char > &I)=0
virtual void initFromPoints(const vpImage< unsigned char > &I, const std::string &initFile)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)=0
virtual void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
virtual vpMbHiddenFaces< vpMbtPolygon > & getFaces()
virtual void initClick(const vpImage< unsigned char > &I, const std::string &initFile, bool displayHelp=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setLod(bool useLod, const std::string &name="")
virtual unsigned int getNbPolygon() const
virtual void initFromPose(const vpImage< unsigned char > &I, const std::string &initFile)
virtual void loadModel(const std::string &modelFile, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setGoodNbRayCastingAttemptsRatio(const double &ratio)
virtual void computeVVSInit()=0
virtual void testTracking()=0
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
Implementation of a polygon of the model used by the model-based tracker.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Defines a generic 2D polygon.