39 #ifndef VP_MB_GENERIC_TRACKER_H
40 #define VP_MB_GENERIC_TRACKER_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>
47 #include <visp3/core/vpJsonParsing.h>
205 EDGE_TRACKER = 1 << 0,
206 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO))
207 KLT_TRACKER = 1 << 1,
209 DEPTH_NORMAL_TRACKER = 1 << 2,
210 DEPTH_DENSE_TRACKER = 1 << 3
216 vpMbGenericTracker(
const std::vector<std::string> &cameraNames,
const std::vector<int> &trackerTypes);
226 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
228 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
230 virtual
void display(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
233 bool displayFullModel = false);
236 const
vpColor &color,
unsigned int thickness = 1,
bool displayFullModel = false);
238 virtual
void display(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
241 unsigned int thickness = 1,
bool displayFullModel = false);
242 virtual
void display(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfImages,
245 unsigned int thickness = 1,
bool displayFullModel = false);
247 virtual std::vector<std::
string> getCameraNames() const;
252 virtual
void getCameraParameters(std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters) const;
254 virtual std::map<std::
string,
int> getCameraTrackerTypes() const;
257 virtual
void getClipping(
unsigned int &clippingFlag1,
unsigned int &clippingFlag2) const;
258 virtual
void getClipping(std::map<std::
string,
unsigned int> &mapOfClippingFlags) const;
260 virtual inline
vpColVector getError() const VP_OVERRIDE {
return m_error; }
265 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
266 virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle();
267 virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder();
268 virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt();
271 virtual std::vector<std::vector<double> > getFeaturesForDisplay();
272 virtual void getFeaturesForDisplay(std::map<std::string, std::vector<std::vector<double> > > &mapOfFeatures);
274 virtual double getGoodMovingEdgesRatioThreshold()
const;
276 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
277 virtual std::vector<vpImagePoint> getKltImagePoints()
const;
278 virtual std::map<int, vpImagePoint> getKltImagePointsWithId()
const;
280 virtual unsigned int getKltMaskBorder()
const;
281 virtual int getKltNbPoints()
const;
285 virtual void getKltOpencv(std::map<std::string, vpKltOpencv> &mapOfKlts)
const;
287 #if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
288 virtual std::vector<cv::Point2f> getKltPoints()
const;
291 virtual double getKltThresholdAcceptation()
const;
294 virtual void getLcircle(std::list<vpMbtDistanceCircle *> &circlesList,
unsigned int level = 0)
const;
295 virtual void getLcircle(
const std::string &cameraName, std::list<vpMbtDistanceCircle *> &circlesList,
296 unsigned int level = 0)
const;
297 virtual void getLcylinder(std::list<vpMbtDistanceCylinder *> &cylindersList,
unsigned int level = 0)
const;
298 virtual void getLcylinder(
const std::string &cameraName, std::list<vpMbtDistanceCylinder *> &cylindersList,
299 unsigned int level = 0)
const;
300 virtual void getLline(std::list<vpMbtDistanceLine *> &linesList,
unsigned int level = 0)
const;
301 virtual void getLline(
const std::string &cameraName, std::list<vpMbtDistanceLine *> &linesList,
302 unsigned int level = 0)
const;
304 virtual std::vector<std::vector<double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
307 bool displayFullModel =
false) VP_OVERRIDE;
308 virtual
void getModelForDisplay(std::map<std::
string, std::vector<std::vector<
double> > > &mapOfModels,
309 const std::map<std::
string,
unsigned int> &mapOfwidths,
310 const std::map<std::
string,
unsigned int> &mapOfheights,
313 bool displayFullModel = false);
315 virtual
vpMe getMovingEdge() const;
316 virtual
void getMovingEdge(
vpMe &me1,
vpMe &me2) const;
317 virtual
void getMovingEdge(std::map<std::
string,
vpMe> &mapOfMovingEdges) const;
322 virtual inline
unsigned int getNbFeaturesDepthDense()
const {
return m_nb_feat_depthDense; }
341 virtual unsigned int getNbPoints(
unsigned int level = 0)
const;
342 virtual void getNbPoints(std::map<std::string, unsigned int> &mapOfNbPoints,
unsigned int level = 0)
const;
345 virtual
void getNbPolygon(std::map<std::
string,
unsigned int> &mapOfNbPolygons) const;
347 virtual
vpMbtPolygon *getPolygon(
unsigned int index) VP_OVERRIDE;
348 virtual
vpMbtPolygon *getPolygon(const std::
string &cameraName,
unsigned int index);
350 virtual std::pair<std::vector<
vpPolygon>, std::vector<std::vector<
vpPoint> > >
351 getPolygonFaces(
bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false) VP_OVERRIDE;
352 virtual
void getPolygonFaces(std::map<std::
string, std::vector<
vpPolygon> > &mapOfPolygons,
353 std::map<std::
string, std::vector<std::vector<
vpPoint> > > &mapOfPoints,
354 bool orderPolygons = true,
bool useVisibility = true,
bool clipPolygon = false);
361 virtual std::
string getReferenceCameraName() const;
363 virtual inline
vpColVector getRobustWeights() const VP_OVERRIDE {
return m_w; }
365 virtual int getTrackerType()
const;
369 #ifdef VISP_HAVE_MODULE_GUI
370 using vpMbTracker::initClick;
372 const std::string &initFile1,
const std::string &initFile2,
bool displayHelp =
false,
376 const std::string &initFile2,
bool displayHelp =
false,
382 const std::map<std::string, std::string> &mapOfInitFiles,
bool displayHelp =
false,
383 const std::map<std::string, vpHomogeneousMatrix> &mapOfT = std::map<std::string, vpHomogeneousMatrix>());
385 initClick(
const std::map<std::string,
const vpImage<vpRGBa> *> &mapOfImages,
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>());
392 const std::string &initFile1,
const std::string &initFile2);
394 const std::string &initFile1,
const std::string &initFile2);
397 const std::map<std::string, std::string> &mapOfInitPoints);
399 const std::map<std::string, std::string> &mapOfInitPoints);
404 const std::string &initFile1,
const std::string &initFile2);
406 const std::string &initFile1,
const std::string &initFile2);
409 const std::map<std::string, std::string> &mapOfInitPoses);
411 const std::map<std::string, std::string> &mapOfInitPoses);
419 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
421 const std::map<std::string, vpHomogeneousMatrix> &mapOfCameraPoses);
423 virtual void loadConfigFile(
const std::string &configFile,
bool verbose =
true) VP_OVERRIDE;
424 virtual
void loadConfigFile(const std::
string &configFile1, const std::
string &configFile2,
bool verbose = true);
425 virtual
void loadConfigFile(const std::map<std::
string, std::
string> &mapOfConfigFiles,
bool verbose = true);
427 #ifdef VISP_HAVE_NLOHMANN_JSON
428 virtual void saveConfigFile(
const std::string &settingsFile)
const;
431 virtual void loadModel(
const std::string &modelFile,
bool verbose =
false,
433 virtual
void loadModel(const std::
string &modelFile1, const std::
string &modelFile2,
bool verbose = false,
438 loadModel(const std::map<std::
string, std::
string> &mapOfModelFiles,
bool verbose = false,
446 virtual
void reInitModel(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
447 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
452 const std::
string &cad_name1, const std::
string &cad_name2, const
vpHomogeneousMatrix &c1Mo,
458 reInitModel(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
459 const std::map<std::
string, std::
string> &mapOfModelFiles,
463 reInitModel(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
464 const std::map<std::
string, std::
string> &mapOfModelFiles,
468 virtual
void resetTracker() VP_OVERRIDE;
470 virtual
void setAngleAppear(const
double &a) VP_OVERRIDE;
471 virtual
void setAngleAppear(const
double &a1, const
double &a2);
472 virtual
void setAngleAppear(const std::map<std::
string,
double> &mapOfAngles);
474 virtual
void setAngleDisappear(const
double &a) VP_OVERRIDE;
475 virtual
void setAngleDisappear(const
double &a1, const
double &a2);
476 virtual
void setAngleDisappear(const std::map<std::
string,
double> &mapOfAngles);
480 virtual
void setCameraParameters(const std::map<std::
string,
vpCameraParameters> &mapOfCameraParameters);
482 virtual
void setCameraTransformationMatrix(const std::
string &cameraName,
485 setCameraTransformationMatrix(const std::map<std::
string,
vpHomogeneousMatrix> &mapOfTransformationMatrix);
487 virtual
void setClipping(const
unsigned int &flags) VP_OVERRIDE;
488 virtual
void setClipping(const
unsigned int &flags1, const
unsigned int &flags2);
489 virtual
void setClipping(const std::map<std::
string,
unsigned int> &mapOfClippingFlags);
491 virtual
void setDepthDenseFilteringMaxDistance(
double maxDistance);
492 virtual
void setDepthDenseFilteringMethod(
int method);
493 virtual
void setDepthDenseFilteringMinDistance(
double minDistance);
494 virtual
void setDepthDenseFilteringOccupancyRatio(
double occupancyRatio);
495 virtual
void setDepthDenseSamplingStep(
unsigned int stepX,
unsigned int stepY);
497 virtual
void setDepthNormalFaceCentroidMethod(const
vpMbtFaceDepthNormal::vpFaceCentroidType &method);
498 virtual
void setDepthNormalFeatureEstimationMethod(const
vpMbtFaceDepthNormal::vpFeatureEstimationType &method);
499 virtual
void setDepthNormalPclPlaneEstimationMethod(
int method);
500 virtual
void setDepthNormalPclPlaneEstimationRansacMaxIter(
int maxIter);
501 virtual
void setDepthNormalPclPlaneEstimationRansacThreshold(
double threshold);
502 virtual
void setDepthNormalSamplingStep(
unsigned int stepX,
unsigned int stepY);
504 virtual
void setDisplayFeatures(
bool displayF) VP_OVERRIDE;
506 virtual
void setFarClippingDistance(const
double &dist) VP_OVERRIDE;
507 virtual
void setFarClippingDistance(const
double &dist1, const
double &dist2);
508 virtual
void setFarClippingDistance(const std::map<std::
string,
double> &mapOfClippingDists);
510 virtual
void setFeatureFactors(const std::map<vpTrackerType,
double> &mapOfFeatureFactors);
512 virtual
void setGoodMovingEdgesRatioThreshold(
double threshold);
514 #ifdef VISP_HAVE_OGRE
519 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
520 virtual void setKltMaskBorder(
const unsigned int &e);
521 virtual void setKltMaskBorder(
const unsigned int &e1,
const unsigned int &e2);
522 virtual void setKltMaskBorder(
const std::map<std::string, unsigned int> &mapOfErosions);
526 virtual void setKltOpencv(
const std::map<std::string, vpKltOpencv> &mapOfKlts);
528 virtual void setKltThresholdAcceptation(
double th);
531 virtual void setLod(
bool useLod,
const std::string &name =
"") VP_OVERRIDE;
533 virtual
void setMask(const
vpImage<
bool> &mask) VP_OVERRIDE;
535 virtual
void setMinLineLengthThresh(
double minLineLengthThresh, const std::
string &name = "") VP_OVERRIDE;
536 virtual
void setMinPolygonAreaThresh(
double minPolygonAreaThresh, const std::
string &name = "") VP_OVERRIDE;
538 virtual
void setMovingEdge(const
vpMe &me);
539 virtual
void setMovingEdge(const
vpMe &me1, const
vpMe &me2);
540 virtual
void setMovingEdge(const std::map<std::
string,
vpMe> &mapOfMe);
542 virtual
void setNearClippingDistance(const
double &dist) VP_OVERRIDE;
543 virtual
void setNearClippingDistance(const
double &dist1, const
double &dist2);
544 virtual
void setNearClippingDistance(const std::map<std::
string,
double> &mapOfDists);
546 virtual
void setOgreShowConfigDialog(
bool showConfigDialog) VP_OVERRIDE;
547 virtual
void setOgreVisibilityTest(const
bool &v) VP_OVERRIDE;
549 virtual
void setOptimizationMethod(const vpMbtOptimizationMethod &opt) VP_OVERRIDE;
554 virtual
void setPose(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2,
559 virtual
void setPose(const std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
561 virtual
void setPose(const std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages,
564 virtual
void setProjectionErrorComputation(const
bool &flag) VP_OVERRIDE;
566 virtual
void setProjectionErrorDisplay(
bool display) VP_OVERRIDE;
567 virtual
void setProjectionErrorDisplayArrowLength(
unsigned int length) VP_OVERRIDE;
568 virtual
void setProjectionErrorDisplayArrowThickness(
unsigned int thickness) VP_OVERRIDE;
570 virtual
void setReferenceCameraName(const std::
string &referenceCameraName);
572 virtual
void setScanLineVisibilityTest(const
bool &v) VP_OVERRIDE;
574 virtual
void setTrackerType(
int type);
575 virtual
void setTrackerType(const std::map<std::
string,
int> &mapOfTrackerTypes);
577 virtual
void setUseDepthDenseTracking(const std::
string &name, const
bool &useDepthDenseTracking);
578 virtual
void setUseDepthNormalTracking(const std::
string &name, const
bool &useDepthNormalTracking);
579 virtual
void setUseEdgeTracking(const std::
string &name, const
bool &useEdgeTracking);
580 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
581 virtual void setUseKltTracking(
const std::string &name,
const bool &useKltTracking);
586 virtual
void track(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
587 virtual
void track(const
vpImage<
vpRGBa> &I_color) VP_OVERRIDE;
589 virtual
void track(const
vpImage<
unsigned char> &I1, const
vpImage<
unsigned char> &I2);
592 virtual
void track(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
593 virtual
void track(std::map<std::
string, const
vpImage<
vpRGBa> *> &mapOfColorImages);
595 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
597 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
599 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
603 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
604 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
605 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
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);
612 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
613 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
614 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);
621 virtual void computeProjectionError();
626 virtual
void computeVVSInit(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages);
627 virtual
void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE;
628 virtual
void computeVVSInteractionMatrixAndResidu(std::map<std::
string, const
vpImage<
unsigned char> *> &mapOfImages,
631 virtual
void computeVVSWeights();
633 virtual
void initCircle(const
vpPoint &p1, const
vpPoint &p2, const
vpPoint &p3,
double radius,
int idFace = 0,
634 const std::
string &name = "") VP_OVERRIDE;
636 virtual
void initCylinder(const
vpPoint &p1, const
vpPoint &p2,
double radius,
int idFace = 0,
637 const std::
string &name = "") VP_OVERRIDE;
639 virtual
void initFaceFromCorners(
vpMbtPolygon &polygon) VP_OVERRIDE;
641 virtual
void initFaceFromLines(
vpMbtPolygon &polygon) VP_OVERRIDE;
643 virtual
void loadConfigFileXML(const std::
string &configFile,
bool verbose = true);
644 #ifdef VISP_HAVE_NLOHMANN_JSON
645 virtual void loadConfigFileJSON(
const std::string &configFile,
bool verbose =
true);
648 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
650 std::map<std::string, pcl::PointCloud<pcl::PointXYZ>::ConstPtr> &mapOfPointClouds);
653 std::map<std::string,
const std::vector<vpColVector> *> &mapOfPointClouds,
654 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
655 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
657 std::map<std::string, const vpMatrix *> &mapOfPointClouds,
658 std::map<std::string, unsigned int> &mapOfPointCloudWidths,
659 std::map<std::string, unsigned int> &mapOfPointCloudHeights);
663 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
664 public vpMbKltTracker,
670 #ifdef VISP_HAVE_NLOHMANN_JSON
671 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
672 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
688 explicit TrackerWrapper(
int trackerType);
694 virtual inline int getTrackerType()
const {
return m_trackerType; }
697 const vpColor &col,
unsigned int thickness = 1,
bool displayFullModel =
false) VP_OVERRIDE;
699 const
vpColor &col,
unsigned int thickness = 1,
bool displayFullModel = false) VP_OVERRIDE;
703 virtual std::vector<std::vector<
double> >
getModelForDisplay(
unsigned int width,
unsigned int height,
706 bool displayFullModel = false) VP_OVERRIDE;
708 virtual
void init(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
710 virtual
void loadConfigFile(const std::
string &configFile,
bool verbose = true) VP_OVERRIDE;
712 virtual
void reInitModel(const
vpImage<
unsigned char> &I, const std::
string &cad_name,
723 virtual
void setClipping(const
unsigned int &flags) VP_OVERRIDE;
742 virtual
void track(const
vpImage<
unsigned char> &I) VP_OVERRIDE;
744 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
747 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
753 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
767 const std::
string &name = "") VP_OVERRIDE;
770 const std::
string &name = "") VP_OVERRIDE;
775 virtual
void initMbtTracking(const
vpImage<
unsigned char> *const ptr_I);
777 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
779 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
781 const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
783 virtual void postTracking(
const vpImage<unsigned char> *
const ptr_I =
nullptr,
const unsigned int pointcloud_width = 0,
784 const unsigned int pointcloud_height = 0);
786 const std::vector<vpColVector> *
const point_cloud =
nullptr,
787 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
789 const vpMatrix *
const point_cloud =
nullptr,
790 const unsigned int pointcloud_width = 0,
const unsigned int pointcloud_height = 0);
796 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
799 #if !((__GNUC__ == 4) && (__GNUC_MINOR__ == 6))
804 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
812 #ifdef VISP_HAVE_NLOHMANN_JSON
813 friend void to_json(nlohmann::json &j,
const TrackerWrapper &t);
814 friend void from_json(
const nlohmann::json &j, TrackerWrapper &t);
853 #ifdef VISP_HAVE_NLOHMANN_JSON
855 #define MBT_JSON_SETTINGS_VERSION "1.0"
858 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
861 {vpMbGenericTracker::KLT_TRACKER,
"klt"},
879 inline void to_json(nlohmann::json &j,
const vpMbGenericTracker::TrackerWrapper &t)
882 const static std::vector<vpMbGenericTracker::vpTrackerType> trackerTypes = {
884 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
885 vpMbGenericTracker::KLT_TRACKER,
892 {
"type", flagsToJSON(t.m_trackerType, trackerTypes)},
894 {
"angleDisappear",
vpMath::deg(t.getAngleDisappear())},
896 {
"useLod", t.useLodGeneral},
897 {
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral},
898 {
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral}
901 {
"features", t.displayFeatures},
902 {
"projectionError", t.m_projectionErrorDisplay}
906 {
"scanline", t.useScanLine}
909 {
"flags", clippingFlagsToJSON(t.getClipping())},
910 {
"near", t.getNearClippingDistance()},
911 {
"far", t.getFarClippingDistance()},
920 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
921 if (t.m_trackerType & vpMbGenericTracker::KLT_TRACKER) {
922 nlohmann::json klt = nlohmann::json {
923 {
"maxFeatures", t.tracker.getMaxFeatures()},
924 {
"windowSize", t.tracker.getWindowSize()},
925 {
"quality", t.tracker.getQuality()},
926 {
"minDistance", t.tracker.getMinDistance()},
927 {
"harris", t.tracker.getHarrisFreeParameter()},
928 {
"blockSize", t.tracker.getBlockSize()},
929 {
"pyramidLevels", t.tracker.getPyramidLevels()}
931 klt[
"maskBorder"] = t.maskBorder;
937 j[
"normals"] = nlohmann::json {
938 {
"featureEstimationMethod", t.m_depthNormalFeatureEstimationMethod},
940 {
"method", t.m_depthNormalPclPlaneEstimationMethod},
941 {
"ransacMaxIter", t.m_depthNormalPclPlaneEstimationRansacMaxIter},
942 {
"ransacThreshold", t.m_depthNormalPclPlaneEstimationRansacThreshold}
945 {
"x", t.m_depthNormalSamplingStepX},
946 {
"y", t.m_depthNormalSamplingStepY}
954 {
"x", t.m_depthDenseSamplingStepX},
955 {
"y", t.m_depthDenseSamplingStepY}
980 inline void from_json(
const nlohmann::json &j, vpMbGenericTracker::TrackerWrapper &t)
982 t.setCameraParameters(j.at(
"camera"));
983 t.setTrackerType(flagsFromJSON<vpMbGenericTracker::vpTrackerType>(j.at(
"type")));
985 if (j.contains(
"angleAppear")) {
986 t.setAngleAppear(
vpMath::rad(
static_cast<double>(j.at(
"angleAppear"))));
988 if (j.contains(
"angleDisappear")) {
989 t.setAngleDisappear(
vpMath::rad(
static_cast<double>(j.at(
"angleDisappear"))));
991 if (j.contains(
"clipping")) {
992 const nlohmann::json clipping = j[
"clipping"];
993 t.setNearClippingDistance(clipping.value(
"near", t.getNearClippingDistance()));
994 t.setFarClippingDistance(clipping.value(
"far", t.getFarClippingDistance()));
995 if (clipping.contains(
"flags")) {
996 t.setClipping(flagsFromJSON<vpPolygon3D::vpPolygon3DClippingType>(clipping.at(
"flags")));
999 if (j.contains(
"lod")) {
1000 const nlohmann::json lod = j[
"lod"];
1001 t.useLodGeneral = lod.value(
"useLod", t.useLodGeneral);
1002 t.minLineLengthThresholdGeneral = lod.value(
"minLineLengthThresholdGeneral", t.minLineLengthThresholdGeneral);
1003 t.minPolygonAreaThresholdGeneral = lod.value(
"minPolygonAreaThresholdGeneral", t.minPolygonAreaThresholdGeneral);
1004 t.applyLodSettingInConfig =
false;
1005 if (t.getNbPolygon() > 0) {
1006 t.applyLodSettingInConfig =
true;
1007 t.setLod(t.useLodGeneral);
1008 t.setMinLineLengthThresh(t.minLineLengthThresholdGeneral);
1009 t.setMinPolygonAreaThresh(t.minPolygonAreaThresholdGeneral);
1012 if (j.contains(
"display")) {
1013 const nlohmann::json displayJson = j[
"display"];
1014 t.setDisplayFeatures(displayJson.value(
"features", t.displayFeatures));
1015 t.setProjectionErrorDisplay(displayJson.value(
"projectionError", t.m_projectionErrorDisplay));
1017 if (j.contains(
"visibilityTest")) {
1018 const nlohmann::json visJson = j[
"visibilityTest"];
1019 t.setOgreVisibilityTest(visJson.value(
"ogre", t.useOgre));
1020 t.setScanLineVisibilityTest(visJson.value(
"scanline", t.useScanLine));
1027 t.setMovingEdge(t.me);
1030 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
1031 if (t.m_trackerType & vpMbGenericTracker::KLT_TRACKER) {
1032 const nlohmann::json klt = j.at(
"klt");
1033 auto &ktrack = t.tracker;
1034 ktrack.setMaxFeatures(klt.value(
"maxFeatures", 10000));
1035 ktrack.setWindowSize(klt.value(
"windowSize", 5));
1036 ktrack.setQuality(klt.value(
"quality", 0.01));
1037 ktrack.setMinDistance(klt.value(
"minDistance", 5));
1038 ktrack.setHarrisFreeParameter(klt.value(
"harris", 0.01));
1039 ktrack.setBlockSize(klt.value(
"blockSize", 3));
1040 ktrack.setPyramidLevels(klt.value(
"pyramidLevels", 3));
1041 t.setMaskBorder(klt.value(
"maskBorder", t.maskBorder));
1042 t.faces.getMbScanLineRenderer().setMaskBorder(t.maskBorder);
1045 if (j.contains(
"klt")) {
1046 std::cerr <<
"Trying to load a KLT tracker, but the ViSP dependency requirements are not met. Ignoring." << std::endl;
1051 const nlohmann::json n = j.at(
"normals");
1052 t.setDepthNormalFeatureEstimationMethod(n.at(
"featureEstimationMethod"));
1053 if (n.contains(
"pcl")) {
1054 const nlohmann::json pcl = n[
"pcl"];
1055 t.setDepthNormalPclPlaneEstimationMethod(pcl.at(
"method"));
1056 t.setDepthNormalPclPlaneEstimationRansacMaxIter(pcl.at(
"ransacMaxIter"));
1057 t.setDepthNormalPclPlaneEstimationRansacThreshold(pcl.at(
"ransacThreshold"));
1059 if (n.contains(
"sampling")) {
1060 const nlohmann::json sampling = n.at(
"sampling");
1061 t.setDepthNormalSamplingStep(sampling.at(
"x"), sampling.at(
"y"));
1066 const nlohmann::json dense = j.at(
"dense");
1067 if (dense.contains(
"sampling")) {
1068 const nlohmann::json sampling = dense.at(
"sampling");
1069 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
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 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.