13 mean(uint8_t *dat, int n)
16 for( int i=0; i<n; ++i, ++dat ) s += *dat;
21 variance(uint8_t *dat, double m, int n)
24 for( int i=0; i<n; ++i, ++dat ) {
28 return (ss - s*s / n) / (n-1);
32 std_dev(uint8_t *dat, double m, int n)
34 return sqrt(variance(dat,m,n));
38 center(uint8_t *dat, int n, int stride)
41 for( int i=0; i<n; dat+=stride ) { s += *dat; ss += ++i * *dat; }
42 return s > 0 ? (double)ss / s : n / 2.;
46 centroid(uint8_t *dat, int w, int h, double *xx, double *yy)
50 for( int i=h; --i>=0; dp+=w ) x += center(dp, w, 1);
51 for( int i=w; --i>=0; ) y += center(dat+i, h, w);
52 *xx = x / h; *yy = y / w;
56 int main(int ac, char **av)
58 int ret; setbuf(stdout,0);
61 //db.access(av[1], 34543, 0);
62 if( !db.opened() || db.error() ) exit(1);
64 FILE *fp = fopen(av[2],"r");
65 for( int i=3; --i>=0; ) {
66 for( int ch=fgetc(fp); ch>=0 && ch!='\n'; ch=fgetc(fp) );
69 int w = SWIDTH, h = SHEIGHT, sfrm_sz = w * h;
71 fread(dat,1,sfrm_sz,fp);
73 double mn = mean(dat,sfrm_sz);
74 double sd = std_dev(dat,mn,sfrm_sz);
75 double cx, cy; centroid(dat, w, h, &cx, &cy);
76 double moment = cx + cy;
77 if( (ret = Video_frameLoc::ikey_Frame_weight(db.video_frame, mn).Locate()) != 0 ) {
78 printf(" not found, ret = %d\n",ret);
81 printf(" id %d, mean %f-%f=%f, std_dev %f-%f=%f, "
82 " cx %f-%f=%f, cy %f-%f=%f, moment %f-%f=%f\n", db.video_frame.id(),
83 mn, db.video_frame.Frame_mean(), mn-db.video_frame.Frame_mean(),
84 sd, db.video_frame.Frame_std_dev(), sd-db.video_frame.Frame_std_dev(),
85 cx, db.video_frame.Frame_cx(), cx-db.video_frame.Frame_cx(),
86 cy, db.video_frame.Frame_cy(), cy-db.video_frame.Frame_cy(),
87 moment, db.video_frame.Frame_moment(), moment-db.video_frame.Frame_moment());
88 if( (ret = Video_frameLoc::ikey_Frame_center(db.video_frame, moment).Locate()) != 0 ) {
89 printf(" not found, ret = %d\n",ret);
92 printf(" id %d, mean %f-%f=%f, std_dev %f-%f=%f, "
93 " cx %f-%f=%f, cy %f-%f=%f, moment %f-%f=%f\n", db.video_frame.id(),
94 mn, db.video_frame.Frame_mean(), mn-db.video_frame.Frame_mean(),
95 sd, db.video_frame.Frame_std_dev(), sd-db.video_frame.Frame_std_dev(),
96 cx, db.video_frame.Frame_cx(), cx-db.video_frame.Frame_cx(),
97 cy, db.video_frame.Frame_cy(), cy-db.video_frame.Frame_cy(),
98 moment, db.video_frame.Frame_moment(), moment-db.video_frame.Frame_moment());