c++ - iris to screen calculation for eye tracking -
i'm experimenting eye tracking i've built iris tracking algorithm using opencv contours , hough transform. next step unclear me. want know if calculations i'm doing correct translating center of eye screen. head of user has fixed position.
what want algorithm works on eyes off course. there angle calculation? when user looking more right, linear?
what right is: first let user @ specific points , use ransac detect iris position that's closest position on screen. 4 2d points on screen , iris. i'm using homography correct calculation.
void gaussian_elimination(float *input, int n){ // ported c pseudocode in // http://en.wikipedia.org/wiki/gaussian_elimination float * = input; int = 0; int j = 0; int m = n-1; while (i < m && j < n){ // find pivot in column j, starting in row i: int maxi = i; for(int k = i+1; k<m; k++){ if(fabs(a[k*n+j]) > fabs(a[maxi*n+j])){ maxi = k; } } if (a[maxi*n+j] != 0){ //swap rows , maxi, not change value of if(i!=maxi) for(int k=0;k<n;k++){ float aux = a[i*n+k]; a[i*n+k]=a[maxi*n+k]; a[maxi*n+k]=aux; } //now a[i,j] contain old value of a[maxi,j]. //divide each entry in row a[i,j] float a_ij=a[i*n+j]; for(int k=0;k<n;k++){ a[i*n+k]/=a_ij; } //now a[i,j] have value 1. for(int u = i+1; u< m; u++){ //subtract a[u,j] * row row u float a_uj = a[u*n+j]; for(int k=0;k<n;k++){ a[u*n+k]-=a_uj*a[i*n+k]; } //now a[u,j] 0, since a[u,j] - a[i,j] * a[u,j] = a[u,j] - 1 * a[u,j] = 0. } i++; } j++; } //back substitution for(int i=m-2;i>=0;i--){ for(int j=i+1;j<n-1;j++){ a[i*n+m]-=a[i*n+j]*a[j*n+m]; //a[i*n+j]=0; } } } ofmatrix4x4 findhomography(ofpoint src[4], ofpoint dst[4]){ ofmatrix4x4 matrix; // create equation system solved // // from: multiple view geometry in computer vision 2ed // hartley r. , zisserman a. // // x' = xh // h homography: 3 3 matrix // transformed inhomogeneous coordinates each point // gives following equations each point: // // x' * (h31*x + h32*y + h33) = h11*x + h12*y + h13 // y' * (h31*x + h32*y + h33) = h21*x + h22*y + h23 // // homography scale independent can let h33 1 (indeed of terms) // 4 points have 8 equations 8 terms solve: h11 - h32 // after ordering terms gives following matrix // can solved gaussian elimination: float p[8][9]={ {-src[0].x, -src[0].y, -1, 0, 0, 0, src[0].x*dst[0].x, src[0].y*dst[0].x, -dst[0].x }, // h11 { 0, 0, 0, -src[0].x, -src[0].y, -1, src[0].x*dst[0].y, src[0].y*dst[0].y, -dst[0].y }, // h12 {-src[1].x, -src[1].y, -1, 0, 0, 0, src[1].x*dst[1].x, src[1].y*dst[1].x, -dst[1].x }, // h13 { 0, 0, 0, -src[1].x, -src[1].y, -1, src[1].x*dst[1].y, src[1].y*dst[1].y, -dst[1].y }, // h21 {-src[2].x, -src[2].y, -1, 0, 0, 0, src[2].x*dst[2].x, src[2].y*dst[2].x, -dst[2].x }, // h22 { 0, 0, 0, -src[2].x, -src[2].y, -1, src[2].x*dst[2].y, src[2].y*dst[2].y, -dst[2].y }, // h23 {-src[3].x, -src[3].y, -1, 0, 0, 0, src[3].x*dst[3].x, src[3].y*dst[3].x, -dst[3].x }, // h31 { 0, 0, 0, -src[3].x, -src[3].y, -1, src[3].x*dst[3].y, src[3].y*dst[3].y, -dst[3].y }, // h32 }; gaussian_elimination(&p[0][0],9); matrix(0,0)=p[0][8]; matrix(0,1)=p[1][8]; matrix(0,2)=0; matrix(0,3)=p[2][8]; matrix(1,0)=p[3][8]; matrix(1,1)=p[4][8]; matrix(1,2)=0; matrix(1,3)=p[5][8]; matrix(2,0)=0; matrix(2,1)=0; matrix(2,2)=0; matrix(2,3)=0; matrix(3,0)=p[6][8]; matrix(3,1)=p[7][8]; matrix(3,2)=0; matrix(3,3)=1; return matrix;
}
you should have @ existing solutions this:
- eye writer painting eyes (i tested control mouse only)
- eyelike pupil tracking
eyelike info page (algorithm similar want want discussed here)
good luck!
Comments
Post a Comment