Skip to content

Commit

Permalink
Moved klt parameters json serialization to vpKltOpencv, working on be…
Browse files Browse the repository at this point in the history
…tter integrating mask in klt tracker
  • Loading branch information
SamFlt committed Sep 19, 2024
1 parent 635acf8 commit 9e5c1b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
40 changes: 40 additions & 0 deletions modules/tracker/klt/include/visp3/klt/vpKltOpencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/video/tracking.hpp>

#if defined(VISP_HAVE_NLOHMANN_JSON)
#include <nlohmann/json.hpp>
#endif


BEGIN_VISP_NAMESPACE
/*!
* \class vpKltOpencv
Expand Down Expand Up @@ -383,6 +388,12 @@ class VISP_EXPORT vpKltOpencv
*/
void suppressFeature(const int &index);

#ifdef VISP_HAVE_NLOHMANN_JSON

friend void to_json(nlohmann::json &j, const vpKltOpencv &array);
friend void from_json(const nlohmann::json &j, vpKltOpencv &array);
#endif

protected:
cv::Mat m_gray; //!< Gray image
cv::Mat m_prevGray; //!< Previous gray image
Expand All @@ -401,6 +412,35 @@ class VISP_EXPORT vpKltOpencv
long m_next_points_id; //!< Id for the newt keypoint
bool m_initial_guess; //!< true when initial guess is provided
};

#ifdef VISP_HAVE_NLOHMANN_JSON
inline void to_json(nlohmann::json &j, const vpKltOpencv &klt)
{
j = nlohmann::json {
{"maxFeatures", klt.getMaxFeatures()},
{"windowSize", klt.getWindowSize()},
{"quality", klt.getQuality()},
{"minDistance", klt.getMinDistance()},
{"useHarris", klt.m_useHarrisDetector},
{"harris", klt.getHarrisFreeParameter()},
{"blockSize", klt.getBlockSize()},
{"pyramidLevels", klt.getPyramidLevels()}
};
}

inline void from_json(const nlohmann::json &j, vpKltOpencv &klt)
{
klt.setMaxFeatures(j.value("maxFeatures", 10000));
klt.setWindowSize(j.value("windowSize", 5));
klt.setQuality(j.value("quality", 0.01));
klt.setMinDistance(j.value("minDistance", 5));
klt.setUseHarris(j.value("useHarris", true));
klt.setHarrisFreeParameter(j.value("harris", 0.01));
klt.setBlockSize(j.value("blockSize", 3));
klt.setPyramidLevels(j.value("pyramidLevels", 3));
}
#endif

END_VISP_NAMESPACE
#endif
#endif
25 changes: 10 additions & 15 deletions tutorial/tracking/render-based/data/sequence1/dragon.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"sampling" : {
"samplingRate": 1,
"numPoints": 512
"numPoints": 128
}
},

Expand All @@ -37,7 +37,7 @@
},
"drift": {
"type": "probabilistic",
"colorUpdateRate": 0.3,
"colorUpdateRate": 0.1,
"initialColorSigma": 15.0,
"depthSigma": 0.01,
"filteringMaxDistance": 0.001,
Expand All @@ -51,27 +51,22 @@
"useMask": true,
"minMaskConfidence": 0.7
},
{
"type": "silhouetteColor",
"weight": 0.01,
"ccd": {
"h": 8,
"delta_h": 1
}
},

{
"type": "klt",
"weight": 0.1,
"useMask": true,
"minMaskConfidence": 0.5,
"maxReprojectionErrorPixels": 5.0,
"newPointsMinPixelDistance": 2,
"newPointsMinPixelDistance": 4,
"minimumNumPoints": 20,
"blockSize": 3,
"blockSize": 5,
"useHarris": true,
"harris": 0.05,
"maskBorder": 5,
"maxFeatures": 200,
"maxFeatures": 500,
"minDistance": 5.0,
"pyramidLevels": 3,
"quality": 0.1,
"quality": 0.05,
"windowSize": 5
}
]
Expand Down

0 comments on commit 9e5c1b7

Please sign in to comment.