Home Forums Software Development dev Get GazePoints and TimeStamps by Event

This topic contains 7 replies, has 2 voices, and was last updated by  Grant [Tobii] 6 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #9328

    Pedro Coelho
    Participant

    Hello, I have a Tobii 4C Eye tracker and I am using the Tobii Core SDK in a C# program.
    I already made a grid in a form with 9 rectangles separating each of the space in the display (center, left, right, left center, right center, left up, left down, right up and right down).
    When the user fixates his eyes on each rectangle (by OnGaze event) it prints to the console the respective area name.
    What I want is also to print the X and Y coordinates and the timestamp when there is the respective OnGaze event.
    I already tried the fixationDataStreams but I don’t know how to combine them to the event and maybe it is not the best solution.
    If someone could help me it would be great.
    I can share the code of the project:
    https://github.com/pedrocoelho100/Modalities/tree/master/GenericGazeModality

    Thank you

    #9342

    Grant [Tobii]
    Moderator

    Hi @wrapcaesar and thanks for your query. You can extract the gaze location and timestamp from the “GazePointDataStream” stream for which we provide an example of syntax within the “Interaction_Streams_101” sample application which you can download @ https://github.com/Tobii/CoreSDK

    Below is the relevant snippet

    var host = new Host();
    
    // 2. Create stream. 
    var gazePointDataStream = host.Streams.CreateGazePointDataStream();
    
    // 3. Get the gaze data!
    gazePointDataStream.GazePoint((x, y, ts) => Console.WriteLine("Timestamp: {0}\t X: {1} Y:{2}", ts, x, y));

    Hopefully this helps you out! Please let us know if we can be of further assistance.

    #9344

    Pedro Coelho
    Participant

    Hello Grant,
    I did that but it is not printing on the console, it just prints one time. And I want the single timestamp when the OnGaze event occurs, how can I do that?
    Can you test it with the program please?

                _host = new Host();
    
                // 2. Create stream.
                gazePointDataStream = _host.Streams.CreateGazePointDataStream();
    
                // 3. Get the gaze data!
                gazePointDataStream.GazePoint((x, y, ts) => Console.WriteLine("Timestamp: {0}\t X: {1} Y:{2}", ts, x, y));
               
                // Add eye-gaze interaction behaviors to the panels on the form.
                Program.EyeXHost.Connect(behaviorMap1);
                behaviorMap1.Add(panel1, new EyeXFramework.GazeAwareBehavior(OnGaze1) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel2, new EyeXFramework.GazeAwareBehavior(OnGaze2) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel3, new EyeXFramework.GazeAwareBehavior(OnGaze3) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel4, new EyeXFramework.GazeAwareBehavior(OnGaze4) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel5, new EyeXFramework.GazeAwareBehavior(OnGaze5) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel6, new EyeXFramework.GazeAwareBehavior(OnGaze6) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel7, new EyeXFramework.GazeAwareBehavior(OnGaze7) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel8, new EyeXFramework.GazeAwareBehavior(OnGaze8) { DelayMilliseconds = 500 });
                behaviorMap1.Add(panel9, new EyeXFramework.GazeAwareBehavior(OnGaze9) { DelayMilliseconds = 500 });
                
                // Close the coonection to the Tobii Engine before exit.
                _host.DisableConnection();
    
            }
    
            private void OnGaze1(object sender, GazeAwareEventArgs e)
            {
                if (e.HasGaze)
                {
                    gazePoint = "Esquerda Cima";
                    gazeType = "Fixação";
                    gazePoints.Add(gazePoint);
                    SendMessage(gazeType, gazePoint /*, timestamp, x, y*/ );
                    Console.WriteLine("Fixação em " + gazePoint);
                    PrintPanel1(this.panel1);
                }
            }

    Thank you

    #9348

    Grant [Tobii]
    Moderator

    Hi @wrapcaesar, your syntax looks okay but it’s the combination of trying to output to the console whilst simultaneously using a WPF application that might be tripping you up. Your code never produced any console out on my machine. I think it would be better to create a text box on the WPF form and populate it’s contents with the fixation information or alternatively save the data to an array for later analysis.. have you already tried this? Why do you want the output to a regular windows console seperate from the WPF window?

    With reference to catching the point at which gaze is detected on the elements (Rather than the fixation time) then it should be sufficient to simply use the current time method (DateTime.Now) within the if(e.HasGaze) routine.

    I would also point out that storing of gaze data for analysis requires the purchase of a special licence to do so. You can read more about this @ https://analyticaluse.tobii.com

    #9351

    Pedro Coelho
    Participant

    Hello Grant,

    Yes, the combination leaded me to some problems but it is resolved now, I created a new Class with the Gaze Data Stream methods, pass the Timestamp, GazeX and GazeY coordinates to a new List<string> and then in each OnGaze() function, call that function that returns those 3 arguments and I can now get the timestamps when there is an event.
    You can test it now, maybe the problem is because you have to reference the mmisharp.dll to the project.
    I want the output to a regular windows console seperate from the WPF window because I want to send the message events with the arguments to another application outside the Visual Studio.

    Ok thank you.

    #9362

    Grant [Tobii]
    Moderator

    Hi @wrapcaesar, great! Glad to hear you got it sorted and working. Certainly it’s a rather unusual setup to try and get console output at the same time, so I suppose the 3rd party application can’t receive events directly but can only read them from console?

    Such a setup is quite outside the scope of the Support offered here I’m afraid, so I would suggest checking out Stackoverflow forums for which I found a relevant link @ https://stackoverflow.com/questions/160587/no-output-to-console-from-a-wpf-application

    Hopefully this is what you need to get up and running. Best Wishes.

    #9376

    Pedro Coelho
    Participant

    Hello Grant,
    Yes, thank you.
    You’re right, the purpose is to pass the arguments to the console so they can be sent to the 3rd party application once an event occur.
    Ok thank you so much.

    #9383

    Grant [Tobii]
    Moderator

    Happy to be of help @wrapcaesar! Thanks for sharing your code at github, hopefully other interested users can make use your efforts. Best Wishes.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.