#ifdef _CH_
#pragma package <opencv>
#endif
#ifndef _EiC
#include "cv.h"
#include "cvcam.h"
#include "highgui.h"
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#endif
IplImage *image = 0, *hsv = 0, *hue = 0, *mask = 0, *backproject = 0, *histimg = 0, *plot = 0, *display = 0, *clone = 0;
CvHistogram *hist = 0;
int backproject_mode = 0;
int select_object = 0;
int track_object = 0;
int show_hist = 1;
const int eye_origin = 160;
// Width of boxex across eye
int col5_left = 0;
int col5_right = 0;
int col4_left = 0; //310;
int col4_right = 0; //325;
int col3_left = 0; //330;
int col3_right = 0; //345;
int col2_left = 0; //355;
int col2_right = 0; //370;
int col1_left = 0; //375;
int col1_right = 0; //390;
// Height of boxes across eye
int row1_upper = 0; //262; //317
int row1_lower = 0; //254; //279
int row2_upper = 0; //254; //269
int row2_lower = 0; //246; //231
int row3_upper = 0; //246; //221
int row3_lower = 0; //238; //183
int row4_upper = 0;
int row4_lower = 0;
//Display numbers
int display_col1 = 10;
int display_col2 = 110;
int display_col3 = 210;
int display_col4 = 310;
int display_col5 = 410;
int display_row1 = 120;
int display_row2 = 240;
int display_row3 = 360;
int display_row4 = 480;
//Display boxes
int box_width = 80;
int box_height = 110;
int box_gapX = 20;
int box_gapY = 10;
//Camera-to-screen ratio
float ratio = 0.118; //camera to eye dist = 6cm, screen to eye dist = 51cm, ratio = 6/51
float scale_width = 0, scale_height = 0, scale_gapX = 0, scale_gapY = 0;
int refresh = 0;
int calibrate = 1;
int EyeCenter_pre = 0;
float scalingX = 1.32; //1.32 for 19", 1 for 15"
float scalingY = 1.13;// 1.13 for 19"
// Data writing
float f;
FILE * pFile;
clock_t delay, time1, time2, time3, time4, timediff_from3, timediff_from2, timediff_from1, track_time;
clock_t time5, time6, time7, time8, time9, time10, time11, time12, time13, START;
clock_t last_time1,last_time2,last_time3,last_time4,last_time5,last_time6,last_time7,last_time8,last_time9,last_time10,last_time11,last_time12,last_time13;
int blank1=1,blank2=1,blank3=1,blank4=1,blank5=1,blank6=1,blank7=1,blank8=1,blank9=1,blank10=1,blank11=1,blank12=1,blank13=1;
float frequency1=2,frequency2=4,frequency3=2,frequency4=8,frequency5=3,frequency6=2,frequency7=9,frequency8=2,frequency9=11,frequency10=4,frequency11=7,frequency12=3,frequency13=1;
time_t rawtime;
clock_t run_start,run_stop;
int running_time=0;
struct tm * timeinfo;
int new_num = 0, pre_num = 0;
const int eye_threshold = 2;
// get capture parameters.
int width, height, fps;
// create video writer for the output.
CvVideoWriter* writer = NULL;
int isColor = 1;
int fps = 5; // or 30
int frameW = 640; // 744 for firewire cameras
int frameH = 480; // 480 for firewire cameras
CvPoint plot_pos;
CvPoint origin;
CvRect selection;
CvRect track_window;
CvBox2D track_box;
CvConnectedComp track_comp;
CvFont font, font1;
CvPoint NewEyeCenter;
CvPoint EllipseCenter;
CvPoint Center;
CvPoint EyeCenter;
int hdims = 16;
float hranges_arr[] = {0,180};
float* hranges = hranges_arr;
int vmin = 200, vmax = 0, smin = 84;
void on_mouse( int event, int x, int y, int flags, void* param )
{
if( !image )
return;
if( image->origin )
y = image->height - y;
if( select_object )
{
//EllipseCenter = cvPoint(selection.width/2, selection.height/2);//
selection.x = MIN(x,origin.x);
selection.y = MIN(y,origin.y);
selection.width = selection.x + CV_IABS(x - origin.x);
selection.height = selection.y + CV_IABS(y - origin.y);
selection.x = MAX( selection.x, 0 );
selection.y = MAX( selection.y, 0 );
selection.width = MIN( selection.width, image->width );
selection.height = MIN( selection.height, image->height );
selection.width -= selection.x;
selection.height -= selection.y;
// Print coordinates //
/*printf("Width equals %d\n", selection.width);
printf("Height equals %d\n", selection.height);*/
EllipseCenter = cvPoint(selection.x, selection.y);
printf("Pointer location x equals %d\n", EllipseCenter.x);
printf("Pointer location y equals %d\n", EllipseCenter.y);
Center = cvPoint((selection.width + selection.x)/2, (selection.height + selection.y)/2);
/*printf("Center of selected rectangle x equals %d\n", Center.x);
printf("Center of selected rectangle y equals %d\n", Center.y);*/
printf("Default eye origin is at x co-oridinate %d\n", eye_origin);
calibrate = 1;
}
switch( event )
{
case CV_EVENT_LBUTTONDOWN:
origin = cvPoint(x,y);
selection = cvRect(x,y,0,0);
select_object = 1;
break;
case CV_EVENT_LBUTTONUP:
select_object = 0;
if( selection.width > 0 && selection.height > 0 )
track_object = -1;
break;
}
}
CvScalar hsv2rgb( float hue )
{
int rgb[3], p, sector;
static const int sector_data[][3]=
{{0,2,1}, {1,2,0}, {1,0,2}, {2,0,1}, {2,1,0}, {0,1,2}};
hue *= 0.033333333333333333333333333333333f;
sector = cvFloor(hue);
p = cvRound(255*(hue - sector));
p ^= sector & 1 ? 255 : 0;
rgb[sector_data[sector][0]] = 255;
rgb[sector_data[sector][1]] = 0;
rgb[sector_data[sector][2]] = p;
return cvScalar(rgb[2], rgb[1], rgb[0],0);
}
int main( int argc, char** argv )
{
CvCapture* capture = 0;
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
else if( argc == 2 )
capture = cvCaptureFromAVI( argv[1] );
if( !capture )
{
fprintf(stderr,"Could not initialize capturing...\n");
return -1;
}
printf( "Hot keys: \n"
"\tESC - quit the program\n"
"\ts - stop the tracking\n"
"\tb - switch to/from backprojection view\n"
"\t1 - to track 1 grid\n"
"\t2 - to track 2 grid\n"
"\t4 - to track 4 grid\n"
"\tt - to track 12 grid\n"
"To initialize tracking, select the object with mouse\n" );
//cvNamedWindow( "Histogram", 1 );//
// Tracking window //
cvNamedWindow( "Test_proj", 0 );
cvResizeWindow( "Test_proj", 300, 300);
/*cvCreateTrackbar( "Vmin", "Test_proj", &vmin, 256, 0 );
cvCreateTrackbar( "Vmax", "Test_proj", &vmax, 256, 0 );
cvCreateTrackbar( "Smin", "Test_proj", &smin, 256, 0 );*/
// Object display window //
display = cvCreateImage( cvSize(500, 500), 8, 3); // size 500 = 0 to 499
cvNamedWindow ("Display", 0);
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 4.0, 4.0, 0, 0.5, CV_AA); // Width and Heigth are in cm
cvInitFont(&font1, CV_FONT_HERSHEY_COMPLEX, 8.0, 8.0, 0, 8, CV_AA);
cvRectangle( display, cvPoint(0, 0), cvPoint(500,500), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
// Draw numbers and boxes in Display window
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "1", cvPoint(10,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 2 //
cvPutText(display, "2", cvPoint(110,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 3 //
cvPutText(display, "3", cvPoint(210,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 4 //
cvPutText(display, "4", cvPoint(310,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 5 //
cvPutText(display, "5", cvPoint(10,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 6 //
cvPutText(display, "6", cvPoint(110,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 7 //
cvPutText(display, "7", cvPoint(210,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 8 //
cvPutText(display, "8", cvPoint(310,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num A //
cvPutText(display, "A", cvPoint(10,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 10 //
cvPutText(display, "9", cvPoint(110,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 11 //
cvPutText(display, "0", cvPoint(210,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num B //
cvPutText(display, "B", cvPoint(310,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num S //
cvPutText(display, "S", cvPoint(410,480), &font, CV_RGB(0, 255, 0));
scale_width = (ratio * box_width) * scalingX;
scale_gapX = (ratio * box_gapX) * scalingX;
scale_height = (ratio * box_height) * scalingY;
scale_gapY = (ratio * box_gapY) * scalingY;
// Eye tracked image //
plot = cvCreateImage( cvSize(500,500), 8, 3 );
plot_pos = cvPoint(100,350);
//cvNamedWindow( "Projection", 0 );
//cvResizeWindow( "Projection", 100, 100);
cvSetMouseCallback( "Test_proj", on_mouse, 0 );
// Writing data
pFile = fopen ("EyeTrack Result_Time.txt","a+"); // Create file
// Print end time and date
time ( &rawtime );
timeinfo = localtime ( &rawtime );
fprintf (pFile, "\n\nThe eye tracking start date/time is: %s\n\n", asctime (timeinfo) );
//writer = cvCreateVideoWriter("Demo_recording_J2.avi",-1,fps,cvSize(frameW,frameH), isColor);
for(;;)
{
IplImage* frame = 0;
int i, bin_w, c, row, col, ch;
run_start=clock();
frame = cvQueryFrame( capture );
if( select_object && selection.width > 0 && selection.height > 0 )
{
cvSetImageROI( image, selection );
cvXorS( image, cvScalarAll(255), image, 0 );
cvResetImageROI( image );
}
if( !frame )
break;
if( !image )
{
/* allocate all the buffers */
image = cvCreateImage( cvGetSize(frame), 8, 3 );
image->origin = frame->origin;
hsv = cvCreateImage( cvGetSize(frame), 8, 3 );
hue = cvCreateImage( cvGetSize(frame), 8, 1 );
mask = cvCreateImage( cvGetSize(frame), 8, 1 );
backproject = cvCreateImage( cvGetSize(frame), 8, 1 );
hist = cvCreateHist( 1, &hdims, CV_HIST_ARRAY, &hranges, 1 );
histimg = cvCreateImage( cvSize(320,200), 8, 3 );
cvZero( histimg );
}
cvCopy( frame, image, 0);
cvCvtColor( image, hsv, CV_BGR2HSV );
if( track_object )
{
int _vmin = vmin, _vmax = vmax;
cvInRangeS( hsv, cvScalar(0,smin,MIN(_vmin,_vmax),0),
cvScalar(180,256,MAX(_vmin,_vmax),0), mask );
cvSplit( hsv, hue, 0, 0, 0 );
if( track_object < 0 )
{
float max_val = 0.f;
cvSetImageROI( hue, selection );
cvSetImageROI( mask, selection );
cvCalcHist( &hue, hist, 0, mask );
cvGetMinMaxHistValue( hist, 0, &max_val, 0, 0 );
cvConvertScale( hist->bins, hist->bins, max_val ? 255. / max_val : 0., 0 );
cvResetImageROI( hue );
cvResetImageROI( mask );
track_window = selection;
track_object = 1;
cvZero( histimg );
bin_w = histimg->width / hdims;
for( i = 0; i < hdims; i++ )
{
int val = cvRound( cvGetReal1D(hist->bins,i)*histimg->height/255 );
CvScalar color = hsv2rgb(i*180.f/hdims);
cvRectangle( histimg, cvPoint(i*bin_w,histimg->height),
cvPoint((i+1)*bin_w,histimg->height - val),
color, -1, 8, 0 );
}
}
cvCalcBackProject( &hue, backproject, hist );
cvAnd( backproject, mask, backproject, 0 );
cvCamShift( backproject, track_window,
cvTermCriteria( CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1 ),
&track_comp, &track_box );
track_window = track_comp.rect;
if( backproject_mode )
cvCvtColor( backproject, image, CV_GRAY2BGR );
if( image->origin )
track_box.angle = -track_box.angle;
cvEllipseBox( image, track_box, CV_RGB(255,0,0), 0.5, CV_AA, 0 ); // change the 0.5 to 15 to get thick ellipse//
// Locate center of eye //
EyeCenter = cvPoint(track_box.center.x, track_box.center.y);
if(calibrate == 1) // Always start the eye at center of grid
{
delay = clock();
NewEyeCenter = cvPoint(EyeCenter.x, EyeCenter.y);
while((clock() - delay) < 0.2 * CLOCKS_PER_SEC) //This delay is for the ellipse the 'settle' before accuqiring the coordinates
{
col3_right = EyeCenter.x + (0.5 * scale_width); // Width = 0.5 x 9.4
col3_left = EyeCenter.x - (0.5 * scale_width); // Width = 0.5 x 9.4
col4_right = col3_left - scale_gapX; // Gap = 6cm/ 51cm x 20units = 2.35
col4_left = col4_right - scale_width; // Width = 9.4
col5_right = col4_left - scale_gapX; // Gap = 10
col5_left = col5_right - scale_width; // S: Width = 6cm/ 51cm x 80units = 9.4units
col2_left = col3_right + scale_gapX; // Gap = 10
col2_right = col2_left + scale_width; // Width = 9.4
col1_left = col2_right + scale_gapX; // Gap = 10
col1_right = col1_left + scale_width; // Width = 9.4
row2_lower = EyeCenter.y + (0.5 * scale_gapY); // Gap = 0.5 x 2.35
row2_upper = row2_lower + scale_height; // Height = 12.94
row3_upper = EyeCenter.y - (0.5 * scale_gapY); // Gap = 0.5 x 2.35
row3_lower = row3_upper - scale_height; // Height = 12.94
row1_lower = row2_upper + scale_gapY; // Gap = 6cm/ 51cm x 20units = 2.35
row1_upper = row1_lower + scale_height; // Height = 12.94
row4_upper = row3_lower - scale_gapY; // Gap = 2.35
row4_lower = row4_upper - scale_height; // S: Height = 6cm/ 51cm x 110units = 12.94units
}
calibrate = calibrate + 1;
// cvSaveImage("test.jpg", image); // Can save file as bmp, jpg
}
//Track Path
cvLine(display, cvPoint( NewEyeCenter.x, NewEyeCenter.y), cvPoint( EyeCenter.x, EyeCenter.y), CV_RGB(255,200,0), 1, CV_AA, 0);
NewEyeCenter = cvPoint(EyeCenter.x, EyeCenter.y);
/* // Draw row 1 boxes across eye //
cvRectangle( image, cvPoint(col1_left, row1_lower), cvPoint(col1_right, row1_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 1 //
cvRectangle( image, cvPoint(col2_left, row1_lower), cvPoint(col2_right, row1_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 2 //
cvRectangle( image, cvPoint(col3_left, row1_lower), cvPoint(col3_right, row1_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 3 //
cvRectangle( image, cvPoint(col4_left, row1_lower), cvPoint(col4_right, row1_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
//cvRectangle( image, cvPoint(col5_left, row1_lower), cvPoint(col5_right, row1_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
// Draw row 2 boxes across eye //
cvRectangle( image, cvPoint(col1_left, row2_lower), cvPoint(col1_right, row2_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 1 //
cvRectangle( image, cvPoint(col2_left, row2_lower), cvPoint(col2_right, row2_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 2 //
cvRectangle( image, cvPoint(col3_left, row2_lower), cvPoint(col3_right, row2_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 3 //
cvRectangle( image, cvPoint(col4_left, row2_lower), cvPoint(col4_right, row2_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
//cvRectangle( image, cvPoint(col5_left, row2_lower), cvPoint(col5_right, row2_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
// Draw row 3 boxes across eye //
cvRectangle( image, cvPoint(col1_left, row3_lower), cvPoint(col1_right, row3_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 1 //
cvRectangle( image, cvPoint(col2_left, row3_lower), cvPoint(col2_right, row3_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 2 //
cvRectangle( image, cvPoint(col3_left, row3_lower), cvPoint(col3_right, row3_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 3 //
cvRectangle( image, cvPoint(col4_left, row3_lower), cvPoint(col4_right, row3_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
//cvRectangle( image, cvPoint(col5_left, row3_lower), cvPoint(col5_right, row3_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
// Draw row 4 boxes across eye //
//cvRectangle( image, cvPoint(col1_left, row4_lower), cvPoint(col1_right, row4_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 1 //
//cvRectangle( image, cvPoint(col2_left, row4_lower), cvPoint(col2_right, row4_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 2 //
//cvRectangle( image, cvPoint(col3_left, row4_lower), cvPoint(col3_right, row4_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 3 //
//cvRectangle( image, cvPoint(col4_left, row4_lower), cvPoint(col4_right, row4_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
cvRectangle( image, cvPoint(col5_left, row4_lower), cvPoint(col5_right, row4_upper), CV_RGB(0, 0, 255),1, 8, 0 ); // Box 4 //
//cvZero(display);
*/if(EyeCenter_pre!=EyeCenter.x){
cvRectangle( display, cvPoint(0, 0), cvPoint(500,500), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
// Draw numbers and boxes in Display window
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "1", cvPoint(10,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 2 //
cvPutText(display, "2", cvPoint(110,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 3 //
cvPutText(display, "3", cvPoint(210,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 4 //
cvPutText(display, "4", cvPoint(310,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 5 //
cvPutText(display, "5", cvPoint(10,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 6 //
cvPutText(display, "6", cvPoint(110,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 7 //
cvPutText(display, "7", cvPoint(210,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 8 //
cvPutText(display, "8", cvPoint(310,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num A //
cvPutText(display, "A", cvPoint(10,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 10 //
cvPutText(display, "9", cvPoint(110,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 11 //
cvPutText(display, "0", cvPoint(210,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num B //
cvPutText(display, "B", cvPoint(310,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num S //
cvPutText(display, "S", cvPoint(410,480), &font, CV_RGB(0, 255, 0));
}
if((EyeCenter.x >= col1_left) && (EyeCenter.x <= col1_right) && (EyeCenter.y >= row1_lower) && (EyeCenter.y <=row1_upper))
{
time1 = clock ();
new_num = 1;
if(new_num != pre_num)// If they are not equal,
{
pre_num = new_num;
track_time = time1;
}
if ((clock()-last_time1)>=0.5/frequency1*CLOCKS_PER_SEC)
{
if (blank1==1){
blank1=0;
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
last_time1=clock();}
else if (blank1==0){
blank1=1;
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "1", cvPoint(10,120), &font, CV_RGB(0, 255, 0));
last_time1=clock();}}/*else
{
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "1", cvPoint(10,120), &font, CV_RGB(0, 255, 0));
}*/
if ((time1 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 1!!\n");
fprintf(pFile, "At pos one %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 1 at %lu ms\n\n", time1); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "1", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
//timediff_from1 = time1 - time4;
//fprintf (pFile, "Eye time diffence from one to four %lu msec\n", timediff_from1);
//timediff_from2 = time1 - time2;
//fprintf (pFile, "Eye time diffence from two to four %lu msec\n", timediff_from2);
//timediff_from3 = time1 - time3;
//fprintf (pFile, "Eye time diffence from three to four %lu msec\n", timediff_from3);
//cvSaveImage("Projection.jpg", plot);
} else if ((EyeCenter.x >= col2_left) && (EyeCenter.x <= col2_right) && (EyeCenter.y >= row1_lower) && (EyeCenter.y <=row1_upper))
{
time2 = clock ();
new_num = 2;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time2;
}
if ((clock()-last_time2)>=0.5/frequency2*CLOCKS_PER_SEC)
{
if (blank2==1){
blank2=0;
cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 2 //
last_time2=clock();}
else if (blank2==0){
blank2=1;
cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 2 //
cvPutText(display, "2", cvPoint(110,120), &font, CV_RGB(0, 255, 0));
last_time2=clock();}}/*else
{ cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 2 //
cvPutText(display, "2", cvPoint(110,120), &font, CV_RGB(0, 255, 0));
}*/
if ((time2 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 2!!\n");
fprintf(pFile, "At pos two %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 2 at %lu ms\n\n", time2); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "2", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col3_left) && (EyeCenter.x <= col3_right) && (EyeCenter.y >= row1_lower) && (EyeCenter.y <=row1_upper))
{
time3 = clock ();
new_num = 3;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time3;
}
if ((clock()-last_time3)>=0.5/frequency3*CLOCKS_PER_SEC)
{
if (blank3==1){
blank3=0;
cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 3 //
last_time3=clock();}
else if (blank3==0){
blank3=1;
cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 3 //
cvPutText(display, "3", cvPoint(210,120), &font, CV_RGB(0, 255, 0));
last_time3=clock();}}/*else
{ cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 3 //
cvPutText(display, "3", cvPoint(210,120), &font, CV_RGB(0, 255, 0));
}*/
if ((time3 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 3!!\n");
fprintf(pFile, "At pos three %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 3 at %lu ms\n\n", time3); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "3", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col4_left) && (EyeCenter.x <= col4_right) && (EyeCenter.y >= row1_lower) && (EyeCenter.y <=row1_upper))
{
time4 = clock ();
new_num = 4;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time4;
}
if ((clock()-last_time4)>=0.5/frequency4*CLOCKS_PER_SEC)
{
if (blank4==1){
blank4=0;
cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 4 //
last_time4=clock();}
else if (blank4==0){
blank4=1;
cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 4 //
cvPutText(display, "4", cvPoint(310,120), &font, CV_RGB(0, 255, 0));
last_time4=clock();}}/*else
{ cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 4 //
cvPutText(display, "4", cvPoint(310,120), &font, CV_RGB(0, 255, 0));
}*/
if ((time4 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 4!!\n");
fprintf(pFile, "At pos four %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 4 at %lu ms\n\n", time4); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "4", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if((EyeCenter.x >= col1_left) && (EyeCenter.x <= col1_right) && (EyeCenter.y >= row2_lower) && (EyeCenter.y <=row2_upper))
{
time5 = clock ();
new_num = 5;
if(new_num != pre_num)// If they are not equal,
{
pre_num = new_num;
track_time = time5;
}
if ((clock()-last_time5)>=0.5/frequency5*CLOCKS_PER_SEC)
{
if (blank5==1){
blank5=0;
cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 5 //
last_time5=clock();}
else if (blank5==0){
blank5=1;
cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 5 //
cvPutText(display, "5", cvPoint(10,240), &font, CV_RGB(0, 255, 0));
last_time5=clock();}}/*else
{ cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 5 //
cvPutText(display, "5", cvPoint(10,240), &font, CV_RGB(0, 255, 0));
}*/
if ((time5 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 5!!\n");
fprintf(pFile, "At pos five %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 5 at %lu ms\n\n", time5); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "5", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col2_left) && (EyeCenter.x <= col2_right) && (EyeCenter.y >= row2_lower) && (EyeCenter.y <=row2_upper))
{
time6 = clock ();
new_num = 6;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time6;
}
if ((clock()-last_time6)>=0.5/frequency6*CLOCKS_PER_SEC)
{
if (blank6==1){
blank6=0;
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 6 //
last_time6=clock();}
else if (blank6==0){
blank6=1;
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 6 //
cvPutText(display, "6", cvPoint(110,240), &font, CV_RGB(0, 255, 0));
last_time6=clock();}}
/*else {
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 6 //
cvPutText(display, "6", cvPoint(110,240), &font, CV_RGB(0, 255, 0));
}*/
if ((time6 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 6!!\n");
fprintf(pFile, "At pos six %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 6 at %lu ms\n\n", time6); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "6", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col3_left) && (EyeCenter.x <= col3_right) && (EyeCenter.y >= row2_lower) && (EyeCenter.y <=row2_upper))
{
time7 = clock ();
new_num = 7;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time7;
}
if ((clock()-last_time7)>=0.5/frequency7*CLOCKS_PER_SEC)
{
//printf("*\t%d\n",blank6);
if (blank7==1){
blank7=0;
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
last_time7=clock();}
else if (blank7==0){
blank7=1;
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 7 //
cvPutText(display, "7", cvPoint(210,240), &font, CV_RGB(0, 255, 0));
last_time7=clock();}
} /*else{
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 7 //
cvPutText(display, "7", cvPoint(210,240), &font, CV_RGB(0, 255, 0));
}*/
if ((time7 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{//refresh=1;
printf("Confirm target at 7!!\n");
fprintf(pFile, "At pos seven %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 7 at %lu ms\n\n", time7); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "7", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col4_left) && (EyeCenter.x <= col4_right) && (EyeCenter.y >= row2_lower) && (EyeCenter.y <=row2_upper))
{
time8 = clock ();
new_num = 8;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time8;
}
if ((clock()-last_time8)>=0.5/frequency8*CLOCKS_PER_SEC)
{
if (blank8==1){
blank8=0;
cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
last_time8=clock();}
else if (blank8==0){
blank8=1;
cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 8 //
cvPutText(display, "8", cvPoint(310,240), &font, CV_RGB(0, 255, 0));
last_time8=clock();}}/*else
{ cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 8 //
cvPutText(display, "8", cvPoint(310,240), &font, CV_RGB(0, 255, 0));
}*/
if ((time8 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 8!!\n");
fprintf(pFile, "At pos eight %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 8 at %lu ms\n\n", time8); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "8", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if((EyeCenter.x >= col1_left) && (EyeCenter.x <= col1_right) && (EyeCenter.y >= row3_lower) && (EyeCenter.y <=row3_upper))
{
time9 = clock ();
new_num = 9;
if(new_num != pre_num)// If they are not equal,
{
pre_num = new_num;
track_time = time9;
}
if ((clock()-last_time9)>=0.5/frequency9*CLOCKS_PER_SEC)
{
if (blank9==1){
blank9=0;
cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
last_time9=clock();}
else if (blank9==0){
blank9=1;
cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "A", cvPoint(10,360), &font, CV_RGB(0, 255, 0));
last_time9=clock();}}/*else
{ cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "A", cvPoint(10,360), &font, CV_RGB(0, 255, 0));
}*/
if ((time9 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at A!!\n");
fprintf(pFile, "At pos A %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position A at %lu ms\n\n", time9); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "A", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col2_left) && (EyeCenter.x <= col2_right) && (EyeCenter.y >= row3_lower) && (EyeCenter.y <=row3_upper))
{
time10 = clock ();
new_num = 10;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time10;
}
if ((clock()-last_time10)>=0.5/frequency10*CLOCKS_PER_SEC)
{
if (blank10==1){
blank10=0;
cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 10 //
last_time10=clock();}
else if (blank10==0){
blank10=1;
cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 10 //
cvPutText(display, "9", cvPoint(110,360), &font, CV_RGB(0, 255, 0));
last_time10=clock();}}/*else
{ cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 10 //
cvPutText(display, "9", cvPoint(110,360), &font, CV_RGB(0, 255, 0));
}*/
if ((time10 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 9!!\n");
fprintf(pFile, "At pos nine %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 9 at %lu ms\n\n", time10); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "9", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col3_left) && (EyeCenter.x <= col3_right) && (EyeCenter.y >= row3_lower) && (EyeCenter.y <=row3_upper))
{
time11 = clock ();
new_num = 11;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time11;
}
if ((clock()-last_time11)>=0.5/frequency11*CLOCKS_PER_SEC)
{
if (blank11==1){
blank11=0;
cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 11 //
last_time11=clock();}
else if (blank11==0){
blank11=1;
cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 11 //
cvPutText(display, "0", cvPoint(210,360), &font, CV_RGB(0, 255, 0));
last_time11=clock();}}/* else
{ cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 11 //
cvPutText(display, "0", cvPoint(210,360), &font, CV_RGB(0, 255, 0));
}*/
if ((time11 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at 0!!\n");
fprintf(pFile, "At pos zero %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position 0 at %lu ms\n\n", time11); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "0", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col4_left) && (EyeCenter.x <= col4_right) && (EyeCenter.y >= row3_lower) && (EyeCenter.y <=row3_upper))
{
time12 = clock ();
new_num = 12;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time12;
}
if ((clock()-last_time12)>=0.5/frequency12*CLOCKS_PER_SEC)
{
if (blank12==1){
blank12=0;
cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num B //
last_time12=clock();}
else if (blank12==0){
blank12=1;
cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num B //
cvPutText(display, "B", cvPoint(310,360), &font, CV_RGB(0, 255, 0));
last_time12=clock();}}/*else
{ cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num B //
cvPutText(display, "B", cvPoint(310,360), &font, CV_RGB(0, 255, 0));
}*/
if ((time12 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at B!!\n");
fprintf(pFile, "At pos B %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position B at %lu ms\n\n", time12); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "B", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
} else if ((EyeCenter.x >= col5_left) && (EyeCenter.x <= col5_right) && (EyeCenter.y >= row4_lower) && (EyeCenter.y <=row4_upper))
{
time13 = clock ();
new_num = 13;
if(new_num != pre_num)
{
pre_num = new_num;
track_time = time13;
}
if ((clock()-last_time13)>=0.5/frequency13*CLOCKS_PER_SEC)
{
if (blank13==1){
blank13=0;
cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num S //
last_time13=clock();}
else if (blank13==0){
blank13=1;
cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num S //
cvPutText(display, "S", cvPoint(410,480), &font, CV_RGB(0, 255, 0));
last_time13=clock();}}/*else
{ cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num S //
cvPutText(display, "S", cvPoint(410,480), &font, CV_RGB(0, 255, 0));
}*/
if ((time13 - track_time) >= eye_threshold * CLOCKS_PER_SEC)
{
printf("Confirm target at S!!\n");
fprintf(pFile, "At pos S %lu ms with coordinates (%d,%d) since start of program\n", track_time, EyeCenter.x, EyeCenter.y); // To read time when eye is at that position since start of program
fprintf(pFile, "Exit position S at %lu ms\n\n", time13); // To read time when eye is at that position since start of program
track_time = clock(); // Reset track_time
}
cvZero( plot ); // To clear previous number displayed //
cvPutText(plot, "S", plot_pos, &font1, CV_RGB(0, 255, 0)); // Show number eye is looking at //
}
else {
cvZero(display);
cvRectangle( display, cvPoint(0, 0), cvPoint(500,500), CV_RGB(255, 255, 255),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
// Draw numbers and boxes in Display window
cvRectangle( display, cvPoint(10, 20), cvPoint(10 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 1 Width = 80, Height = 110, GapX = 20, GapY = 10//
cvPutText(display, "1", cvPoint(10,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 20), cvPoint(110 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 2 //
cvPutText(display, "2", cvPoint(110,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 20), cvPoint(210 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 3 //
cvPutText(display, "3", cvPoint(210,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 20), cvPoint(310 + box_width, 20 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 4 //
cvPutText(display, "4", cvPoint(310,120), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 140), cvPoint(10 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 5 //
cvPutText(display, "5", cvPoint(10,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 140), cvPoint(110 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 6 //
cvPutText(display, "6", cvPoint(110,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 140), cvPoint(210 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 7 //
cvPutText(display, "7", cvPoint(210,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 140), cvPoint(310 + box_width, 140 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 8 //
cvPutText(display, "8", cvPoint(310,240), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(10, 260), cvPoint(10 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num A //
cvPutText(display, "A", cvPoint(10,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(110, 260), cvPoint(110 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 10 //
cvPutText(display, "9", cvPoint(110,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(210, 260), cvPoint(210 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num 11 //
cvPutText(display, "0", cvPoint(210,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(310, 260), cvPoint(310 + box_width, 260 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num B //
cvPutText(display, "B", cvPoint(310,360), &font, CV_RGB(0, 255, 0));
cvRectangle( display, cvPoint(410, 380), cvPoint(410 + box_width, 380 + box_height), CV_RGB(0, 0, 0),CV_FILLED, 8, 0 ); // Num S //
cvPutText(display, "S", cvPoint(410,480), &font, CV_RGB(0, 255, 0));
}
run_stop=clock();
}
//cvSaveImage("Display.jpg", display);
// Draw cross at center of eye //
cvLine(image, cvPoint( track_box.center.x - 3, track_box.center.y - 3), cvPoint( track_box.center.x + 3, track_box.center.y + 3), CV_RGB(255,0,0), 1, CV_AA, 0);
cvLine(image, cvPoint( track_box.center.x - 3, track_box.center.y + 3), cvPoint( track_box.center.x + 3, track_box.center.y - 3), CV_RGB(255,0,0), 1, CV_AA, 0);
cvShowImage( "Test_proj", image );
// cvShowImage( "Histogram", histimg );//
cvShowImage( "Projection", plot );
cvShowImage ( "Display", display);
// Write frame to file
//cvWriteFrame(writer, image);
c = cvWaitKey(10);
if( (char) c == 27 )
break;
switch( (char) c )
{
case 'b': // Toggle backprojection
backproject_mode ^= 1;
break;
case 'x': // Calibration
calibrate = 1;
printf("Calibrated.\n\n");
break;
case 's': // Clear tracking
track_object = 0;
// Print end time and date
time ( &rawtime );
timeinfo = localtime ( &rawtime );
fprintf (pFile, "The eye tracking end date/time is: %s\n", asctime (timeinfo) );
cvZero( histimg );
break;
default:
;
}
}
cvReleaseCapture( &capture );
cvDestroyWindow("Test_proj");
cvDestroyWindow("Projection");
cvDestroyWindow("Display");
// Release writer
cvReleaseVideoWriter(&writer);
return 0;
}
#ifdef _EiC
main(1,"test_proj.c");
#endif