Skip to content

Commit

Permalink
Setup testing rbt module, testing basic configuration/user api
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Sep 24, 2024
1 parent b09b6f1 commit 8cbee82
Show file tree
Hide file tree
Showing 11 changed files with 750 additions and 57 deletions.
10 changes: 10 additions & 0 deletions modules/tracker/rbt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ if(WITH_SIMDLIB)
list(APPEND opt_libs_private ${SIMDLIB_LIBRARIES})
endif()

if(WITH_CATCH2)
# catch2 is private
include_directories(${CATCH2_INCLUDE_DIRS})
endif()


vp_add_module(rbt visp_vision visp_core visp_me visp_visual_features visp_ar OPTIONAL visp_klt visp_gui PRIVATE_OPTIONAL ${opt_libs_private})
vp_glob_module_sources()

vp_module_include_directories(${opt_incs})
vp_create_module(${opt_libs})

vp_add_tests(DEPENDS_ON visp_core visp_gui visp_io)

if(VISP_DATASET_FOUND)

endif()
6 changes: 3 additions & 3 deletions modules/tracker/rbt/include/visp3/rbt/vpRBDenseDepthTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ class VISP_EXPORT vpRBDenseDepthTracker : public vpRBFeatureTracker
virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
{
vpRBFeatureTracker::loadJsonConfiguration(j);
m_step = j.value("step", m_step);
m_useMask = j.value("useMask", m_useMask);
m_minMaskConfidence = j.value("minMaskConfidence", m_minMaskConfidence);
setStep(j.value("step", m_step));
setShouldUseMask(j.value("useMask", m_useMask));
setMinimumMaskConfidence(j.value("minMaskConfidence", m_minMaskConfidence));
}

#endif
Expand Down
13 changes: 10 additions & 3 deletions modules/tracker/rbt/include/visp3/rbt/vpRBSilhouetteCCDTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ inline void from_json(const nlohmann::json &j, vpCCDParameters &ccdParameters)
ccdParameters.phi_dim = j.value("phi_dim", ccdParameters.phi_dim);
if (j.contains("gamma")) {
nlohmann::json gammaj = j["gamma"];
if (!j.is_array() || j.size() != 4) {
if (!gammaj.is_array() || gammaj.size() != 4) {
throw vpException(vpException::ioError, "CCD parameters: tried to read gamma values from something that is not a 4-sized float array");
}
ccdParameters.gamma_1 = gammaj[0];
Expand Down Expand Up @@ -211,7 +211,14 @@ class VISP_EXPORT vpRBSilhouetteCCDTracker : public vpRBFeatureTracker
*
* @param factor the new temporal smoothing factor. Should be greater than 0
*/
void setTemporalSmoothingFactor(double factor) { m_temporalSmoothingFac = factor; }
void setTemporalSmoothingFactor(double factor)
{
if (factor < 0.0) {
throw vpException(vpException::badValue, "Temporal smoothing factor should be equal to or greater than 0");
}
m_temporalSmoothingFac = factor;

}
/**
* @}
*/
Expand All @@ -238,7 +245,7 @@ class VISP_EXPORT vpRBSilhouetteCCDTracker : public vpRBFeatureTracker
{
vpRBFeatureTracker::loadJsonConfiguration(j);
m_vvsConvergenceThreshold = j.value("convergenceThreshold", m_vvsConvergenceThreshold);
m_temporalSmoothingFac = j.value("temporalSmoothing", m_temporalSmoothingFac);
setTemporalSmoothingFactor(j.value("temporalSmoothing", m_temporalSmoothingFac));
m_ccdParameters = j.value("ccd", m_ccdParameters);
}

Expand Down
79 changes: 74 additions & 5 deletions modules/tracker/rbt/include/visp3/rbt/vpRBSilhouetteMeTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,90 @@ class VISP_EXPORT vpRBSilhouetteMeTracker : public vpRBFeatureTracker

void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth, const vpRBFeatureDisplayType type) const VP_OVERRIDE;

/**
* \name Settings
* @{
*/
const vpMe &getMe() const { return m_me; }
vpMe &getMe() { return m_me; }

unsigned int getNumCandidates() const { return m_numCandidates; }
void setNumCandidates(unsigned int candidates)
{
if (candidates == 0) {
throw vpException(vpException::badValue, "Cannot set a number of candidates equal to zero");
}
m_numCandidates = candidates;
}

double getMinRobustThreshold() const { return m_robustMadMin; }
void setMinRobustThreshold(double threshold)
{
if (threshold < 0) {
throw vpException(vpException::badValue, "Robust M estimator min threshold should be greater or equal to 0.");
}
m_robustMadMin = threshold;
}

/**
* \brief Returns whether the tracking algorithm should filter out points that are unlikely to be on the object according to the mask.
* If the mask is not computed beforehand, then it has no effect
*/
bool shouldUseMask() const { return m_useMask; }
void setShouldUseMask(bool useMask) { m_useMask = useMask; }

/**
* \brief Returns the minimum mask confidence that a pixel linked to depth point should have if it should be kept during tracking.
*
* This value is between 0 and 1
*/
float getMinimumMaskConfidence() const { return m_minMaskConfidence; }
void setMinimumMaskConfidence(float confidence)
{
if (confidence > 1.f || confidence < 0.f) {
throw vpException(vpException::badValue, "Mask confidence should be between 0 and 1");
}
m_minMaskConfidence = confidence;
}

double getSinglePointConvergenceThreshold() const { return m_singlePointConvergedThresholdPixels; }
void setSinglePointConvergenceThreshold(double threshold)
{
if (threshold < 0.0) {
throw vpException(vpException::badValue, "Convergence threshold should be null or positive");
}
m_singlePointConvergedThresholdPixels = threshold;
}

double getGlobalConvergenceMinimumRatio() const { return m_globalVVSConvergenceThreshold; }
void setGlobalConvergenceMinimumRatio(double threshold)
{
if (threshold < 0.0 || threshold > 1.0) {
throw vpException(vpException::badValue, "Minimum converged ratio be between 0 and 1");
}
m_globalVVSConvergenceThreshold = threshold;
}

#if defined(VISP_HAVE_NLOHMANN_JSON)
virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
{
vpRBFeatureTracker::loadJsonConfiguration(j);
m_numCandidates = j.value("numCandidates", m_numCandidates);
m_singlePointConvergedThresholdPixels = j.value("convergencePixelThreshold", m_singlePointConvergedThresholdPixels);
m_globalVVSConvergenceThreshold = j.value("convergenceRatio", m_globalVVSConvergenceThreshold);
setNumCandidates(j.value("numCandidates", m_numCandidates));
setSinglePointConvergenceThreshold(j.value("convergencePixelThreshold", m_singlePointConvergedThresholdPixels));
setGlobalConvergenceMinimumRatio(j.value("convergenceRatio", m_globalVVSConvergenceThreshold));
m_me = j.value("movingEdge", m_me);
m_useMask = j.value("useMask", m_useMask);
m_minMaskConfidence = j.value("minMaskConfidence", m_minMaskConfidence);
setShouldUseMask(j.value("useMask", m_useMask));
setMinimumMaskConfidence(j.value("minMaskConfidence", m_minMaskConfidence));
// m_me.setThresholdMarginRatio(-1.0);
// m_me.setMinThreshold(-1.0);
}
#endif

/**
* \name Settings
* @}
*/

private:

std::vector<vpRBSilhouetteControlPoint> m_controlPoints;
Expand Down
21 changes: 17 additions & 4 deletions modules/tracker/rbt/include/visp3/rbt/vpRBTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ class VISP_EXPORT vpRBTracker
* @{
*/
void addTracker(std::shared_ptr<vpRBFeatureTracker> tracker);
void loadObjectModel(const std::string &file);
void setupRenderer(const std::string &file);
void setModelPath(const std::string &path);

vpCameraParameters getCameraParameters() const;
void setCameraParameters(const vpCameraParameters &cam, unsigned h, unsigned w);

unsigned int getImageWidth() const { return m_imageWidth; }
unsigned int getImageHeight() const { return m_imageHeight; }

vpSilhouettePointsExtractionSettings getSilhouetteExtractionParameters() const
{
return m_depthSilhouetteSettings;
Expand All @@ -114,13 +118,19 @@ class VISP_EXPORT vpRBTracker
m_lambda = lambda;
}
unsigned int getMaxOptimizationIters() const { return m_vvsIterations; }
void setMaxOptimizationIters(unsigned int iters) { m_vvsIterations = iters; }
void setMaxOptimizationIters(unsigned int iters)
{
if (iters == 0) {
throw vpException(vpException::badValue, "Max number of iterations must be greater than zero");
}
m_vvsIterations = iters;
}

double getOptimizationInitialMu() const { return m_muInit; }
void setOptimizationInitialMu(double mu)
{
if (mu < 0.0) {
throw vpException(vpException::badValue, "Optimization gain should be greater to zero");
throw vpException(vpException::badValue, "Optimization gain should be greater or equal to zero");
}
m_muInit = mu;
}
Expand All @@ -129,7 +139,7 @@ class VISP_EXPORT vpRBTracker
void setOptimizationMuIterFactor(double factor)
{
if (factor < 0.0) {
throw vpException(vpException::badValue, "Optimization gain should be greater to zero");
throw vpException(vpException::badValue, "Optimization gain should be greater or equal to zero");
}
m_muIterFactor = factor;
}
Expand Down Expand Up @@ -157,10 +167,12 @@ class VISP_EXPORT vpRBTracker

void reset();


/**
* \name Tracking
* @{
*/
void startTracking();
void track(const vpImage<unsigned char> &I);
void track(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB);
void track(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<float> &depth);
Expand Down Expand Up @@ -211,6 +223,7 @@ class VISP_EXPORT vpRBTracker
vpRBFeatureTrackerInput m_currentFrame;
vpRBFeatureTrackerInput m_previousFrame;

std::string m_modelPath;
vpHomogeneousMatrix m_cMo;
vpHomogeneousMatrix m_cMoPrev;
vpCameraParameters m_cam;
Expand Down
Loading

0 comments on commit 8cbee82

Please sign in to comment.