40 #include <visp3/tt/vpTemplateTracker.h>
41 #include <visp3/tt/vpTemplateTrackerBSpline.h>
45 : nbLvlPyr(1), l0Pyr(0), pyrInitialised(false), evolRMS(0), x_pos(), y_pos(), evolRMS_eps(1e-4), ptTemplate(nullptr),
46 ptTemplatePyr(nullptr), ptTemplateInit(false), templateSize(0), templateSizePyr(nullptr), ptTemplateSelect(nullptr),
47 ptTemplateSelectPyr(nullptr), ptTemplateSelectInit(false), templateSelectSize(0), ptTemplateSupp(nullptr),
48 ptTemplateSuppPyr(nullptr), ptTemplateCompo(nullptr), ptTemplateCompoPyr(nullptr), zoneTracked(nullptr), zoneTrackedPyr(nullptr),
49 pyr_IDes(nullptr), H(), Hdesire(), HdesirePyr(), HLM(), HLMdesire(), HLMdesirePyr(), HLMdesireInverse(),
50 HLMdesireInversePyr(), G(), gain(1.), thresholdGradient(40), costFunctionVerification(false), blur(true),
51 useBrent(false), nbIterBrent(3), taillef(7), fgG(nullptr), fgdG(nullptr), ratioPixelIn(0), mod_i(1), mod_j(1), nbParam(0),
52 lambdaDep(0.001), iterationMax(30), iterationGlobale(0), diverge(false), nbIteration(0), useCompositionnal(true),
53 useInverse(false), Warp(_warp), p(0), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(), zoneRef_()
87 unsigned int NbPointDsZone = 0;
92 for (
int i = 0; i < hauteur_im; i += mod_fi) {
93 for (
int j = 0; j < largeur_im; j += mod_fj) {
115 unsigned int cpt_point = 0;
117 for (
int i = 0; i < hauteur_im; i +=
mod_i) {
118 for (
int j = 0; j < largeur_im; j +=
mod_j) {
133 pt.
val = vpTemplateTrackerBSpline::getSubPixBspline4(GaussI, i, j);
164 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
178 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
190 if (ptTemplateSuppPyr) {
191 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
192 if (ptTemplateSuppPyr[i]) {
194 delete[] ptTemplateSuppPyr[i][point].Bt;
195 delete[] ptTemplateSuppPyr[i][point].BtInit;
196 delete[] ptTemplateSuppPyr[i][point].dBt;
197 delete[] ptTemplateSuppPyr[i][point].d2W;
198 delete[] ptTemplateSuppPyr[i][point].d2Wx;
199 delete[] ptTemplateSuppPyr[i][point].d2Wy;
201 delete[] ptTemplateSuppPyr[i];
204 delete[] ptTemplateSuppPyr;
205 ptTemplateSuppPyr =
nullptr;
209 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
249 for (
unsigned int point = 0; point <
templateSize; point++) {
258 for (
unsigned int point = 0; point <
templateSize; point++) {
264 if (ptTemplateSupp) {
265 for (
unsigned int point = 0; point <
templateSize; point++) {
266 delete[] ptTemplateSupp[point].Bt;
267 delete[] ptTemplateSupp[point].BtInit;
268 delete[] ptTemplateSupp[point].dBt;
269 delete[] ptTemplateSupp[point].d2W;
270 delete[] ptTemplateSupp[point].d2Wx;
271 delete[] ptTemplateSupp[point].d2Wy;
273 delete[] ptTemplateSupp;
274 ptTemplateSupp =
nullptr;
327 zoneWarped.
display(I, col, thickness);
373 zoneWarped.
display(I, col, thickness);
403 adpt = alpha * direction;
411 p2 = tp + alpha * direction;
419 double *Cost =
new double[4];
424 double *talpha =
new double[4];
431 for (
unsigned int opt = 0; opt <
nbIterBrent; opt++) {
433 for (
unsigned int i = 0; i < 3; i++) {
434 A[i][0] = talpha[i] * talpha[i];
439 for (
unsigned int i = 0; i < 3; i++)
442 parabol = (A.
t() * A).inverseByLU() * A.
t() * B;
445 if (parabol[0] > 0) {
446 talpha[3] = -0.5 * parabol[1] / parabol[0];
449 int tindic_x_min = 0;
450 int tindic_x_max = 0;
451 for (
int i = 1; i < 3; i++) {
452 if (talpha[i] < talpha[tindic_x_min])
454 if (talpha[i] > talpha[tindic_x_max])
458 if (Cost[tindic_x_max] < Cost[tindic_x_min]) {
459 talpha[3] = talpha[tindic_x_max] + 1.;
462 talpha[3] = talpha[tindic_x_min] - 1.;
467 for (
int i = 1; i < 3; i++) {
468 if (talpha[i] < talpha[indic_x_min])
470 if (talpha[i] > talpha[indic_x_max])
473 if (talpha[3] > talpha[indic_x_max])
474 if ((talpha[3] - talpha[indic_x_max]) > alpha)
475 talpha[3] = talpha[indic_x_max] + 4.;
476 if (talpha[3] < talpha[indic_x_min])
477 if ((talpha[indic_x_min] - talpha[3]) > alpha)
478 talpha[3] = talpha[indic_x_min] - 4.;
481 adpt = talpha[3] * direction;
489 p3 = tp + talpha[3] * direction;
494 int indice_f_max = 0;
495 for (
int i = 1; i < 4; i++)
496 if (Cost[i] > Cost[indice_f_max])
498 if (indice_f_max != 3) {
499 *ptp[indice_f_max] = *ptp[3];
500 Cost[indice_f_max] = Cost[3];
501 talpha[indice_f_max] = talpha[3];
507 int indice_f_min = 0;
508 for (
int i = 0; i < 4; i++)
509 if (Cost[i] < Cost[indice_f_min])
512 alpha = talpha[indice_f_min];
536 ptTemplateSuppPyr =
new vpTemplateTrackerPointSuppMIInv *[
nbLvlPyr];
538 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
540 ptTemplateSuppPyr[i] =
nullptr;
564 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
668 ptTemplateSuppPyr[0] = ptTemplateSupp;
675 ptTemplateSuppPyr[0] = ptTemplateSupp;
686 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
694 ptTemplateSuppPyr[i] = ptTemplateSupp;
701 ptTemplateSuppPyr[i] = ptTemplateSupp;
733 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
740 for (
int i = (
int)
nbLvlPyr - 1; i >= 0; i--) {
741 if (i >= (
int)
l0Pyr) {
745 ptTemplateSupp = ptTemplateSuppPyr[i];
774 p_pre_estimation =
p;
781 if (pre_fcost < post_fcost) {
782 p = p_pre_estimation;
800 Warp->computeCoeff(param);
806 for (
unsigned int j = 0; j < 3; j++) {
809 Warp->computeDenom(
X1, param);
812 unsigned int index = i * 3 + j;
813 double x_ =
x_pos[index] -
X2[0];
814 double y_ =
y_pos[index] -
X2[1];
832 x_pos.resize(nb_corners);
833 y_pos.resize(nb_corners);
835 Warp->computeCoeff(param);
839 unsigned int i3 = i * 3;
841 for (
unsigned int j = 0; j < 3; j++) {
844 Warp->computeDenom(
X1, param);
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
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.
const char * getMessage() const
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)
void destroy()
Destructor : Memory de-allocation.
unsigned int getWidth() const
unsigned int getHeight() const
Implementation of a matrix and operations on matrices.
vpColVector getCorner(unsigned int i) const
virtual void getParamPyramidUp(const vpColVector &p, vpColVector &p_up)=0
unsigned int getNbParam() const
virtual void getParamInverse(const vpColVector &p, vpColVector &p_inv) const =0
void warpZone(const vpTemplateTrackerZone &in, const vpColVector &p, vpTemplateTrackerZone &out)
virtual void warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)=0
virtual void getParamPyramidDown(const vpColVector &p, vpColVector &p_down)=0
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const =0
vpTemplateTrackerZone getPyramidDown() const
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
bool inZone(const int &i, const int &j) const
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
unsigned int getNbTriangle() const
void copy(const vpTemplateTrackerZone &z)
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
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
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
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.