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>
209 EDGE_TRACKER = 1 << 0,
210 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO))
211 KLT_TRACKER = 1 << 1,
213 DEPTH_NORMAL_TRACKER = 1 << 2,
214 DEPTH_DENSE_TRACKER = 1 << 3
220 vpMbGenericTracker(
const std::vector<std::string> &cameraNames,
const std::vector<int> &trackerTypes);
230 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
232 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
234 virtual
void display(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
237 bool displayFullModel = false);
240 const
vpColor &color,
unsigned int thickness = 1,
bool displayFullModel = false);
242 virtual
void display(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
245 unsigned int thickness = 1,
bool displayFullModel = false);
246 virtual
void display(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfImages,
249 unsigned int thickness = 1,
bool displayFullModel = false);
251 virtual std::vector<std::
string> getCameraNames() const;
256 virtual
void getCameraParameters(std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters) const;
258 virtual std::map<std::
string,
int> getCameraTrackerTypes() const;
261 virtual
void getClipping(
unsigned int &clippingFlag1,
unsigned int &clippingFlag2) const;
262 virtual
void getClipping(std::map<std::
string,
unsigned int> &mapOfClippingFlags) const;
264 virtual inline
vpColVector getError() const VP_OVERRIDE {
return m_error; }
269 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
270 virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
271 virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
272 virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
275 virtual std::vector<std::vector<double> > getFeaturesForDisplay();
276 virtual void getFeaturesForDisplay(std::map<std::string, std::vector<std::vector<double> > > &mapOfFeatures);
278 virtual double getGoodMovingEdgesRatioThreshold()
const;
280 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
281 virtual std::vector<vpImagePoint> getKltImagePoints()
const;
282 virtual std::map<int, vpImagePoint> getKltImagePointsWithId()
const;
284 virtual unsigned int getKltMaskBorder()
const;
285 virtual int getKltNbPoints()
const;
289 virtual void getKltOpencv(std::map<std::string, vpKltOpencv> &mapOfKlts)
const;
291 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
292 virtual std::vector<cv::Point2f> getKltPoints()
const;
295 virtual double getKltThresholdAcceptation()
const;
298 virtual void getLcircle(std::list<vpMbtDistanceCircle *> &circlesList,
unsigned int level = 0)
const;
299 virtual void getLcircle(
const std::string &cameraName, std::list<vpMbtDistanceCircle *> &circlesList,
300 unsigned int level = 0)
const;
301 virtual void getLcylinder(std::list<vpMbtDistanceCylinder *> &cylindersList,
unsigned int level = 0)
const;
302 virtual void getLcylinder(
const std::string &cameraName, std::list<vpMbtDistanceCylinder *> &cylindersList,
303 unsigned int level = 0)
const;
304 virtual void getLline(std::list<vpMbtDistanceLine *> &linesList,
unsigned int level = 0)
const;
305 virtual void getLline(
const std::string &cameraName, std::list<vpMbtDistanceLine *> &linesList,
306 unsigned int level = 0)
const;
308 virtual std::vector<std::vector<double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
311 bool displayFullModel =
false) VP_OVERRIDE;
312 virtual
void getModelForDisplay(std::map<std::
string, std::vector<std::vector<
double> > > &mapOfModels,
313 const std::map<std::
string,
unsigned int> &mapOfwidths,
314 const std::map<std::
string,
unsigned int> &mapOfheights,
317 bool displayFullModel = false);
319 virtual
vpMe getMovingEdge() const;
320 virtual
void getMovingEdge(
vpMe &me1,
vpMe &me2) const;
321 virtual
void getMovingEdge(std::map<std::
string,
vpMe> &mapOfMovingEdges) const;
326 virtual inline
unsigned int getNbFeaturesDepthDense()
const {
return m_nb_feat_depthDense; }
345 virtual unsigned int getNbPoints(
unsigned int level = 0)
const;
346 virtual void getNbPoints(std::map<std::string, unsigned int> &mapOfNbPoints,
unsigned int level = 0)
const;
349 virtual
void getNbPolygon(std::map<std::
string,
unsigned int> &mapOfNbPolygons) const;
351 virtual
vpMbtPolygon *getPolygon(
unsigned int index) VP_OVERRIDE;
352 virtual
vpMbtPolygon *getPolygon(const std::
string &cameraName,
unsigned int index);
354 virtual std::pair<std::vector<
vpPolygon>, std::vector<std::vector<
vpPoint> > >
355 getPolygonFaces(
bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false) VP_OVERRIDE;
356 virtual
void getPolygonFaces(std::map<std::
string, std::vector<
vpPolygon> > &mapOfPolygons,
357 std::map<std::
string, std::vector<std::vector<
vpPoint> > > &mapOfPoints,
358 bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false);
365 virtual std::
string getReferenceCameraName() const;
367 virtual inline
vpColVector getRobustWeights() const VP_OVERRIDE {
return m_w; }
369 virtual int getTrackerType()
const;
373 #ifdef VISP_HAVE_MODULE_GUI
376 const std::string &initFile1,
const std::string &initFile2,
bool displayHelp =
false,
380 const std::string &initFile2,
bool displayHelp =
false,
386 const std::map<std::string, std::string> &mapOfInitFiles,
bool displayHelp =
false,
387 const std::map<std::string, vpHomogeneousMatrix> &mapOfT = std::map<std::string, vpHomogeneousMatrix>());
390 const std::map<std::string, std::string> &mapOfInitFiles,
bool displayHelp =
false,
391 const std::map<std::string, vpHomogeneousMatrix> &mapOfT = std::map<std::string, vpHomogeneousMatrix>());
396 const std::string &initFile1,
const std::string &initFile2);
398 const std::string &initFile1,
const std::string &initFile2);
401 const std::map<std::string, std::string> &mapOfInitPoints);
403 const std::map<std::string, std::string> &mapOfInitPoints);
408 const std::string &initFile1,
const std::string &initFile2);
410 const std::string &initFile1,
const std::string &initFile2);
413 const std::map<std::string, std::string> &mapOfInitPoses);
415 const std::map<std::string, std::string> &mapOfInitPoses);
423 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
425 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
427 virtual void loadConfigFile(
const std::string &configFile,
bool verbose =
true) VP_OVERRIDE;
428 virtual
void loadConfigFile(const std::
string &configFile1, const std::
string &configFile2,
bool verbose = true);
429 virtual
void loadConfigFile(const std::map<std::
string, std::
string> &mapOfConfigFiles,
bool verbose = true);
431 #ifdef VISP_HAVE_NLOHMANN_JSON
432 virtual void saveConfigFile(
const std::string &settingsFile)
const;
435 virtual void loadModel(
const std::string &modelFile,
bool verbose =
false,
437 virtual
void loadModel(const std::
string &modelFile1, const std::
string &modelFile2,
bool verbose = false,
442 loadModel(const std::map<std::
string, std::
string> &mapOfModelFiles,
bool verbose = false,
450 virtual
void reInitModel(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
451 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
456 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
462 reInitModel(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
463 const std::map<std::
string, std::
string> &mapOfModelFiles,
467 reInitModel(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
468 const std::map<std::
string, std::
string> &mapOfModelFiles,
472 virtual
void resetTracker() VP_OVERRIDE;
474 virtual
void setAngleAppear(const
double &a) VP_OVERRIDE;
475 virtual
void setAngleAppear(const
double &a1, const
double &a2);
476 virtual
void setAngleAppear(const std::map<std::
string,
double> &mapOfAngles);
478 virtual
void setAngleDisappear(const
double &a) VP_OVERRIDE;
479 virtual
void setAngleDisappear(const
double &a1, const
double &a2);
480 virtual
void setAngleDisappear(const std::map<std::
string,
double> &mapOfAngles);
484 virtual
void setCameraParameters(const std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters);
486 virtual
void setCameraTransformationMatrix(const std::
string &cameraName,
489 setCameraTransformationMatrix(const std::map<std::
string,
vpHomogeneousMatrix> &mapOfTransformationMatrix);
491 virtual
void setClipping(const
unsigned int &flags) VP_OVERRIDE;
492 virtual
void setClipping(const
unsigned int &flags1, const
unsigned int &flags2);
493 virtual
void setClipping(const std::map<std::
string,
unsigned int> &mapOfClippingFlags);
495 virtual
void setDepthDenseFilteringMaxDistance(
double maxDistance);
496 virtual
void setDepthDenseFilteringMethod(
int method);
497 virtual
void setDepthDenseFilteringMinDistance(
double minDistance);
498 virtual
void setDepthDenseFilteringOccupancyRatio(
double occupancyRatio);
499 virtual
void setDepthDenseSamplingStep(
unsigned int stepX,
unsigned int stepY);
501 virtual
void setDepthNormalFaceCentroidMethod(const
vpMbtFaceDepthNormal::vpFaceCentroidType &method);
502 virtual
void setDepthNormalFeatureEstimationMethod(const
vpMbtFaceDepthNormal::vpFeatureEstimationType &method);
503 virtual
void setDepthNormalPclPlaneEstimationMethod(
int method);
504 virtual
void setDepthNormalPclPlaneEstimationRansacMaxIter(
int maxIter);
505 virtual
void setDepthNormalPclPlaneEstimationRansacThreshold(
double threshold);
506 virtual
void setDepthNormalSamplingStep(
unsigned int stepX,
unsigned int stepY);
508 virtual
void setDisplayFeatures(
bool displayF) VP_OVERRIDE;
510 virtual
void setFarClippingDistance(const
double &dist) VP_OVERRIDE;
511 virtual
void setFarClippingDistance(const
double &dist1, const
double &dist2);
512 virtual
void setFarClippingDistance(const std::map<std::
string,
double> &mapOfClippingDists);
514 virtual
void setFeatureFactors(const std::map<vpTrackerType,
double> &mapOfFeatureFactors);
516 virtual
void setGoodMovingEdgesRatioThreshold(
double threshold);
518 #ifdef VISP_HAVE_OGRE
523 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
524 virtual void setKltMaskBorder(
const unsigned int &e);
525 virtual void setKltMaskBorder(
const unsigned int &e1,
const unsigned int &e2);
526 virtual void setKltMaskBorder(
const std::map<std::string, unsigned int> &mapOfErosions);
530 virtual void setKltOpencv(
const std::map<std::string, vpKltOpencv> &mapOfKlts);
532 virtual void setKltThresholdAcceptation(
double th);
535 virtual void setLod(
bool useLod,
const std::string &name =
"") VP_OVERRIDE;
537 virtual
void setMask(const
vpImage<
bool> &mask) VP_OVERRIDE;
539 virtual
void setMinLineLengthThresh(
double minLineLengthThresh, const std::
string &name = "") VP_OVERRIDE;
540 virtual
void setMinPolygonAreaThresh(
double minPolygonAreaThresh, const std::
string &name = "") VP_OVERRIDE;
542 virtual
void setMovingEdge(const
vpMe &me);
543 virtual
void setMovingEdge(const
vpMe &me1, const
vpMe &me2);
544 virtual
void setMovingEdge(const std::map<std::
string,
vpMe> &mapOfMe);
546 virtual
void setNearClippingDistance(const
double &dist) VP_OVERRIDE;
547 virtual
void setNearClippingDistance(const
double &dist1, const
double &dist2);
548 virtual
void setNearClippingDistance(const std::map<std::
string,
double> &mapOfDists);
550 virtual
void setOgreShowConfigDialog(
bool showConfigDialog) VP_OVERRIDE;
551 virtual
void setOgreVisibilityTest(const
bool &v) VP_OVERRIDE;
553 virtual
void setOptimizationMethod(const vpMbtOptimizationMethod &opt) VP_OVERRIDE;
558 virtual
void setPose(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
563 virtual
void setPose(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
565 virtual
void setPose(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
568 virtual
void setProjectionErrorComputation(const
bool &flag) VP_OVERRIDE;
570 virtual
void setProjectionErrorDisplay(
bool display) VP_OVERRIDE;
571 virtual
void setProjectionErrorDisplayArrowLength(
unsigned int length) VP_OVERRIDE;
572 virtual
void setProjectionErrorDisplayArrowThickness(
unsigned int thickness) VP_OVERRIDE;
574 virtual
void setReferenceCameraName(const std::
string &referenceCameraName);
576 virtual
void setScanLineVisibilityTest(const
bool &v) VP_OVERRIDE;
578 virtual
void setTrackerType(
int type);
579 virtual
void setTrackerType(const std::map<std::
string,
int> &mapOfTrackerTypes);
581 virtual
void setUseDepthDenseTracking(const std::
string &name, const
bool &useDepthDenseTracking);
582 virtual
void setUseDepthNormalTracking(const std::
string &name, const
bool &useDepthNormalTracking);
583 virtual
void setUseEdgeTracking(const std::
string &name, const
bool &useEdgeTracking);
584 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
585 virtual void setUseKltTracking(
const std::string &name,
const bool &useKltTracking);
590 virtual
void track(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
591 virtual
void track(const
vpImage<
vpRGBa> &I_color) VP_OVERRIDE;
593 virtual
void track(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2);
596 virtual
void track(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
597 virtual
void track(std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages);
599 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
601 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
603 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
607 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
608 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
609 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
611 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
612 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
613 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
616 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
617 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
618 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
620 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
621 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
622 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
625 virtual void computeProjectionError();
630 virtual
void computeVVSInit(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
631 virtual
void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE;
632 virtual
void computeVVSInteractionMatrixAndResidu(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
635 virtual
void computeVVSWeights();
637 virtual
void initCircle(const
vpPoint &p1, const
vpPoint &p2, const
vpPoint &p3,
double radius,
int idFace = 0,
638 const std::
string &name = "") VP_OVERRIDE;
640 virtual
void initCylinder(const
vpPoint &p1, const
vpPoint &p2,
double radius,
int idFace = 0,
641 const std::
string &name = "") VP_OVERRIDE;
643 virtual
void initFaceFromCorners(
vpMbtPolygon &polygon) VP_OVERRIDE;
645 virtual
void initFaceFromLines(
vpMbtPolygon &polygon) VP_OVERRIDE;
647 virtual
void loadConfigFileXML(const std::
string &configFile,
bool verbose = true);
648 #ifdef VISP_HAVE_NLOHMANN_JSON
649 virtual void loadConfigFileJSON(
const std::string &configFile,
bool verbose =
true);
652 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
654 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
657 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
658 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
659 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
661 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
662 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
663 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
667 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
674 #ifdef VISP_HAVE_NLOHMANN_JSON
675 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
676 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
692 explicit TrackerWrapper(
int trackerType);
698 virtual inline int getTrackerType()
const {
return m_trackerType; }
701 const vpColor &col,
unsigned int thickness = 1,
bool displayFullModel =
false) VP_OVERRIDE;
703 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
707 virtual std::vector<std::vector<
double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
710 bool displayFullModel = false) VP_OVERRIDE;
712 virtual
void init(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
714 virtual
void loadConfigFile(const std::
string &configFile,
bool verbose = true) VP_OVERRIDE;
716 virtual
void reInitModel(const
vpImage<
unsigned char> &I, const std::
string &cad_name,
727 virtual
void setClipping(const
unsigned int &flags) VP_OVERRIDE;
746 virtual
void track(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
748 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
751 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
757 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
771 const std::
string &name = "") VP_OVERRIDE;
774 const std::
string &name = "") VP_OVERRIDE;
779 virtual
void initMbtTracking(const
vpImage<
unsigned char> *const ptr_I);
781 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
783 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
785 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
787 virtual void postTracking(
const vpImage<unsigned char> *
const ptr_I =
nullptr,
const unsigned int pointcloud_width = 0,
788 const unsigned int pointcloud_height = 0);
790 const std::vector<vpColVector> *
const point_cloud =
nullptr,
791 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
793 const vpMatrix *
const point_cloud =
nullptr,
794 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
800 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
803 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
808 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
816 #ifdef VISP_HAVE_NLOHMANN_JSON
817 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
818 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
857 #ifdef VISP_HAVE_NLOHMANN_JSON
859 #define MBT_JSON_SETTINGS_VERSION "1.0"
862 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
883 inline void to_json(nlohmann::json &j,
const vpMbGenericTracker::TrackerWrapper &t)
886 const static std::vector<vpMbGenericTracker::vpTrackerType> trackerTypes = {
888 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
896 {
"type", flagsToJSON(t.m_trackerType, trackerTypes)},
898 {
"angleDisappear",
vpMath::deg(t.getAngleDisappear())},
900 {
"useLod", t.useLodGeneral},
901 {
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral},
902 {
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral}
905 {
"features", t.displayFeatures},
906 {
"projectionError", t.m_projectionErrorDisplay}
910 {
"scanline", t.useScanLine}
913 {
"flags", clippingFlagsToJSON(t.getClipping())},
914 {
"near", t.getNearClippingDistance()},
915 {
"far", t.getFarClippingDistance()},
924 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
926 nlohmann::json klt = nlohmann::json {
927 {
"maxFeatures", t.tracker.getMaxFeatures()},
928 {
"windowSize", t.tracker.getWindowSize()},
929 {
"quality", t.tracker.getQuality()},
930 {
"minDistance", t.tracker.getMinDistance()},
931 {
"harris", t.tracker.getHarrisFreeParameter()},
932 {
"blockSize", t.tracker.getBlockSize()},
933 {
"pyramidLevels", t.tracker.getPyramidLevels()}
935 klt[
"maskBorder"] = t.maskBorder;
941 j[
"normals"] = nlohmann::json {
942 {
"featureEstimationMethod", t.m_depthNormalFeatureEstimationMethod},
944 {
"method", t.m_depthNormalPclPlaneEstimationMethod},
945 {
"ransacMaxIter", t.m_depthNormalPclPlaneEstimationRansacMaxIter},
946 {
"ransacThreshold", t.m_depthNormalPclPlaneEstimationRansacThreshold}
949 {
"x", t.m_depthNormalSamplingStepX},
950 {
"y", t.m_depthNormalSamplingStepY}
958 {
"x", t.m_depthDenseSamplingStepX},
959 {
"y", t.m_depthDenseSamplingStepY}
984 inline void from_json(
const nlohmann::json &j, vpMbGenericTracker::TrackerWrapper &t)
986 t.setCameraParameters(j.at(
"camera"));
987 t.setTrackerType(flagsFromJSON<vpMbGenericTracker::vpTrackerType>(j.at(
"type")));
989 if (j.contains(
"angleAppear")) {
990 t.setAngleAppear(
vpMath::rad(
static_cast<double>(j.at(
"angleAppear"))));
992 if (j.contains(
"angleDisappear")) {
993 t.setAngleDisappear(
vpMath::rad(
static_cast<double>(j.at(
"angleDisappear"))));
995 if (j.contains(
"clipping")) {
996 const nlohmann::json clipping = j[
"clipping"];
997 t.setNearClippingDistance(clipping.value(
"near", t.getNearClippingDistance()));
998 t.setFarClippingDistance(clipping.value(
"far", t.getFarClippingDistance()));
999 if (clipping.contains(
"flags")) {
1000 t.setClipping(flagsFromJSON<vpPolygon3D::vpPolygon3DClippingType>(clipping.at(
"flags")));
1003 if (j.contains(
"lod")) {
1004 const nlohmann::json lod = j[
"lod"];
1005 t.useLodGeneral = lod.value(
"useLod", t.useLodGeneral);
1006 t.minLineLengthThresholdGeneral = lod.value(
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral);
1007 t.minPolygonAreaThresholdGeneral = lod.value(
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral);
1008 t.applyLodSettingInConfig =
false;
1009 if (t.getNbPolygon() > 0) {
1010 t.applyLodSettingInConfig =
true;
1011 t.setLod(t.useLodGeneral);
1012 t.setMinLineLengthThresh(t.minLineLengthThresholdGeneral);
1013 t.setMinPolygonAreaThresh(t.minPolygonAreaThresholdGeneral);
1016 if (j.contains(
"display")) {
1017 const nlohmann::json displayJson = j[
"display"];
1018 t.setDisplayFeatures(displayJson.value(
"features", t.displayFeatures));
1019 t.setProjectionErrorDisplay(displayJson.value(
"projectionError", t.m_projectionErrorDisplay));
1021 if (j.contains(
"visibilityTest")) {
1022 const nlohmann::json visJson = j[
"visibilityTest"];
1023 t.setOgreVisibilityTest(visJson.value(
"ogre", t.useOgre));
1024 t.setScanLineVisibilityTest(visJson.value(
"scanline", t.useScanLine));
1031 t.setMovingEdge(t.me);
1034 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
1036 const nlohmann::json klt = j.at(
"klt");
1037 auto &ktrack = t.tracker;
1038 ktrack.setMaxFeatures(klt.value(
"maxFeatures", 10000));
1039 ktrack.setWindowSize(klt.value(
"windowSize", 5));
1040 ktrack.setQuality(klt.value(
"quality", 0.01));
1041 ktrack.setMinDistance(klt.value(
"minDistance", 5));
1042 ktrack.setHarrisFreeParameter(klt.value(
"harris", 0.01));
1043 ktrack.setBlockSize(klt.value(
"blockSize", 3));
1044 ktrack.setPyramidLevels(klt.value(
"pyramidLevels", 3));
1045 t.setMaskBorder(klt.value(
"maskBorder", t.maskBorder));
1046 t.faces.getMbScanLineRenderer().setMaskBorder(t.maskBorder);
1049 if (j.contains(
"klt")) {
1050 std::cerr <<
"Trying to load a KLT tracker, but the ViSP dependency requirements are not met. Ignoring." << std::endl;
1055 const nlohmann::json n = j.at(
"normals");
1056 t.setDepthNormalFeatureEstimationMethod(n.at(
"featureEstimationMethod"));
1057 if (n.contains(
"pcl")) {
1058 const nlohmann::json pcl = n[
"pcl"];
1059 t.setDepthNormalPclPlaneEstimationMethod(pcl.at(
"method"));
1060 t.setDepthNormalPclPlaneEstimationRansacMaxIter(pcl.at(
"ransacMaxIter"));
1061 t.setDepthNormalPclPlaneEstimationRansacThreshold(pcl.at(
"ransacThreshold"));
1063 if (n.contains(
"sampling")) {
1064 const nlohmann::json sampling = n.at(
"sampling");
1065 t.setDepthNormalSamplingStep(sampling.at(
"x"), sampling.at(
"y"));
1070 const nlohmann::json dense = j.at(
"dense");
1071 if (dense.contains(
"sampling")) {
1072 const nlohmann::json sampling = dense.at(
"sampling");
1073 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 setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &) VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &) VP_OVERRIDE
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) 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 std::vector< std::vector< double > > getFeaturesForDisplay()
virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE
virtual int getTrackerType() const
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
std::map< std::string, TrackerWrapper * > m_mapOfTrackers
virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE
virtual vpColVector getError() const 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 initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="") VP_OVERRIDE
virtual void initFaceFromCorners(vpMbtPolygon &polygon) 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 testTracking() VP_OVERRIDE
virtual unsigned int getNbFeaturesKlt() const
unsigned int m_nb_feat_depthDense
Number of depth dense features.
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 computeVVSInit() VP_OVERRIDE
virtual void init(const vpImage< unsigned char > &I) VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &I) VP_OVERRIDE
vpColVector m_weightedError
Weighted error.
vpMatrix m_L
Interaction matrix.
virtual void computeVVSWeights()
virtual unsigned int getNbFeaturesDepthNormal() const
vpColVector m_error
(s - s*)
virtual vpColVector getRobustWeights() const VP_OVERRIDE
virtual void setClipping(const unsigned int &flags) VP_OVERRIDE
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 setTrackerType(int type)
virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE
unsigned int m_nb_feat_klt
Number of klt features.
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="") VP_OVERRIDE
unsigned int m_nb_feat_depthNormal
Number of depth normal features.
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
virtual void resetTracker() VP_OVERRIDE
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE
virtual void preTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages, std::map< std::string, pcl::PointCloud< pcl::PointXYZ >::ConstPtr > &mapOfPointClouds)
virtual void setNearClippingDistance(const double &dist) 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
std::string m_referenceCameraName
Name of the reference camera.
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 from_json(const nlohmann::json &j, TrackerWrapper &t)
Load configuration settings from a JSON object for a tracker wrapper.
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
virtual void setFarClippingDistance(const double &dist) 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.