41 #include <visp3/tt/vpTemplateTracker.h> 42 #include <visp3/tt/vpTemplateTrackerBSpline.h> 45 : nbLvlPyr(1), l0Pyr(0), pyrInitialised(false), evolRMS(0), x_pos(), y_pos(),
46 evolRMS_eps(1e-4), ptTemplate(NULL), ptTemplatePyr(NULL), ptTemplateInit(false),
47 templateSize(0), templateSizePyr(NULL), ptTemplateSelect(NULL), ptTemplateSelectPyr(NULL),
48 ptTemplateSelectInit(false), templateSelectSize(0), ptTemplateSupp(NULL), ptTemplateSuppPyr(NULL),
49 ptTemplateCompo(NULL), ptTemplateCompoPyr(NULL), zoneTracked(NULL), zoneTrackedPyr(NULL), pyr_IDes(NULL), H(),
50 Hdesire(), HdesirePyr(), HLM(), HLMdesire(), HLMdesirePyr(), HLMdesireInverse(), HLMdesireInversePyr(), G(),
51 gain(1.), thresholdGradient(40), costFunctionVerification(false), blur(true), useBrent(false), nbIterBrent(3),
52 taillef(7), fgG(NULL), fgdG(NULL), ratioPixelIn(0), mod_i(1), mod_j(1), nbParam(0), lambdaDep(0.001),
53 iterationMax(30), iterationGlobale(0), diverge(false), nbIteration(0), useCompositionnal(true), useInverse(false),
54 Warp(_warp), p(0), dp(), X1(), X2(), dW(), BI(), dIx(), dIy(), zoneRef_()
88 unsigned int NbPointDsZone = 0;
93 for (
int i = 0; i < hauteur_im; i += mod_fi) {
94 for (
int j = 0; j < largeur_im; j += mod_fj) {
117 unsigned int cpt_point = 0;
119 for (
int i = 0; i < hauteur_im; i +=
mod_i) {
120 for (
int j = 0; j < largeur_im; j +=
mod_j) {
134 pt.
val = vpTemplateTrackerBSpline::getSubPixBspline4(GaussI, i, j);
165 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
179 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
191 if (ptTemplateSuppPyr) {
192 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
193 if (ptTemplateSuppPyr[i]) {
195 delete[] ptTemplateSuppPyr[i][point].Bt;
196 delete[] ptTemplateSuppPyr[i][point].BtInit;
197 delete[] ptTemplateSuppPyr[i][point].dBt;
198 delete[] ptTemplateSuppPyr[i][point].d2W;
199 delete[] ptTemplateSuppPyr[i][point].d2Wx;
200 delete[] ptTemplateSuppPyr[i][point].d2Wy;
202 delete[] ptTemplateSuppPyr[i];
205 delete[] ptTemplateSuppPyr;
206 ptTemplateSuppPyr = NULL;
210 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 = NULL;
323 zoneWarped.
display(I, col, thickness);
365 zoneWarped.
display(I, col, thickness);
394 adpt = alpha * direction;
401 p2 = tp + alpha * direction;
409 double *Cost =
new double[4];
414 double *talpha =
new double[4];
421 for (
unsigned int opt = 0; opt <
nbIterBrent; opt++) {
423 for (
unsigned int i = 0; i < 3; i++) {
424 A[i][0] = talpha[i] * talpha[i];
429 for (
unsigned int i = 0; i < 3; i++)
432 parabol = (A.
t() * A).inverseByLU() * A.
t() * B;
435 if (parabol[0] > 0) {
436 talpha[3] = -0.5 * parabol[1] / parabol[0];
438 int tindic_x_min = 0;
439 int tindic_x_max = 0;
440 for (
int i = 1; i < 3; i++) {
441 if (talpha[i] < talpha[tindic_x_min])
443 if (talpha[i] > talpha[tindic_x_max])
447 if (Cost[tindic_x_max] < Cost[tindic_x_min]) {
448 talpha[3] = talpha[tindic_x_max] + 1.;
450 talpha[3] = talpha[tindic_x_min] - 1.;
455 for (
int i = 1; i < 3; i++) {
456 if (talpha[i] < talpha[indic_x_min])
458 if (talpha[i] > talpha[indic_x_max])
461 if (talpha[3] > talpha[indic_x_max])
462 if ((talpha[3] - talpha[indic_x_max]) > alpha)
463 talpha[3] = talpha[indic_x_max] + 4.;
464 if (talpha[3] < talpha[indic_x_min])
465 if ((talpha[indic_x_min] - talpha[3]) > alpha)
466 talpha[3] = talpha[indic_x_min] - 4.;
469 adpt = talpha[3] * direction;
476 p3 = tp + talpha[3] * direction;
481 int indice_f_max = 0;
482 for (
int i = 1; i < 4; i++)
483 if (Cost[i] > Cost[indice_f_max])
485 if (indice_f_max != 3) {
486 *ptp[indice_f_max] = *ptp[3];
487 Cost[indice_f_max] = Cost[3];
488 talpha[indice_f_max] = talpha[3];
493 int indice_f_min = 0;
494 for (
int i = 0; i < 4; i++)
495 if (Cost[i] < Cost[indice_f_min])
498 alpha = talpha[indice_f_min];
522 ptTemplateSuppPyr =
new vpTemplateTrackerPointSuppMIInv *[
nbLvlPyr];
524 for (
unsigned int i = 0; i <
nbLvlPyr; i++) {
526 ptTemplateSuppPyr[i] = NULL;
550 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
651 ptTemplateSuppPyr[0] = ptTemplateSupp;
657 ptTemplateSuppPyr[0] = ptTemplateSupp;
668 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
676 ptTemplateSuppPyr[i] = ptTemplateSupp;
682 ptTemplateSuppPyr[i] = ptTemplateSupp;
714 for (
unsigned int i = 1; i <
nbLvlPyr; i++) {
721 for (
int i = (
int)nbLvlPyr - 1; i >= 0; i--) {
722 if (i >= (
int)
l0Pyr) {
726 ptTemplateSupp = ptTemplateSuppPyr[i];
753 p_pre_estimation =
p;
760 if (pre_fcost < post_fcost) {
761 p = p_pre_estimation;
778 Warp->computeCoeff(param);
784 for (
unsigned int j = 0; j < 3; j++) {
787 Warp->computeDenom(
X1, param);
790 unsigned int index = i * 3 + j;
791 double x_ =
x_pos[index] -
X2[0];
792 double y_ =
y_pos[index] - X2[1];
794 x_pos[index] = X2[0];
795 y_pos[index] = X2[1];
810 x_pos.resize(nb_corners);
811 y_pos.resize(nb_corners);
813 Warp->computeCoeff(param);
817 unsigned int i3 = i * 3;
819 for (
unsigned int j = 0; j < 3; j++) {
822 Warp->computeDenom(
X1, param);
static void getGaussPyramidal(const vpImage< unsigned char > &I, vpImage< unsigned char > &GI)
virtual void warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)=0
vpTemplateTrackerZone getPyramidDown() const
bool ptTemplateSelectInit
virtual void getParamInverse(const vpColVector &p, vpColVector &p_inv) const =0
void display(const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
Used to indicate that a value is not in the allowed range.
Implementation of a matrix and operations on matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
virtual void trackPyr(const vpImage< unsigned char > &I)
bool costFunctionVerification
unsigned int templateSelectSize
void getGaussianBluredImage(const vpImage< unsigned char > &I)
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerPoint ** ptTemplatePyr
Class to define RGB colors available for display functionnalities.
unsigned int getNbParam() const
static void getGaussianKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
virtual void initTrackingPyr(const vpImage< unsigned char > &I, vpTemplateTrackerZone &zone)
std::vector< double > y_pos
virtual void getParamPyramidDown(const vpColVector &p, vpColVector &p_down)=0
void computeOptimalBrentGain(const vpImage< unsigned char > &I, vpColVector &tp, double tMI, vpColVector &direction, double &alpha)
error that can be emited by ViSP classes.
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
void initPosEvalRMS(const vpColVector &p)
static void getGradYGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIy, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
const char * getMessage() const
void computeEvalRMS(const vpColVector &p)
vpMatrix * HLMdesireInversePyr
vpTemplateTracker()
Default constructor.
static void getGradXGauss2D(const vpImage< unsigned char > &I, vpImage< double > &dIx, const double *gaussianKernel, const double *gaussianDerivativeKernel, unsigned int size)
void copy(const vpTemplateTrackerZone &z)
unsigned int templateSize
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)
bool inZone(const int &i, const int &j) const
Error that can be emited by the vpTracker class and its derivates.
std::vector< double > x_pos
vpTemplateTrackerZone * zoneTrackedPyr
virtual ~vpTemplateTracker()
virtual void initHessienDesired(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone zoneRef_
void setGaussianFilterSize(unsigned int new_taill)
void initFromZone(const vpImage< unsigned char > &I, const vpTemplateTrackerZone &zone)
virtual double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)=0
virtual void initHessienDesiredPyr(const vpImage< unsigned char > &I)
virtual void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const =0
void initClick(const vpImage< unsigned char > &I, bool delaunay=false)
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
void destroy()
Destructor : Memory de-allocation.
void initFromPoints(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &v_ip, bool delaunay=false)
vpColVector getCorner(unsigned int i) const
unsigned int * templateSizePyr
static void filter(const vpImage< double > &I, vpImage< double > &Iu, vpImage< double > &Iv, const vpMatrix &M, bool convolve=false)
vpMatrix HLMdesireInverse
void resize(unsigned int i, bool flagNullify=true)
virtual void initPyramidal(unsigned int nbLvl, unsigned int l0)
void warpZone(const vpTemplateTrackerZone &in, const vpColVector &p, vpTemplateTrackerZone &out)
static void getGaussianDerivativeKernel(double *filter, unsigned int size, double sigma=0., bool normalize=true)
unsigned int getHeight() const
vpTemplateTrackerPointCompo * ptTemplateCompo
Implementation of column vector and the associated operations.
void track(const vpImage< unsigned char > &I)
virtual void trackNoPyr(const vpImage< unsigned char > &I)=0
vpTemplateTrackerZone * zoneTracked
unsigned int getNbTriangle() const
bool ** ptTemplateSelectPyr
void trackRobust(const vpImage< unsigned char > &I)
vpImage< unsigned char > * pyr_IDes
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
virtual void getParamPyramidUp(const vpColVector &p, vpColVector &p_up)=0
vpTemplateTrackerWarp * Warp
unsigned int getWidth() const
vpTemplateTrackerPointCompo ** ptTemplateCompoPyr