change sum of products from float to int, no float needed

test16bit
Steffen Pohle 4 years ago
parent a7d696384a
commit aad9e0b6ef

@ -42,7 +42,6 @@ Detect::Detect() { // @suppress("Class members should be properly initialized")
maxx = NULL; maxx = NULL;
maxy = NULL; maxy = NULL;
detmatrix = NULL; detmatrix = NULL;
detmatrixv2 = NULL;
autodetecttype = 0; autodetecttype = 0;
autofollowtype = 0; autofollowtype = 0;
}; };
@ -156,10 +155,8 @@ void Detect::SetInputSize (int nw, int nh) {
if (detmatrix != NULL) { if (detmatrix != NULL) {
free (detmatrix); free (detmatrix);
free (detmatrixv2);
} }
detmatrix = (float*) malloc (sizeof(float) * nw * nh); detmatrix = (uint32_t*) malloc (sizeof(uint32_t) * DET_MAXSHIFT * DET_MAXSHIFT);
detmatrixv2 = (uint16_t*) malloc (sizeof(uint16_t) * nw * nh);
objectX = nw/2; objectX = nw/2;
objectY = 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 OBJSIZE 52
#define MAXSHIFT 20
void Detect::InputDetectCrossC(int *posx, int *posy) { void Detect::InputDetectCrossC(int *posx, int *posy) {
unsigned char *pxi; // input image unsigned char *pxi; // input image
unsigned char *pxo; // old image unsigned char *pxo; // old image
int inx, iny, oldx, oldy; int inx, iny, oldx, oldy;
int shiftx, shifty, x, y, ini, oldi, mxi, mxx, mxy; 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) { if (oldFrame.h != inFrame.h || oldFrame.w != inFrame.w || *posx == -1 || *posy == -1) {
*posx = -1; *posx = -1;
@ -261,18 +257,18 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
pxo = oldFrame.data; pxo = oldFrame.data;
mxx = mxy = 0; mxx = mxy = 0;
for (shifty = 0; shifty < MAXSHIFT; shifty++) { for (shifty = 0; shifty < DET_MAXSHIFT; shifty++) {
mxi = shifty * objectW; mxi = shifty * DET_MAXSHIFT;
for (shiftx = 0; shiftx < MAXSHIFT; shiftx++, mxi++) { for (shiftx = 0; shiftx < DET_MAXSHIFT; shiftx++, mxi++) {
f = 0.0; sp = 0;
for (y = 0; y < OBJSIZE; y++) { for (y = 0; y < OBJSIZE; y++) {
oldx = (*posx)- OBJSIZE/2; oldx = (*posx)- OBJSIZE/2;
oldy = (*posy)- OBJSIZE/2 + y; oldy = (*posy)- OBJSIZE/2 + y;
oldi = 3 * (oldx + oldFrame.w * oldy); oldi = 3 * (oldx + oldFrame.w * oldy);
inx = oldx + shiftx - MAXSHIFT/2; inx = oldx + shiftx - DET_MAXSHIFT/2;
iny = oldy + shifty - MAXSHIFT/2; iny = oldy + shifty - DET_MAXSHIFT/2;
ini = 3* (inx + inFrame.w * iny); ini = 3* (inx + inFrame.w * iny);
for (x = 0; x < OBJSIZE; x++, oldi += 3, ini += 3, oldx++, inx++) { 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[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[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]); 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[1], igray[1],
ogray[2], igray[2], ogray[2], igray[2],
ogray[3], igray[3]); ogray[3], igray[3]);
@ -296,16 +292,16 @@ void Detect::InputDetectCrossC(int *posx, int *posy) {
} }
} }
} }
detmatrix[mxi] = f; detmatrix[mxi] = sp;
if (detmatrix[mxx + (mxy * objectW)] < f) { if (detmatrix[mxx + (mxy * DET_MAXSHIFT)] < sp) {
mxx = shiftx; mxx = shiftx;
mxy = shifty; mxy = shifty;
} }
} }
} }
*posx += (mxx-MAXSHIFT/2); *posx += (mxx-DET_MAXSHIFT/2);
*posy += (mxy-MAXSHIFT/2); *posy += (mxy-DET_MAXSHIFT/2);
CopyObjectImage (*posx, *posy); CopyObjectImage (*posx, *posy);
} }

@ -13,6 +13,8 @@
#include "video.h" #include "video.h"
#include "videoframe.h" #include "videoframe.h"
#define DET_MAXSHIFT 20
enum { enum {
AUTODETECT_OFF = 0, AUTODETECT_OFF = 0,
AUTODETECT_BRIGHT AUTODETECT_BRIGHT
@ -27,6 +29,7 @@ enum {
struct { struct {
VideoFrame *image; // detected image VideoFrame *image; // detected image
uint16_t *detmatrix;
int posx; // position of the detected object int posx; // position of the detected object
int posy; // position of the detected object int posy; // position of the detected object
} typedef DetectOutput; } typedef DetectOutput;
@ -50,8 +53,7 @@ private:
float *maxy; float *maxy;
int posmaxx; int posmaxx;
int posmaxy; int posmaxy;
float *detmatrix; uint32_t *detmatrix;
uint16_t *detmatrixv2;
int objectX; // current object position int objectX; // current object position
int objectY; // current object position int objectY; // current object position

Loading…
Cancel
Save