|
|
|
@ -74,7 +74,6 @@ int Detect::NewFrame(VideoFrame *newframe) {
|
|
|
|
|
// Thread: newFrame |------> Find Object --- not found ---> send gui information
|
|
|
|
|
void Detect::Thread() {
|
|
|
|
|
DetectOutput output;
|
|
|
|
|
int errorinputtype = -1, x, y;
|
|
|
|
|
|
|
|
|
|
objectX = -1;
|
|
|
|
|
objectY = -1;
|
|
|
|
@ -176,11 +175,6 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
|
int x, y, i, dx, dy, sy;
|
|
|
|
|
unsigned char *pxs, *pxi;
|
|
|
|
|
int idx, didx;
|
|
|
|
|
struct timeval t1, t2;
|
|
|
|
|
float f;
|
|
|
|
|
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
t2 = t1;
|
|
|
|
|
|
|
|
|
|
image.SetSize (objectW, objectH);
|
|
|
|
|
SetInputSize(inFrame.w, inFrame.h);
|
|
|
|
@ -189,10 +183,6 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
|
*posx = 0;
|
|
|
|
|
*posy = 0;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d setup memory time needed:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
#endif
|
|
|
|
|
//
|
|
|
|
|
// maximum brightness
|
|
|
|
|
for (x = 0; x < posmaxx; x++) maxx[x] = 0.0;
|
|
|
|
@ -203,17 +193,8 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
|
maxx[x] += pow(pxs[idx+0] + pxs[idx+1] + pxs[idx+2], POWERVAL);
|
|
|
|
|
maxy[y] += pow(pxs[idx+0] + pxs[idx+1] + pxs[idx+2], POWERVAL);
|
|
|
|
|
}
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d calculated maximum:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
// select maximum
|
|
|
|
|
#endif
|
|
|
|
|
for (x = 1; x < inFrame.w; x++) if (maxx[x] > maxx[*posx]) *posx = x;
|
|
|
|
|
for (y = 1; y < inFrame.h; y++) if (maxy[y] > maxy[*posy]) *posy = y;
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d selected maximum:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// select start corner
|
|
|
|
|
if (*posx < (objectW / 2)) x = 0;
|
|
|
|
@ -228,18 +209,8 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
|
for (dy = 0, y = sy; dy < image.h && y < inFrame.h; y++, dy++) {
|
|
|
|
|
idx = 3* (inFrame.w * y + x);
|
|
|
|
|
didx = 3* (image.w * dy + dx);
|
|
|
|
|
// printf ("[%d , %d] --> [%d, %d] idx: %d --> %d Value:%d\n", x, y, dx, dy, idx, didx, pxs[idx+i]);
|
|
|
|
|
for (i = 0; i < 3; i++) pxi[didx+i] = pxs[idx+i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// printf ("%s:%d %s pos: %d,%d \n", __FILE__, __LINE__, __FUNCTION__, *posx, *posy);
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d copy output:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
f = get_cycletime(&t2);
|
|
|
|
|
printf ("%s:%d time needed:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline float calc_vector(uint8_t a1, uint8_t a2, uint8_t b1, uint8_t b2, uint8_t c1, uint8_t c2, uint8_t d1, uint8_t d2) {
|
|
|
|
@ -254,15 +225,12 @@ inline float calc_vector(uint8_t a1, uint8_t a2, uint8_t b1, uint8_t b2, uint8_t
|
|
|
|
|
|
|
|
|
|
#define OBJSIZE 50
|
|
|
|
|
#define MAXSHIFT 20
|
|
|
|
|
// #define DEBUGTIMES 1
|
|
|
|
|
void Detect::InputDetectCrossC(int *posx, int *posy) {
|
|
|
|
|
unsigned char *pxi; // input image
|
|
|
|
|
unsigned char *pxd; // destination image
|
|
|
|
|
unsigned char *pxo; // old image
|
|
|
|
|
int inx, iny, oldx, oldy;
|
|
|
|
|
|
|
|
|
|
struct timeval t1, t2;
|
|
|
|
|
int shiftx, shifty, x, y, ini, oldi, desti, mxi, mxx, mxy;
|
|
|
|
|
int shiftx, shifty, x, y, ini, oldi, mxi, mxx, mxy;
|
|
|
|
|
float f;
|
|
|
|
|
|
|
|
|
|
if (oldFrame.h != inFrame.h || oldFrame.w != inFrame.w || *posx == -1 || *posy == -1) {
|
|
|
|
@ -271,10 +239,6 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
t2 = t1;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (objectW > inFrame.w || objectH > inFrame.h) {
|
|
|
|
|
printf ("%s:%d %s objectW,H (%d,%d) > inFrame.W,H (%d, %d)\n", __FILE__, __LINE__, __FUNCTION__,
|
|
|
|
@ -288,19 +252,11 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
|
|
|
|
|
SetInputSize(inFrame.w, inFrame.h);
|
|
|
|
|
pxi = inFrame.data;
|
|
|
|
|
pxo = oldFrame.data;
|
|
|
|
|
pxd = image.data;
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d setup memory time needed:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
mxx = mxy = 0;
|
|
|
|
|
for (shifty = 0; shifty < MAXSHIFT; shifty++) {
|
|
|
|
|
// printf ("%s:%d %s shift (%d)\n", __FILE__, __LINE__, __FUNCTION__, shifty);
|
|
|
|
|
mxi = shifty * objectW;
|
|
|
|
|
for (shiftx = 0; shiftx < MAXSHIFT; shiftx++, mxi++) {
|
|
|
|
|
// fixme: help help
|
|
|
|
|
f = 0.0;
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < OBJSIZE; y++) {
|
|
|
|
@ -315,7 +271,6 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
|
|
|
|
|
for (x = 0; x < OBJSIZE; x++, oldi += 3, ini += 3, oldx++, inx++) {
|
|
|
|
|
if (oldx >= 0 && oldy >= 0 && oldx < oldFrame.w && oldy <= oldFrame.h &&
|
|
|
|
|
inx >= 0 && inx < inFrame.w && iny >= 0 && iny < inFrame.h) {
|
|
|
|
|
//f += (float)(pxo[oldi+0])*(float)(pxi[ini+0]);
|
|
|
|
|
f += calc_vector( pxo[oldi+0], pxi[ini+0],
|
|
|
|
|
pxo[oldi+3], pxi[ini+3],
|
|
|
|
|
pxo[oldi+6], pxi[ini+6],
|
|
|
|
@ -332,19 +287,9 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// printf ("%s:%d %s pos (%d,%d) dpos (%d,%d) newpos (%d,%d)\n", __FILE__, __LINE__, __FUNCTION__,
|
|
|
|
|
// *posx, *posy, (mxx-MAXSHIFT/2), (mxy-MAXSHIFT/2), *posx - (mxx-MAXSHIFT/2), *posy - (mxy-MAXSHIFT/2));
|
|
|
|
|
|
|
|
|
|
*posx += (mxx-MAXSHIFT/2);
|
|
|
|
|
*posy += (mxy-MAXSHIFT/2);
|
|
|
|
|
CopyObjectImage (*posx, *posy);
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
|
printf ("%s:%d copy output:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
f = get_cycletime(&t2);
|
|
|
|
|
printf ("%s:%d time needed:%f\n", __FILE__, __LINE__, f);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|