34#include <visp3/tt/vpTemplateTracker.h>
35#include <visp3/tt/vpTemplateTrackerBSpline.h>
47 useInverse(false),
Warp(_warp),
p(0),
dp(),
X1(),
X2(),
dW(),
BI(),
dIx(),
dIy(),
zoneRef_()
78 int largeur_im =
static_cast<int>(I.getWidth());
79 int hauteur_im =
static_cast<int>(I.getHeight());
81 unsigned int NbPointDsZone = 0;
86 for (
int i = 0; i < hauteur_im; i += mod_fi) {
87 for (
int j = 0; j < largeur_im; j += mod_fj) {
109 unsigned int cpt_point = 0;
111 for (
int i = 0; i < hauteur_im; i +=
mod_i) {
112 for (
int j = 0; j < largeur_im; j +=
mod_j) {
127 pt.
val = vpTemplateTrackerBSpline::getSubPixBspline4(GaussI, i, j);
158 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
172 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
184 if (ptTemplateSuppPyr) {
185 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
186 if (ptTemplateSuppPyr[i]) {
188 delete[] ptTemplateSuppPyr[i][point].Bt;
189 delete[] ptTemplateSuppPyr[i][point].BtInit;
190 delete[] ptTemplateSuppPyr[i][point].dBt;
191 delete[] ptTemplateSuppPyr[i][point].d2W;
192 delete[] ptTemplateSuppPyr[i][point].d2Wx;
193 delete[] ptTemplateSuppPyr[i][point].d2Wy;
195 delete[] ptTemplateSuppPyr[i];
198 delete[] ptTemplateSuppPyr;
199 ptTemplateSuppPyr =
nullptr;
203 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
243 for (
unsigned int point = 0; point <
templateSize; point++) {
252 for (
unsigned int point = 0; point <
templateSize; point++) {
258 if (ptTemplateSupp) {
259 for (
unsigned int point = 0; point <
templateSize; point++) {
260 delete[] ptTemplateSupp[point].Bt;
261 delete[] ptTemplateSupp[point].BtInit;
262 delete[] ptTemplateSupp[point].dBt;
263 delete[] ptTemplateSupp[point].d2W;
264 delete[] ptTemplateSupp[point].d2Wx;
265 delete[] ptTemplateSupp[point].d2Wy;
267 delete[] ptTemplateSupp;
268 ptTemplateSupp =
nullptr;
321 zoneWarped.
display(I, col, thickness);
367 zoneWarped.
display(I, col, thickness);
386 Warp->getParamInverse(direction, dpt);
389 Warp->pRondp(tp, dpt, p1);
397 adpt = alpha * direction;
399 Warp->getParamInverse(adpt, dpt);
402 Warp->pRondp(tp, dpt, p2);
405 p2 = tp + alpha * direction;
413 double *Cost =
new double[4];
418 double *talpha =
new double[4];
425 for (
unsigned int opt = 0; opt <
nbIterBrent; opt++) {
427 for (
unsigned int i = 0; i < 3; i++) {
428 A[i][0] = talpha[i] * talpha[i];
433 for (
unsigned int i = 0; i < 3; i++)
436 parabol = (A.
t() * A).inverseByLU() * A.
t() * B;
439 if (parabol[0] > 0) {
440 talpha[3] = -0.5 * parabol[1] / parabol[0];
443 int tindic_x_min = 0;
444 int tindic_x_max = 0;
445 for (
int i = 1; i < 3; i++) {
446 if (talpha[i] < talpha[tindic_x_min])
448 if (talpha[i] > talpha[tindic_x_max])
452 if (Cost[tindic_x_max] < Cost[tindic_x_min]) {
453 talpha[3] = talpha[tindic_x_max] + 1.;
456 talpha[3] = talpha[tindic_x_min] - 1.;
461 for (
int i = 1; i < 3; i++) {
462 if (talpha[i] < talpha[indic_x_min])
464 if (talpha[i] > talpha[indic_x_max])
467 if (talpha[3] > talpha[indic_x_max])
468 if ((talpha[3] - talpha[indic_x_max]) > alpha)
469 talpha[3] = talpha[indic_x_max] + 4.;
470 if (talpha[3] < talpha[indic_x_min])
471 if ((talpha[indic_x_min] - talpha[3]) > alpha)
472 talpha[3] = talpha[indic_x_min] - 4.;
475 adpt = talpha[3] * direction;
477 Warp->getParamInverse(adpt, dpt);
480 Warp->pRondp(tp, dpt, p3);
483 p3 = tp + talpha[3] * direction;
488 int indice_f_max = 0;
489 for (
int i = 1; i < 4; i++)
490 if (Cost[i] > Cost[indice_f_max])
492 if (indice_f_max != 3) {
493 *ptp[indice_f_max] = *ptp[3];
494 Cost[indice_f_max] = Cost[3];
495 talpha[indice_f_max] = talpha[3];
501 int indice_f_min = 0;
502 for (
int i = 0; i < 4; i++)
503 if (Cost[i] < Cost[indice_f_min])
506 alpha = talpha[indice_f_min];
530 ptTemplateSuppPyr =
new vpTemplateTrackerPointSuppMIInv *[
nbLvlPyr];
532 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
534 ptTemplateSuppPyr[i] =
nullptr;
558 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
621 zoneRef_.initFromPoints(I, v_ip, delaunay);
662 ptTemplateSuppPyr[0] = ptTemplateSupp;
669 ptTemplateSuppPyr[0] = ptTemplateSupp;
680 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
688 ptTemplateSuppPyr[i] = ptTemplateSupp;
695 ptTemplateSuppPyr[i] = ptTemplateSupp;
727 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
729 Warp->getParamPyramidDown(
p, ptemp);
734 for (
int i =
static_cast<int>(
nbLvlPyr) - 1; i >= 0; i--) {
735 if (i >=
static_cast<int>(
l0Pyr)) {
739 ptTemplateSupp = ptTemplateSuppPyr[i];
747 Warp->getParamPyramidUp(
p, ptemp);
768 p_pre_estimation =
p;
775 if (pre_fcost < post_fcost) {
776 p = p_pre_estimation;
792 unsigned int nb_corners =
zoneTracked->getNbTriangle() * 3;
794 Warp->computeCoeff(param);
798 for (
unsigned int i = 0; i <
zoneTracked->getNbTriangle(); i++) {
800 for (
unsigned int j = 0; j < 3; j++) {
803 Warp->computeDenom(
X1, param);
806 unsigned int index = i * 3 + j;
807 double x_ =
x_pos[index] -
X2[0];
808 double y_ =
y_pos[index] -
X2[1];
825 unsigned int nb_corners =
zoneTracked->getNbTriangle() * 3;
826 x_pos.resize(nb_corners);
827 y_pos.resize(nb_corners);
829 Warp->computeCoeff(param);
832 for (
unsigned int i = 0; i <
zoneTracked->getNbTriangle(); i++) {
833 unsigned int i3 = i * 3;
835 for (
unsigned int j = 0; j < 3; j++) {
838 Warp->computeDenom(
X1, param);
Implementation of column vector and the associated operations.
Class to define RGB colors available for display functionalities.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
static void getGradXGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIx, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
static void getGaussianDerivativeKernel(FilterType *filter, unsigned int size, FilterType sigma=0., bool normalize=true)
static void filter(const vpImage< ImageType > &I, vpImage< FilterType > &If, const vpArray2D< FilterType > &M, bool convolve=false, const vpImage< bool > *p_mask=nullptr)
static void getGaussianKernel(FilterType *filter, unsigned int size, FilterType sigma=0., bool normalize=true)
static void getGradYGauss2D(const vpImage< ImageType > &I, vpImage< FilterType > &dIy, const FilterType *gaussianKernel, const FilterType *gaussianDerivativeKernel, unsigned int size, const vpImage< bool > *p_mask=nullptr)
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
Definition of the vpImage class member functions.
void destroy()
Destructor : Memory de-allocation.
Implementation of a matrix and operations on matrices.
vpColVector getCorner(unsigned int i) const
bool inZone(const int &i, const int &j) const
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
void initTracking(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
vpTemplateTracker()
Default constructor.
vpMatrix HLMdesireInverse
unsigned int templateSelectSize
virtual void initHessienDesiredPyr(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint ** ptTemplatePyr
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false)
void computeEvalRMS(const vpColVector &p)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
unsigned int * templateSizePyr
void initFromZone(const vpImage< unsigned char > &I, const vpTemplateTrackerZone &zone)
vpTemplateTrackerZone * zoneTrackedPyr
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
vpTemplateTrackerZone zoneRef_
bool ** ptTemplateSelectPyr
vpImage< unsigned char > * pyr_IDes
std::vector< double > y_pos
vpMatrix * HLMdesireInversePyr
std::vector< double > x_pos
unsigned int iterationMax
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0
void track(const vpImage< unsigned char > &I)
bool costFunctionVerification
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr
virtual void trackPyr(const vpImage< unsigned char > &I)
void getGaussianBluredImage(const vpImage< unsigned char > &I)
void initPosEvalRMS(const vpColVector &p)
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
virtual ~vpTemplateTracker()
vpTemplateTrackerPoint * ptTemplate
virtual void initTrackingPyr(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
virtual void initPyramidal(unsigned int nbLvl, unsigned int l0)
void setGaussianFilterSize(unsigned int new_taill)
vpTemplateTrackerWarp * Warp
unsigned int iterationGlobale
bool ptTemplateSelectInit
void trackRobust(const vpImage< unsigned char > &I)
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
unsigned int templateSize
vpTemplateTrackerPointCompo * ptTemplateCompo
vpTemplateTrackerZone * zoneTracked
Error that can be emitted by the vpTracker class and its derivatives.