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