31 TrackerPsa::TrackerPsa(
int _max_shift) {
    32         max_shift = _max_shift;
    39 TrackerPsa::~TrackerPsa() {
    40         if (hor) 
delete [] hor;
    41         if (horprev) 
delete [] horprev;
    42         if (ver) 
delete [] ver;
    43         if (verprev) 
delete [] verprev;
    46 double TrackerPsa::Track(IplImage *img) {
    47         long best_x_factor=99999999;
    48         long best_y_factor=99999999;
    49         long worst_x_factor=0;
    50         long worst_y_factor=0;
    55         if ((x_res != img->width) || (y_res != img->height)) {
    58                 if (hor) 
delete [] hor;
    59                 if (horprev) 
delete [] horprev;
    60                 if (ver) 
delete [] ver;
    61                 if (verprev) 
delete [] verprev;
    62                 hor = 
new long [x_res];
    63                 horprev = 
new long [x_res];
    64                 ver = 
new long [y_res];
    65                 verprev = 
new long [y_res];
    71         memset(hor, 0, 
sizeof(
long)*x_res);
    72         memset(ver, 0, 
sizeof(
long)*y_res);
    73         for (
int y=0; 
y<y_res; 
y++) {
    74                 for (
int x=0; 
x<x_res; 
x++) {
    75                         unsigned char c = (
unsigned char)cvGet2D(img, 
y, 
x).val[0];
    82         if (framecount == 1) {
    89                 for (
int s=0; s<max_shift; (s>0 ? 
s=-s : s=-s+1) ) {
    93                         for (
int x=0; 
x<x_res; 
x++) {
    95                                 if ((x2 > 0) && (x2<x_res)) {
    96                                         factor += labs(hor[x2] - horprev[
x]);
   101                         if (factor < best_x_factor) {
   102                                 best_x_factor=factor;
   105                         if (factor > worst_x_factor) worst_x_factor=factor;
   107                 for (
int s=0; s<max_shift; (s>0 ? s=-s : s=-s+1)) {
   110                         for (
int y=0; 
y<y_res; 
y++) {
   112                                 if ((y2 > 0) && (y2<y_res)) {
   113                                         factor += labs(ver[y2] - verprev[
y]);
   118                         if (factor < best_y_factor) {
   119                                 best_y_factor=factor;
   122                         if (factor > worst_y_factor) worst_y_factor=factor;
   127                 int qual_x = (worst_x_factor - best_x_factor)/y_res;
   128                 int qual_y = (worst_y_factor - best_y_factor)/x_res;
   129                 quality = std::min(qual_x, qual_y);
   134         tmp=hor; hor=horprev; horprev=tmp;
   135         tmp=ver; ver=verprev; verprev=tmp;
   144 void TrackerPsa::Compensate(
double *x, 
double *y) {
   148 TrackerPsaRot::TrackerPsaRot(
int _max_shift) : 
TrackerPsa(_max_shift) {
   150         rot=
new double [360];
   162         long best_rot_factor=99999999;
   169                 memset(
rot, 0, 
sizeof(
double)*360);
   173                                 double y2 = 
y-(y_res/2)-(
yd);
   174                                 double x2 = 
x-(x_res/2)-(
xd);
   175                                 double r = sqrt((
double)y2*y2 + x2*x2);
   176                                 int theta = int(atan2((
double)y2, (
double)x2)*180/3.14159265);
   177                                 if (theta < 0) theta+=360;
   178                                 if ((
y >= 0) && (y < img->
height) &&
   179                                         (
x >= 0) && (x < img->
width))
   181                                         rot[theta] += (
unsigned char)cvGet2D(img, 
y, 
x).val[0];
   186                 for (
int i=0; i<360; i++) {
   189                 for (
int s=0; s<45; (s>0 ? 
s=-s : s=-s+1)) {
   191                         for (
int theta=0; theta<360; theta++) {
   192                                 int theta2 = theta+s;
   193                                 if (theta2 < 0) theta2+=360;
   194                                 if (theta2 >= 360) theta2-=360;
   195                                 factor += (long)labs(
long(
rot[theta2] - 
rotprev[theta]));
   197                         if (factor < best_rot_factor) {
   198                                 best_rot_factor=factor;
   204         memset(
rotprev, 0, 
sizeof(
double)*360);
   208                         double y2 = 
y-(y_res/2);
   209                         double x2 = 
x-(x_res/2);
   210                         double r = sqrt((
double)y2*y2 + x2*x2);
   211                         int theta = int(atan2((
double)y2, (
double)x2)*180/3.14159265);
   212                         if (theta < 0) theta+=360;
   213                         if ((
y >= 0) && (y < img->
height) &&
   214                                 (
x >= 0) && (x < img->
width))
   216                                 rotprev[theta] += (
unsigned char)cvGet2D(img, 
y, 
x).val[0];
   221         for (
int i=0; i<360; i++) {
   224         return conf1 + best_rot_factor;
   229         double xx = *x - (
x_res/2);
   230         double yy = *y - (
y_res/2);
   231         double kosini = cos(
rotd*3.1415926535/180);
   232         double sini = sin(
rotd*3.1415926535/180);
   233         *x = ((kosini * xx) - (sini * yy)) + 
xd + (
x_res/2);
   234         *y = ((sini * xx) + (kosini * yy)) + 
yd + (
y_res/2);
 
TrackerPsa implements a very simple PSA tracker 
double yd
Track result y-translation in pixels 
double Track(IplImage *img)
Track using PSA with rotation. 
TFSIMD_FORCE_INLINE const tfScalar & y() const 
double xd
Track result x-translation in pixels 
~TrackerPsaRot()
Destructor. 
This file implements a PSA tracker. 
double rotd
Track result rotation in degrees 
TFSIMD_FORCE_INLINE const tfScalar & x() const 
virtual void Compensate(double *x, double *y)
double Track(IplImage *img)
Track using PSA.