Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "TrackerStat.h"
00025
00026 using namespace std;
00027
00028 namespace alvar {
00029 using namespace std;
00030
00031 TrackerStat::TrackerStat(int binsize) : f(100,90) {
00032 hist.AddDimension(binsize);
00033 hist.AddDimension(binsize);
00034 }
00035
00036 void TrackerStat::Reset() {
00037 f.Reset();
00038 }
00039
00040 double TrackerStat::Track(IplImage *img)
00041 {
00042 if (img == NULL) return -1;
00043 f.Track(img);
00044 hist.Clear();
00045 for (int p=0; p<f.prev_feature_count ; p++) {
00046 for (int c=0; c<f.feature_count; c++) {
00047 if (f.prev_ids[p] != f.ids[c]) continue;
00048 float x = f.features[c].x - f.prev_features[p].x;
00049 float y = f.features[c].y - f.prev_features[p].y;
00050 hist.Inc(x, y);
00051 }
00052 }
00053 xd = 0; yd = 0;
00054 return hist.GetMax(&xd, &yd);
00055 }
00056
00057 void TrackerStat::Compensate(double *x, double *y) {
00058 *x += xd; *y += yd;
00059 }
00060
00061 TrackerStatRot::TrackerStatRot(int binsize , int binsize_rot) : TrackerStat(binsize) {
00062 hist_rot.AddDimension(binsize_rot);
00063 }
00064
00065 double TrackerStatRot::Track(IplImage *img)
00066 {
00067 if (img == NULL) return -1;
00068 f.Track(img);
00069
00070 hist.Clear();
00071 for (int p=0; p<f.prev_feature_count ; p++) {
00072 for (int c=0; c<f.feature_count; c++) {
00073 if (f.prev_ids[p] != f.ids[c]) continue;
00074 float x = f.features[c].x - f.prev_features[p].x;
00075 float y = f.features[c].y - f.prev_features[p].y;
00076 hist.Inc(x, y);
00077 }
00078 }
00079 xd = 0; yd = 0;
00080 double ret = hist.GetMax(&xd, &yd);
00081
00082 x_res = img->width;
00083 y_res = img->height;
00084 hist_rot.Clear();
00085 for (int p=0; p<f.prev_feature_count ; p++) {
00086 for (int c=0; c<f.feature_count; c++) {
00087 if (f.prev_ids[p] != f.ids[c]) continue;
00088 double x_pred = f.prev_features[p].x + xd;
00089 double y_pred = f.prev_features[p].y + yd;
00090 double x_curr = f.features[c].x;
00091 double y_curr = f.features[c].y;
00092 double x = x_curr - x_pred;
00093 double y = y_curr - y_pred;
00094 double theta_pred = atan2((double)y_pred-(y_res/2), (double)x_pred-(x_res/2))*180.0/3.1415926535;
00095 double theta_curr = atan2((double)y_curr-(y_res/2), (double)x_curr-(x_res/2))*180.0/3.1415926535;
00096 hist_rot.Inc(theta_curr-theta_pred);
00097 }
00098 }
00099 rotd=0;
00100 hist_rot.GetMax(&rotd);
00101 return ret;
00102 }
00103
00104 void TrackerStatRot::Compensate(double *x, double *y)
00105 {
00106 double xx = *x - (x_res/2);
00107 double yy = *y - (y_res/2);
00108 double kosini = cos(rotd*3.1415926535/180);
00109 double sini = sin(rotd*3.1415926535/180);
00110 *x = ((kosini * xx) - (sini * yy)) + xd + (x_res/2);
00111 *y = ((sini * xx) + (kosini * yy)) + yd + (y_res/2);
00112 }
00113
00114 }