diff --git a/detect.cc b/detect.cc index f09473a..e04f1bf 100644 --- a/detect.cc +++ b/detect.cc @@ -42,7 +42,6 @@ Detect::Detect() { // @suppress("Class members should be properly initialized") maxx = NULL; maxy = NULL; detmatrix = NULL; - detmatrixv2 = NULL; autodetecttype = 0; autofollowtype = 0; }; @@ -156,10 +155,8 @@ void Detect::SetInputSize (int nw, int nh) { if (detmatrix != NULL) { free (detmatrix); - free (detmatrixv2); } - detmatrix = (float*) malloc (sizeof(float) * nw * nh); - detmatrixv2 = (uint16_t*) malloc (sizeof(uint16_t) * nw * nh); + detmatrix = (uint32_t*) malloc (sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT); objectX = nw/2; objectY = nw/2; @@ -231,14 +228,13 @@ inline uint32_t calc_vector(uint16_t a1, uint16_t a2, uint16_t b1, uint16_t b2, } #define OBJSIZE 52 -#define MAXSHIFT 20 void Detect::InputDetectCrossC(int *posx, int *posy) { unsigned char *pxi; // input image unsigned char *pxo; // old image int inx, iny, oldx, oldy; int shiftx, shifty, x, y, ini, oldi, mxi, mxx, mxy; - float f; + uint32_t sp; if (oldFrame.h != inFrame.h || oldFrame.w != inFrame.w || *posx == -1 || *posy == -1) { *posx = -1; @@ -261,18 +257,18 @@ void Detect::InputDetectCrossC(int *posx, int *posy) { pxo = oldFrame.data; mxx = mxy = 0; - for (shifty = 0; shifty < MAXSHIFT; shifty++) { - mxi = shifty * objectW; - for (shiftx = 0; shiftx < MAXSHIFT; shiftx++, mxi++) { - f = 0.0; + for (shifty = 0; shifty < DET_MAXSHIFT; shifty++) { + mxi = shifty * DET_MAXSHIFT; + for (shiftx = 0; shiftx < DET_MAXSHIFT; shiftx++, mxi++) { + sp = 0; for (y = 0; y < OBJSIZE; y++) { oldx = (*posx)- OBJSIZE/2; oldy = (*posy)- OBJSIZE/2 + y; oldi = 3 * (oldx + oldFrame.w * oldy); - inx = oldx + shiftx - MAXSHIFT/2; - iny = oldy + shifty - MAXSHIFT/2; + inx = oldx + shiftx - DET_MAXSHIFT/2; + iny = oldy + shifty - DET_MAXSHIFT/2; ini = 3* (inx + inFrame.w * iny); for (x = 0; x < OBJSIZE; x++, oldi += 3, ini += 3, oldx++, inx++) { @@ -288,7 +284,7 @@ void Detect::InputDetectCrossC(int *posx, int *posy) { igray[1] = calc_gray( pxi[oldi+3], pxi[ini+4], pxi[ini+5]); igray[2] = calc_gray( pxi[oldi+6], pxi[ini+7], pxi[ini+8]); igray[3] = calc_gray( pxi[oldi+9], pxi[ini+10], pxi[ini+11]); - f += calc_vector( ogray[0], igray[0], + sp += calc_vector( ogray[0], igray[0], ogray[1], igray[1], ogray[2], igray[2], ogray[3], igray[3]); @@ -296,16 +292,16 @@ void Detect::InputDetectCrossC(int *posx, int *posy) { } } } - detmatrix[mxi] = f; - if (detmatrix[mxx + (mxy * objectW)] < f) { + detmatrix[mxi] = sp; + if (detmatrix[mxx + (mxy * DET_MAXSHIFT)] < sp) { mxx = shiftx; mxy = shifty; } } } - *posx += (mxx-MAXSHIFT/2); - *posy += (mxy-MAXSHIFT/2); + *posx += (mxx-DET_MAXSHIFT/2); + *posy += (mxy-DET_MAXSHIFT/2); CopyObjectImage (*posx, *posy); } diff --git a/detect.h b/detect.h index 325784e..2ce8da2 100644 --- a/detect.h +++ b/detect.h @@ -13,6 +13,8 @@ #include "video.h" #include "videoframe.h" +#define DET_MAXSHIFT 20 + enum { AUTODETECT_OFF = 0, AUTODETECT_BRIGHT @@ -27,6 +29,7 @@ enum { struct { VideoFrame *image; // detected image + uint16_t *detmatrix; int posx; // position of the detected object int posy; // position of the detected object } typedef DetectOutput; @@ -50,8 +53,7 @@ private: float *maxy; int posmaxx; int posmaxy; - float *detmatrix; - uint16_t *detmatrixv2; + uint32_t *detmatrix; int objectX; // current object position int objectY; // current object position