The project is based on Eye Tracker. Let me brief the idea behind the project to understand my problem better.
I have the hardware of Tobii C eye tracker. This eye tracker will be able to give out coordinates of the X, Y of where I am looking at. But this device is very sensitive. When I look at 1 point, the eye tracker will send out many different data of coordinates but within ± 100
range which I found out. Even though you are staring at 1 point, your eyes keep moving, therefore giving out many data. This many data (float numbers) are then saved in a text file. Now I only need 1 data (X coordinate) which signifies the 1 point I am staring instead of the many data which are within the ± 100
range and move it to a new text file.
I have no idea how I should code to do that.
These are the float
numbers in the text file.
200
201
198
202
250
278
310
315
360
389
500
568
579
590
When I stare at point 1, the data are 200-300
, which are within the ± 100
range. I wanna set the 200
as reference point subtracts itself with the next number and check if the resultant value within 100
, if it is, remove them. The reference point should keep doing that to the following numbers until it reaches outside the ± 100
range. Once outside the 100
range, now the number is 310
, then now this number is the next reference point and do the same and subtract with the following numbers below and check if the resultant value within 100
. Once outside the 100
range, the next number is 500
, now, that is the new reference point, and do the same. That is my objective. To put it to simpler terms, The reference points should be moved into a new file.
This is my code so far which get the gaze coordinates and stores them in a text file.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Tobii.Interaction;
namespace ConsoleApp1
{
class Program
{
private static void programintro()
{
Console.WriteLine("Press Any Keys To Start");
}
public static void Main(string[] args)
{
programintro();
Console.ReadKey();
double currentX = 0.0;
double currentY = 0.0;
double timeStampCurrent = 0.0;
double diffX = 0.0;
double diffY = 0.0;
int counter = 0;
var host = new Host();
host.EnableConnection();
var gazePointDataStream = host.Streams.CreateGazePointDataStream();
gazePointDataStream.GazePoint((gazePointX, gazePointY, timestamp) =>
{
diffX = gazePointX - currentX;
diffY = gazePointY - currentY;
currentX = gazePointX;
currentY = gazePointY;
timeStampCurrent = timestamp;
if (diffX > 100 || diffX <= -100 || diffY >= 100 || diffY <= -100)
{
counter++;
using (StreamWriter writer = new StreamWriter("C: \\Users\\Student\\Desktop\\FYP 2019\\ConsoleApp1\\ConsoleApp1\\Data\\TextFile1.txt", true))
{
writer.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
writer.WriteLine("=================================================================================================================");
}
Console.WriteLine("Recorded Data " + counter + "\n=================================================================================================================\nX: {0} Y:{1}\nData collected at {2}", currentX, currentY, timeStampCurrent);
Console.WriteLine("=================================================================================================================");
}
});
//host.DisableConnection();
while (true)
{
if (counter < 10)
{
continue;
}
else
{
Environment.Exit(0);
}
}
Now my Question is how do I code to read the text file and set a reference number and subtracts itself with the next number and check if the resultant value within
100
and have a new reference number if it outside the± 100
range. Those reference numbers are then stored in a new text file.