Skip to content

Commit 8d9c56a

Browse files
committed
Fixed indexing issue in python bindings, Silhouette ccd tracker inversion issue protection
1 parent 26469c7 commit 8d9c56a

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

modules/python/bindings/include/core/images.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void define_get_item_2d_image(py::class_<vpImage<T>, std::shared_ptr<vpImage<T>>
5757
{
5858
pyClass.def("__getitem__", [](const vpImage<T> &self, std::pair<int, int> pair) -> T {
5959
int i = pair.first, j = pair.second;
60-
const int rows = (int)self.getHeight(), cols = (int)self.getRows();
60+
const int rows = (int)self.getRows(), cols = (int)self.getCols();
6161
if (i >= rows || j >= cols || i < -rows || j < -cols) {
6262
std::stringstream ss;
6363
ss << "Invalid indexing into a 2D image: got indices " << shape_to_string({ i, j })
@@ -92,6 +92,14 @@ void define_get_item_2d_image(py::class_<vpImage<T>, std::shared_ptr<vpImage<T>>
9292
return (py::cast(self).template cast<np_array_cf<NpRep> >())[tuple].template cast<py::array_t<NpRep>>();
9393
}, py::keep_alive<0, 1>());
9494
}
95+
/*
96+
* Image 2D indexing
97+
*/
98+
template<typename T, typename NpRep>
99+
void define_set_item_2d_image(py::class_<vpImage<T>, std::shared_ptr<vpImage<T>>> &pyClass)
100+
{
101+
102+
}
95103

96104
/*
97105
* vpImage
@@ -121,6 +129,7 @@ Construct an image by **copying** a 2D numpy array.
121129
)doc", py::arg("np_array"));
122130

123131
define_get_item_2d_image<T, T>(pyImage);
132+
define_set_item_2d_image<T, T>(pyImage);
124133

125134
pyImage.def("__repr__", [](const vpImage<T> &self) -> std::string {
126135
std::stringstream ss;

modules/tracker/rbt/src/features/vpRBSilhouetteCCDTracker.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ void vpRBSilhouetteCCDTracker::extractFeatures(const vpRBFeatureTrackerInput &fr
9494
// std::cout << sp.j << ", " << sp.i << std::endl;
9595
int ii = sp.i, jj = sp.j;
9696

97+
if (ii < 4 || jj < 4 || static_cast<unsigned int>(ii) > frame.I.getHeight() - 4 || static_cast<unsigned int>(jj) > frame.I.getWidth() - 4) {
98+
continue;
99+
}
97100
vpRBSilhouetteControlPoint pccd;
98101
pccd.buildSilhouettePoint(ii, jj, sp.Z, sp.orientation, sp.normal, cMo, oMc, frame.cam);
102+
99103
pccd.detectSilhouette(frame.renders.depth);
100104
if (pccd.isSilhouette() && !std::isnan(sp.orientation) && pccd.isValid()) {
101105
m_controlPoints.push_back(std::move(pccd));
@@ -373,7 +377,7 @@ void vpRBSilhouetteCCDTracker::computeLocalStatistics(const vpImage<vpRGBa> &I,
373377
normalized_param[kk][1] += vic_ptr[10 * negative_normal + 7];
374378
}
375379

376-
}
380+
}
377381
#ifdef VISP_HAVE_OPENMP
378382
#pragma omp parallel for
379383
#endif
@@ -489,7 +493,7 @@ void vpRBSilhouetteCCDTracker::computeLocalStatistics(const vpImage<vpRGBa> &I,
489493
}
490494

491495
}
492-
}
496+
}
493497

494498
void vpRBSilhouetteCCDTracker::computeErrorAndInteractionMatrix()
495499
{
@@ -647,10 +651,14 @@ void vpRBSilhouetteCCDTracker::computeErrorAndInteractionMatrix()
647651

648652
m_LTL = m_hessian;
649653
m_LTR = -m_gradient;
650-
651-
vpMatrix hessian_E_inv = m_hessian.inverseByCholesky();
652-
//m_sigma = /*m_sigma +*/ 2*hessian_E_inv;
653-
m_sigma = m_ccdParameters.covarianceIterDecreaseFactor * m_sigma + 2.0 * (1.0 - m_ccdParameters.covarianceIterDecreaseFactor) * hessian_E_inv;
654+
try {
655+
vpMatrix hessian_E_inv = m_hessian.inverseByCholesky();
656+
//m_sigma = /*m_sigma +*/ 2*hessian_E_inv;
657+
m_sigma = m_ccdParameters.covarianceIterDecreaseFactor * m_sigma + 2.0 * (1.0 - m_ccdParameters.covarianceIterDecreaseFactor) * hessian_E_inv;
658+
}
659+
catch (vpException &e) {
660+
std::cerr << "Inversion issues in CCD tracker" << std::endl;
661+
}
654662

655663
}
656664

0 commit comments

Comments
 (0)