C++ EXAMPLE FOR EYE TRACKING

Forum for development in the C++ programming language.

C++ EXAMPLE FOR EYE TRACKING

Postby uril » 20 Jan 2014, 21:04

Hi everyone,

We have just received our eye tracker and I am wondering where I can get C++ examples. Any help will be appreciated.

Thank you,

Uril.
uril
 
Posts: 11
Joined: 20 Jan 2014, 20:34

Re: C++ example for Eye tracking device

Postby Martin » 21 Jan 2014, 01:58

Hi Uril,

We're having a release meeting tomorrow, aiming at shipping the c++ examples soon. Sorry to keep you waiting.
Martin
 
Posts: 567
Joined: 29 Oct 2013, 15:20

Re: C++ example for Eye tracking device

Postby uril » 21 Jan 2014, 02:24

Hi Everyone,

I have a C++ project which involves showing an image on the screen and reading the X and Y coordinate from the Eye tracking device. I have downloaded SDK from the Eye Tribe link.
I have a couple questions:
1. Does anyone know which C++ Jason library I can use in order to communicate with the Eye tracking device.
2. Can anyone provide me with a simple C++ example.
3. I am using Windows 7 and Visual Studio C++ Express. Which libraries should I link with my project in order to compile it? Can I use g++ mingw compiler?

Any help will be appreciated!

Thank you,

Uril.
uril
 
Posts: 11
Joined: 20 Jan 2014, 20:34

Re: C++ EXAMPLE FOR EYE TRACKING

Postby Henrik » 22 Jan 2014, 17:42

Hi uril,

The C++ SDK client will be available early next week.
Henrik
 
Posts: 10
Joined: 29 Oct 2013, 16:21

Re: C++ EXAMPLE FOR EYE TRACKING

Postby Martin » 30 Jan 2014, 15:19

The C++ SDK has been published on Github.

Please let us know what you think.

Enjoy!
Martin
 
Posts: 567
Joined: 29 Oct 2013, 15:20

Re: C++ EXAMPLE FOR EYE TRACKING

Postby uril » 26 Feb 2014, 19:19

Hi Everyone,

I have copied all files from GitHub C++ directory directly into my Visual C++ project, installed boost and successfully compiled and linked using your example from http://dev.theeyetribe.com/tutorial/ link.

I have added diagnostic line to function on_gaze_data from MyGaze class to see if I getting data from the server. In the main function I have declared MyGaze class.

Unfortunately I could not get data from the server. Did I do something wrong?

Any help will be appreciated?

Uril.
uril
 
Posts: 11
Joined: 20 Jan 2014, 20:34

Re: C++ EXAMPLE FOR EYE TRACKING

Postby mingxinbit » 26 Feb 2014, 21:39

I have researched this code.

In fact, I think it is very easy to operate.

Maybe you first build a new project e.g console application program, then add MyGaze Class and header files into your project.

It is very interesting, their connect function for linking server was put with the Class Constructor function.

In this case, you can define a object for this class, like this:

Code: Select all
MyGaze _mygaze


Then the Class Constructor function can be run, and you will see your eye tracker is running.

As for gaze data, you need not to do anything. If the connect correct, then add_listener function run, about this function's application, they provided a introduction:
Code: Select all
/** Add an IGazeListener to the GazeApi.
         *
         * \param[in] listener The IGazeListener listener to be added.
         * \sa remove_listener(IGazeListener & listener).
         */
        void add_listener(IGazeListener & listener);


As for me, I think it looks like a sniffer function, if new data is calculated, then gaze data will be return through CallBack function, as follows:

Code: Select all
 /** A notification call back indicating that a new GazeData frame is available.
         * Implementing classes should update themselves accordingly if needed.
         * Register for updates through GazeApi::add_listener(IGazeListener & listener)
 \param[in] gazeData Latest GazeData frame processed by Tracker Server
 */
        virtual void on_gaze_data(gtl::GazeData const & gaze_data) = 0;


Is that clear?

Thank you!
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: C++ EXAMPLE FOR EYE TRACKING

Postby uril » 27 Feb 2014, 21:19

Hi Everyone,

It is clear.
Please see below:

#include "stdafx.h"
#include "gazeapi.h"
#include <iostream>


using namespace std;

// --- MyGaze definition
class MyGaze : public gtl::IGazeListener
{
public:
MyGaze();
~MyGaze();
private:
// IGazeListener
void on_gaze_data( gtl::GazeData const & gaze_data );
private:
gtl::GazeApi m_api;
};

// --- MyGaze implementation
MyGaze::MyGaze()
{
// Connect to the server in push mode on the default TCP port (6555)
if( m_api.connect( true ) )
{
// Enable GazeData notifications
m_api.add_listener( *this );
}
}

MyGaze::~MyGaze()
{
m_api.remove_listener( *this );
m_api.disconnect();
}

void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinates = gaze_data.avg;

// Move GUI point, do hit-testing, log coordinates, etc.

cout << "x = " << smoothedCoordinates.x << " y = " << smoothedCoordinates.y << endl;
}
}


int main()
{

MyGaze test;


return 0;
}

I don't see X any Y coordinates inside console output.
Is it possible that the server and the client have different software versions? For example I have been using server software since January.
I see declaration of "class engine" in gazeapi.h but where your define this class.

Thank you,

Uril.
uril
 
Posts: 11
Joined: 20 Jan 2014, 20:34

Re: C++ EXAMPLE FOR EYE TRACKING

Postby mingxinbit » 27 Feb 2014, 21:55

Hi,

I made the same as your mistake as your code.

I suggest you can re-make your code below:

Code: Select all
using namespace std;

// --- MyGaze definition
class MyGaze : public gtl::IGazeListener
{
public:
MyGaze();
~MyGaze();
private:
// IGazeListener
void on_gaze_data( gtl::GazeData const & gaze_data );
private:
gtl::GazeApi m_api;
};

// --- MyGaze implementation
MyGaze::MyGaze()
{
// Connect to the server in push mode on the default TCP port (6555)
if( m_api.connect( true ) )
{
// Enable GazeData notifications
m_api.add_listener( *this );
}
}

MyGaze::~MyGaze()
{
m_api.remove_listener( *this );
m_api.disconnect();
}

void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinates = gaze_data.avg;

// Move GUI point, do hit-testing, log coordinates, etc.

cout << "x = " << smoothedCoordinates.x << " y = " << smoothedCoordinates.y << endl;
}
}


int main()
{

MyGaze test;

where (1)
{
here you also can write the output function e.g. cout <<  or printf, of course, under the precondition of predefined coordinates variable in your class
}

return 0;
}


1. I found the console can not be output from value of coordinates, since your code just run once. You maybe seen your eye tracker run with IR light on, later it was shut down quickly. I guess the data is delayed due to device initialization, send data, etc, all need time so called delay, so your code on your computer run too fast to never be displayed on the console window. So, you'd better insert the loop code for not quit your running code, here I used while (1), above code. In this case, you will see data and work well.

2. If you follow above and operate well, maybe you can check the smoothed data from smoothedCoordinates.x. As for me I always captured error data which are the value -107374176. I have no idea for this problem, and I have posted the message in this forum, maybe you have visited there.

3. Today, I have tested another method to capture the gaze data. Through the review of the code, I changed the method for capturing x and Y coordinates as can be seen follows:

Code: Select all
void MyGaze::on_gaze_data( gtl::GazeData const & gaze_data )
{
if( gaze_data.state & gtl::GazeData::GD_STATE_TRACKING_GAZE )
{
gtl::Point2D const & smoothedCoordinatesLeftEye = gaze_data.lefteye.avg; // smoothed data from left eye
gtl::Point2D const & smoothedCoordinatesRightEye=gaze_data.righteye.avg; // smoothed data from right eye

LeftEyeX=smoothedCoordinatesLeftEye.x;
LeftEyeY=smoothedCoordinatesLeftEye.y;
      
RightEyeX=smoothedCoordinatesRightEye.x;
RightEyeY=smoothedCoordinatesRightEye.y;

// Move GUI point, do hit-testing, log coordinates, etc.
cout << "x = " << (LeftEyeX+ RightEyeX)/2<< " y = " << (LeftEyeY+RightEyeY)/2 << endl; //center values for left and right eyes, respectively.
}
}


At least, I had a good result. More than that, I input the captured gaze data (coordinates) set into cursor positions for successful controlling cursor movement. I think it is cool, the smoothed data is very stable. Maybe you can have a try.

By the way, what's your application for? Research or else?

Is that clear?

I hope hear your sound.

Thank you!

Mingxin
mingxinbit
 
Posts: 19
Joined: 22 Jan 2014, 05:59

Re: C++ EXAMPLE FOR EYE TRACKING

Postby uril » 28 Feb 2014, 00:05

Hi Everyone,

I have found declaration of class Engine.

Thanks,

uril.
uril
 
Posts: 11
Joined: 20 Jan 2014, 20:34

Next

Return to C++



cron