|
|
@ -37,6 +37,8 @@ Detect::Detect() { // @suppress("Class members should be properly initialized")
|
|
|
|
posmaxy = 0;
|
|
|
|
posmaxy = 0;
|
|
|
|
maxx = NULL;
|
|
|
|
maxx = NULL;
|
|
|
|
maxy = NULL;
|
|
|
|
maxy = NULL;
|
|
|
|
|
|
|
|
detmatrix = NULL;
|
|
|
|
|
|
|
|
inputtype = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -66,7 +68,8 @@ int Detect::NewFrame(VideoFrame *newframe) {
|
|
|
|
// Thread: newFrame |------> Find Object --- not found ---> send gui information
|
|
|
|
// Thread: newFrame |------> Find Object --- not found ---> send gui information
|
|
|
|
void Detect::Thread() {
|
|
|
|
void Detect::Thread() {
|
|
|
|
DetectOutput output;
|
|
|
|
DetectOutput output;
|
|
|
|
int posx, posy;
|
|
|
|
int errorinputtype = -1;
|
|
|
|
|
|
|
|
int posx = -1, posy = -1;
|
|
|
|
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
while (running) {
|
|
|
|
// check for new frame
|
|
|
|
// check for new frame
|
|
|
@ -74,9 +77,32 @@ void Detect::Thread() {
|
|
|
|
if (inFrameNew == 1) {
|
|
|
|
if (inFrameNew == 1) {
|
|
|
|
inFrameNew = 0;
|
|
|
|
inFrameNew = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LockMutex(); // lock Config
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// do some input detection improvement
|
|
|
|
// 1. if no position of the object is known, search brightest
|
|
|
|
InputDetect(&posx, &posy);
|
|
|
|
// object on the inFrame image.
|
|
|
|
|
|
|
|
// 2. check near the last known position.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (inputtype) {
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
InputDetect(&posx, &posy);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
if (posx < objectW/2 || posy < objectH/2 ||
|
|
|
|
|
|
|
|
posx > (inFrame.w-objectW/2) || posy > (inFrame.h-objectH/2))
|
|
|
|
|
|
|
|
InputDetect(&posx, &posy);
|
|
|
|
|
|
|
|
else InputDetectCrossC(&posx, &posy);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
if (errorinputtype != inputtype)
|
|
|
|
|
|
|
|
printf ("%s:%d %s error: inputtype (%d) not found\n", __FILE__, __LINE__, __FUNCTION__, inputtype);
|
|
|
|
|
|
|
|
errorinputtype = inputtype;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
oldFrame.CopyFrom(&inFrame);
|
|
|
|
oldFrame.CopyFrom(&inFrame);
|
|
|
|
UnLockInMutex();
|
|
|
|
UnLockInMutex();
|
|
|
|
|
|
|
|
|
|
|
@ -84,6 +110,9 @@ void Detect::Thread() {
|
|
|
|
LockImageMutex();
|
|
|
|
LockImageMutex();
|
|
|
|
imagegtk.CopyFrom(&image);
|
|
|
|
imagegtk.CopyFrom(&image);
|
|
|
|
UnLockImageMutex();
|
|
|
|
UnLockImageMutex();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UnLockMutex(); // unlock Config
|
|
|
|
|
|
|
|
|
|
|
|
output.posx = posx;
|
|
|
|
output.posx = posx;
|
|
|
|
output.posy = posy;
|
|
|
|
output.posy = posy;
|
|
|
|
output.image = &imagegtk;
|
|
|
|
output.image = &imagegtk;
|
|
|
@ -106,6 +135,12 @@ void Detect::SetInputSize (int nw, int nh) {
|
|
|
|
if (maxy != NULL) free (maxy);
|
|
|
|
if (maxy != NULL) free (maxy);
|
|
|
|
maxy = (float*) malloc (nh * sizeof (float));
|
|
|
|
maxy = (float*) malloc (nh * sizeof (float));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((posmaxx * posmaxy) < (nw * nh) || detmatrix != NULL) {
|
|
|
|
|
|
|
|
free (detmatrix);
|
|
|
|
|
|
|
|
detmatrix = (float*) malloc (sizeof(float) * nw * nh);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
posmaxx = nw;
|
|
|
|
posmaxx = nw;
|
|
|
|
posmaxy = nh;
|
|
|
|
posmaxy = nh;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -172,6 +207,111 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
// printf ("[%d , %d] --> [%d, %d] idx: %d --> %d Value:%d\n", x, y, dx, dy, idx, didx, pxs[idx+i]);
|
|
|
|
// 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];
|
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
|
|
float f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (oldFrame.h != inFrame.h || oldFrame.w != inFrame.w || *posx == -1 || *posy == -1) {
|
|
|
|
|
|
|
|
*posx = -1;
|
|
|
|
|
|
|
|
*posy = -1;
|
|
|
|
|
|
|
|
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__,
|
|
|
|
|
|
|
|
objectW, objectH, inFrame.w, inFrame.h);
|
|
|
|
|
|
|
|
*posx = -1;
|
|
|
|
|
|
|
|
*posy = -1;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image.SetSize (objectW, objectH);
|
|
|
|
|
|
|
|
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 < objectH; y++) {
|
|
|
|
|
|
|
|
oldx = (*posx)- objectW/2;
|
|
|
|
|
|
|
|
oldy = (*posy)- objectH/2 + y;
|
|
|
|
|
|
|
|
oldi = 3 * (oldx + oldFrame.w * oldy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inx = oldx + shiftx - MAXSHIFT/2;
|
|
|
|
|
|
|
|
iny = oldy + shifty - MAXSHIFT/2;
|
|
|
|
|
|
|
|
ini = 3* (inx + inFrame.w * iny);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < objectW; 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]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
detmatrix[mxi] = f;
|
|
|
|
|
|
|
|
if (detmatrix[mxx + (mxy * objectW)] < f) {
|
|
|
|
|
|
|
|
mxx = shiftx;
|
|
|
|
|
|
|
|
mxy = shifty;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// copy image data to destination
|
|
|
|
|
|
|
|
for (x = 0; x < objectW; x++) for (y = 0; y < objectH; y++) {
|
|
|
|
|
|
|
|
desti = 3*(x + y * objectW);
|
|
|
|
|
|
|
|
ini = 3*((x + *posx - objectW/2) + (y + *posy - objectH/2) * inFrame.w);
|
|
|
|
|
|
|
|
if (desti < 0 || desti > objectW*objectH*3) continue;
|
|
|
|
|
|
|
|
if (ini < 0 || ini > inFrame.w*inFrame.h*3) continue;
|
|
|
|
|
|
|
|
pxd[desti+0] = pxi[ini+0];
|
|
|
|
|
|
|
|
pxd[desti+1] = pxi[ini+1];
|
|
|
|
|
|
|
|
pxd[desti+2] = pxi[ini+2];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
#ifdef DEBUGTIMES
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
f = get_cycletime(&t1);
|
|
|
|
printf ("%s:%d copy output:%f\n", __FILE__, __LINE__, f);
|
|
|
|
printf ("%s:%d copy output:%f\n", __FILE__, __LINE__, f);
|
|
|
@ -181,6 +321,14 @@ void Detect::InputDetect(int *posx, int *posy) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Detect::SetInputType(int intype) {
|
|
|
|
|
|
|
|
LockMutex();
|
|
|
|
|
|
|
|
inputtype = intype;
|
|
|
|
|
|
|
|
UnLockMutex();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Detect::SetObjectSize(int neww, int newh) {
|
|
|
|
void Detect::SetObjectSize(int neww, int newh) {
|
|
|
|
LockImageMutex();
|
|
|
|
LockImageMutex();
|
|
|
|
LockInMutex();
|
|
|
|
LockInMutex();
|
|
|
@ -195,3 +343,9 @@ void Detect::SetObjectSize(int neww, int newh) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Detect::SetMinBrightness(int value) {
|
|
|
|
|
|
|
|
LockMutex();
|
|
|
|
|
|
|
|
minBright = value;
|
|
|
|
|
|
|
|
UnLockMutex();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|