Skip to content

Commit

Permalink
Remove display type parameter in display
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Dec 18, 2024
1 parent b9e0dd1 commit 20203be
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 106 deletions.
4 changes: 2 additions & 2 deletions modules/python/bindings/include/rbt/feature_tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ class TrampolineRBFeatureTracker : public vpRBFeatureTracker
override(&frame, cMo, iteration);
}
}
virtual 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
virtual void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE
{
pybind11::gil_scoped_acquire gil; // Acquire the GIL while in this scope.
// Try to look up the overridden method on the Python side.
pybind11::function override = pybind11::get_override(this, "display");
if (override) { // method is found
// Pybind seems to copy the frames, so we pass the pointers
override(cam, &I, &IRGB, &depth, type);
override(cam, &I, &IRGB, &depth);
}
}
virtual const vpMatrix getCovariance() const VP_OVERRIDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class VISP_EXPORT vpRBDenseDepthTracker : public vpRBFeatureTracker
void initVVS(const vpRBFeatureTrackerInput &/*frame*/, const vpRBFeatureTrackerInput &/*previousFrame*/, const vpHomogeneousMatrix &/*cMo*/) VP_OVERRIDE { }
void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration) VP_OVERRIDE;

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;
void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE;

struct vpDepthPoint
{
Expand Down
9 changes: 1 addition & 8 deletions modules/tracker/rbt/include/visp3/rbt/vpRBFeatureTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
#include VISP_NLOHMANN_JSON(json.hpp)
#endif

enum vpRBFeatureDisplayType
{
SIMPLE = 0,
IMPORTANCE = 1,
ERROR = 2
};

BEGIN_VISP_NAMESPACE
/**
Expand Down Expand Up @@ -155,8 +149,7 @@ class VISP_EXPORT vpRBFeatureTracker
const vpCameraParameters &cam,
const vpImage<unsigned char> &I,
const vpImage<vpRGBa> &IRGB,
const vpImage<unsigned char> &depth,
const vpRBFeatureDisplayType type) const = 0;
const vpImage<unsigned char> &depth) const = 0;

/**
* @}
Expand Down
2 changes: 1 addition & 1 deletion modules/tracker/rbt/include/visp3/rbt/vpRBKltTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class VISP_EXPORT vpRBKltTracker : public vpRBFeatureTracker

void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration) VP_OVERRIDE;

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;
void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE;

/**
* \name Settings
Expand Down
18 changes: 17 additions & 1 deletion modules/tracker/rbt/include/visp3/rbt/vpRBSilhouetteCCDTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@

BEGIN_VISP_NAMESPACE


enum vpRBSilhouetteCCDDisplayType
{
SIMPLE = 0,
WEIGHT = 1,
ERROR = 2,
INVALID = 3
};

class VISP_EXPORT vpCCDParameters
{
public:
Expand Down Expand Up @@ -239,6 +248,11 @@ class VISP_EXPORT vpRBSilhouetteCCDTracker : public vpRBFeatureTracker
m_minMaskConfidence = confidence;
}

void setDisplayType(vpRBSilhouetteCCDDisplayType type)
{
m_displayType = type;
}

/**
* @}
*/
Expand All @@ -258,7 +272,7 @@ class VISP_EXPORT vpRBSilhouetteCCDTracker : public vpRBFeatureTracker
m_cov = m_sigma;
}

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;
void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE;

#if defined(VISP_HAVE_NLOHMANN_JSON)
virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
Expand Down Expand Up @@ -303,6 +317,8 @@ class VISP_EXPORT vpRBSilhouetteCCDTracker : public vpRBFeatureTracker

bool m_useMask;
double m_minMaskConfidence;

vpRBSilhouetteCCDDisplayType m_displayType;
};

END_VISP_NAMESPACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class VISP_EXPORT vpRBSilhouetteMeTracker : public vpRBFeatureTracker

void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration) VP_OVERRIDE;

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;
void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE;

/**
* \name Settings
Expand Down
4 changes: 1 addition & 3 deletions modules/tracker/rbt/include/visp3/rbt/vpRBTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class VISP_EXPORT vpRBTracker
* @{
*/
void displayMask(vpImage<unsigned char> &Imask) const;
void display(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth, const vpRBFeatureDisplayType type);
void display(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth);
/**
* @}
*/
Expand Down Expand Up @@ -272,8 +272,6 @@ class VISP_EXPORT vpRBTracker
std::shared_ptr<vpRBDriftDetector> m_driftDetector;
std::shared_ptr<vpRBVisualOdometry> m_odometry;


// vpRBTrackerFilter m_filter;
};

END_VISP_NAMESPACE
Expand Down
7 changes: 2 additions & 5 deletions modules/tracker/rbt/src/core/vpRBTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ void vpRBTracker::displayMask(vpImage<unsigned char> &Imask) const
}
}

void vpRBTracker::display(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth, const vpRBFeatureDisplayType type)
void vpRBTracker::display(const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth)
{
if (m_currentFrame.renders.normals.getSize() == 0) {
return;
Expand All @@ -564,15 +564,13 @@ void vpRBTracker::display(const vpImage<unsigned char> &I, const vpImage<vpRGBa>

for (std::shared_ptr<vpRBFeatureTracker> &tracker : m_trackers) {
if (tracker->featuresShouldBeDisplayed()) {
tracker->display(m_currentFrame.cam, I, IRGB, depth, type);
tracker->display(m_currentFrame.cam, I, IRGB, depth);
}
}

if (m_driftDetector) {
m_driftDetector->display(IRGB);
}

// vpDisplay::displayRectangle(IRGB, m_renderer.getBoundingBox(), vpColor::red);
}

vpObjectCentricRenderer &vpRBTracker::getRenderer()
Expand All @@ -594,7 +592,6 @@ void vpRBTracker::loadConfigurationFile(const std::string &filename)
catch (nlohmann::json::parse_error &e) {
std::stringstream msg;
msg << "Could not parse JSON file : \n";

msg << e.what() << std::endl;
msg << "Byte position of error: " << e.byte;
throw vpException(vpException::ioError, msg.str());
Expand Down
3 changes: 1 addition & 2 deletions modules/tracker/rbt/src/features/vpRBDenseDepthTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ void vpRBDenseDepthTracker::computeVVSIter(const vpRBFeatureTrackerInput &/*fram
}

void vpRBDenseDepthTracker::display(const vpCameraParameters &/*cam*/, const vpImage<unsigned char> &/*I*/,
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &depth,
const vpRBFeatureDisplayType /*type*/) const
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &depth) const
{
for (unsigned int i = 0; i < m_depthPoints.size(); ++i) {
const vpDepthPoint &p = m_depthPoints[i];
Expand Down
3 changes: 1 addition & 2 deletions modules/tracker/rbt/src/features/vpRBKltTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ void vpRBKltTracker::computeVVSIter(const vpRBFeatureTrackerInput &/*frame*/, co
}

void vpRBKltTracker::display(const vpCameraParameters &cam, const vpImage<unsigned char> &I,
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &/*depth*/,
const vpRBFeatureDisplayType /*type*/) const
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &/*depth*/) const
{
for (const std::pair<const long, vpTrackedKltPoint> &p : m_points) {
double u = 0.0, v = 0.0;
Expand Down
15 changes: 7 additions & 8 deletions modules/tracker/rbt/src/features/vpRBSilhouetteCCDTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ template <class T> class FastVec3

};

vpRBSilhouetteCCDTracker::vpRBSilhouetteCCDTracker() : vpRBFeatureTracker(), m_vvsConvergenceThreshold(0.0), m_temporalSmoothingFac(0.1), m_useMask(false), m_minMaskConfidence(0.0)
vpRBSilhouetteCCDTracker::vpRBSilhouetteCCDTracker() : vpRBFeatureTracker(), m_vvsConvergenceThreshold(0.0), m_temporalSmoothingFac(0.1), m_useMask(false), m_minMaskConfidence(0.0), m_displayType(vpRBSilhouetteCCDDisplayType::SIMPLE)
{ }

void vpRBSilhouetteCCDTracker::extractFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput & /*previousFrame*/, const vpHomogeneousMatrix &/*cMo*/)
Expand Down Expand Up @@ -258,12 +258,11 @@ void vpRBSilhouetteCCDTracker::computeVVSIter(const vpRBFeatureTrackerInput &fra
}

void vpRBSilhouetteCCDTracker::display(const vpCameraParameters &/*cam*/, const vpImage<unsigned char> &/*I*/,
const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &/*depth*/,
const vpRBFeatureDisplayType type) const
const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &/*depth*/) const
{
unsigned normal_points_number = floor(m_ccdParameters.h / m_ccdParameters.delta_h);
unsigned nerror_per_point = 2 * normal_points_number * 3;
if (type == vpRBFeatureDisplayType::SIMPLE) {
if (m_displayType == vpRBSilhouetteCCDDisplayType::SIMPLE) {

for (unsigned int i = 0; i < m_controlPoints.size(); ++i) {
const vpRBSilhouetteControlPoint &p = m_controlPoints[i];
Expand All @@ -274,7 +273,7 @@ void vpRBSilhouetteCCDTracker::display(const vpCameraParameters &/*cam*/, const
// vpDisplay::displayArrow(IRGB, p.icpoint, ip2, p.invnormal ? vpColor::red : vpColor::lightBlue);
}
}
else if (type == vpRBFeatureDisplayType::ERROR) {
else if (m_displayType == vpRBSilhouetteCCDDisplayType::ERROR) {
vpColVector errorPerPoint(m_controlPoints.size());
double maxPointError = 0.0;
for (unsigned int i = 0; i < m_controlPoints.size(); ++i) {
Expand Down Expand Up @@ -305,7 +304,7 @@ void vpRBSilhouetteCCDTracker::display(const vpCameraParameters &/*cam*/, const
++idx;
}
}
else if (type == vpRBFeatureDisplayType::IMPORTANCE) {
else if (m_displayType == vpRBSilhouetteCCDDisplayType::WEIGHT) {
vpColVector weightPerPoint(m_controlPoints.size());
for (unsigned int i = 0; i < m_controlPoints.size(); ++i) {
double sum = 0.0;
Expand Down Expand Up @@ -387,7 +386,7 @@ void vpRBSilhouetteCCDTracker::computeLocalStatistics(const vpImage<vpRGBa> &I,
#if VISP_DEBUG_CCD_TRACKER
if (std::isnan(nv_ptr[0]) || std::isnan(nv_ptr[1])) {
throw vpException(vpException::fatalError, "x: %f, theta = %f", p.xs, p.getTheta());
}
}
#endif

int k = 0;
Expand Down Expand Up @@ -466,7 +465,7 @@ void vpRBSilhouetteCCDTracker::computeLocalStatistics(const vpImage<vpRGBa> &I,
vic_ptr[10 * negative_normal + 9] = exp(-dist2[0] * dist2[0] / (2 * sigma * sigma)) / (sqrt(2 * CV_PI) * sigma);
normalized_param[kk][1] += vic_ptr[10 * negative_normal + 7];
}
}
}

#ifdef VISP_HAVE_OPENMP
#pragma omp parallel for
Expand Down
74 changes: 4 additions & 70 deletions modules/tracker/rbt/src/features/vpRBSilhouetteMeTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,80 +184,14 @@ void vpRBSilhouetteMeTracker::computeVVSIter(const vpRBFeatureTrackerInput &fram
}

void vpRBSilhouetteMeTracker::display(const vpCameraParameters &/*cam*/, const vpImage<unsigned char> &I,
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &/*depth*/,
const vpRBFeatureDisplayType type) const
const vpImage<vpRGBa> &/*IRGB*/, const vpImage<unsigned char> &/*depth*/) const
{

if (type == vpRBFeatureDisplayType::SIMPLE) {
for (const vpRBSilhouetteControlPoint &p: m_controlPoints) {
const vpMeSite &s = p.getSite();
s.display(I);
// vpImagePoint diff(p.nys * m_me.getRange(), p.nxs * m_me.getRange());
// vpImagePoint ip2 = p.icpoint + diff;
// vpDisplay::displayLine(I, p.icpoint, ip2, vpColor::lightBlue, 2);
// vpDisplay::displayPoint(I, p.icpoint, vpColor::red, 2);

}
// vpColor cs[6] = {
// vpColor::red,
// vpColor::blue,
// vpColor::green,
// vpColor::purple,
// vpColor::cyan,
// vpColor::darkGreen

// };
// unsigned colorIndex = 0;
// for (const vpTrackedSilhouetteLine &line: m_lines) {
// if (line.getPoints().size() > 10) {
// for (const vpRBSilhouetteControlPoint *p: line.getPoints()) {
// vpDisplay::displayCross(I, p->getSite().m_i, p->getSite().m_j, 3, cs[colorIndex]);
// }
// colorIndex = (colorIndex + 1) % 6;
// }
// //line.getLine().display(I, cam);
// }
}
else if (type == vpRBFeatureDisplayType::IMPORTANCE) {
const double maxWeight = m_weights.getMaxValue();
unsigned idx = 0;
const vpColor bestColor = vpColor::green;
for (const vpRBSilhouetteControlPoint &p: m_controlPoints) {
const vpMeSite &s = p.getSite();

if (s.getState() == vpMeSite::NO_SUPPRESSION) {
double weight = m_weights[idx] / maxWeight;
vpColor c((unsigned char)((double)(bestColor.R) * weight), (unsigned char)((double)(bestColor.G) * weight), (unsigned char)((double)(bestColor.B) * weight));
vpDisplay::displayCross(I, s.get_i(), s.get_j(), 3, c, 1);
}
else {
s.display(I);
}
++idx;
}
for (const vpRBSilhouetteControlPoint &p: m_controlPoints) {
const vpMeSite &s = p.getSite();
s.display(I);
}
else if (type == vpRBFeatureDisplayType::ERROR) {
unsigned idx = 0;
const vpColor bestColor = vpColor::green;
double maxError = m_error.getMaxValue();

for (const vpRBSilhouetteControlPoint &p: m_controlPoints) {
const vpMeSite &s = p.getSite();

if (s.getState() == vpMeSite::NO_SUPPRESSION) {
double weight = m_error[idx] / maxError;
vpColor c((unsigned char)((double)(bestColor.R) * weight), (unsigned char)((double)(bestColor.G) * weight), (unsigned char)((double)(bestColor.B) * weight));
vpDisplay::displayCross(I, s.get_i(), s.get_j(), 3, c, 1);
}
else {
s.display(I);
}
++idx;
}
}
else {
throw vpException(vpException::notImplementedError, "Display not implemented for unknown type");
}
}

END_VISP_NAMESPACE
2 changes: 1 addition & 1 deletion tutorial/tracking/render-based/tutorial-rbt-realsense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int main(int argc, const char **argv)
vpDisplay::display(IdepthDisplay);
vpDisplay::display(Id);
// vpDisplay::display(Icol);
tracker.display(Id, Icol, IdepthDisplay, vpRBFeatureDisplayType::SIMPLE);
tracker.display(Id, Icol, IdepthDisplay);
vpDisplay::displayFrame(Icol, cMo, cam, 0.05, vpColor::none, 2);
vpDisplay::displayText(Id, 20, 5, "Right click to exit", vpColor::red);
vpMouseButton::vpMouseButtonType button;
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tracking/render-based/tutorial-rbt-sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int main(int argc, const char **argv)
vpDisplay::flush(IProbaDisplay);
vpDisplay::display(Id);
// vpDisplay::display(Icol);
tracker.display(Id, Icol, depthDisplay, vpRBFeatureDisplayType::SIMPLE);
tracker.display(Id, Icol, depthDisplay);
vpDisplay::displayFrame(Icol, cMo, cam, 0.05, vpColor::none, 2);

vpDisplay::flush(Icol);
Expand Down

0 comments on commit 20203be

Please sign in to comment.