calibration

Forum for development in the Java programming language.

calibration

Postby rZamora » 05 Aug 2014, 15:57

Can i please get some help on implementing the calibration process. I have taken code from the previous thread ([Resolved] Geting no calibresult data in last pointed ) but i do not understand if the API will draw the points in the screen or i have to do that with my code. Would appreciate if someone can share some code.
many thanks
rZamora
 
Posts: 2
Joined: 04 Aug 2014, 19:06

Re: calibration

Postby Javier » 05 Aug 2014, 17:12

The Java SDK does not include any UI elements to draw the calibration points. We recommend you take a look at the C# samples on GitHub to get some inspiration on how to build a calibration routine.
Javier
 
Posts: 54
Joined: 24 Oct 2013, 14:20

Re: calibration

Postby sourabhbans0007 » 21 Aug 2014, 16:50

Hi there , I am facing same kind of problems (Calibration process). I need to implement calibration process in my application. but no idea how to do that. I have implemented the code that is given in previous article and it is showing calibrating, but some times it show calibration result failed. And i am confused how to show the calibration screen. Is someone have code sample or example or any kind of information about it please contact me. Can someone help me ?


Thanks and regards...

Sourabh bans
email:- sourabhbans007@gmail.com
sourabhbans0007
 
Posts: 11
Joined: 11 Aug 2014, 12:18

Re: calibration

Postby Anders » 19 Sep 2014, 08:07

Maybe taking a look at the resources references in this post will help you understand and implement the calibration process.

BR,
Anders
Anders
 
Posts: 124
Joined: 29 Oct 2013, 16:23

Re: calibration

Postby carlos.gomes » 03 Oct 2014, 11:06

Hi,

I have done the calibration process on Java with no problems (see an excerpt of the java code).

Any question you can email me varz86@gmail.com

PS: I am not doing some interesting checks. For instance, notice that I am not implementing ITrackerStateListener.

Code: Select all
package Calibration;

import java.util.LinkedList;
import java.util.Queue;
import Utilities.Point2D;
import com.theeyetribe.client.GazeManager;
import com.theeyetribe.client.GazeManager.ApiVersion;
import com.theeyetribe.client.GazeManager.ClientMode;
import com.theeyetribe.client.ICalibrationProcessHandler;
import com.theeyetribe.client.IGazeListener;
import com.theeyetribe.client.data.CalibrationResult;
import com.theeyetribe.client.data.CalibrationResult.CalibrationPoint;
import com.theeyetribe.client.data.GazeData;

public class Cali implements ICalibrationProcessHandler{ 

   private int number_points;
   private int reSamplingCount;

   Queue<Point2D> calibrationPoints;
   Point2D currentPoint;
   private final int NUM_MAX_CALIBRATION_ATTEMPTS = 2;
   private final int NUM_MAX_RESAMPLE_POINTS = 4;

   Cali(GraphicsLogic SC){

      if (GazeManager.getInstance().isActivated()){
         GazeManager.getInstance().deactivate();
      }

      GazeManager.getInstance().activate(ApiVersion.VERSION_1_0, ClientMode.PUSH);

      this.number_points = 9;

      final GazeListener gazeListener = new GazeListener();
      GazeManager.getInstance().addGazeListener(gazeListener);

      Runtime.getRuntime().addShutdownHook(new Thread()
      {
         @Override
         public void run()
         {
            GazeManager.getInstance().removeGazeListener(gazeListener);
            GazeManager.getInstance().deactivate();
         }
      });


   }

   public void StartCalibration(){

      System.out.println("Start");      

      //Checking if Eye Tracker is OK -> ITrackerStateListener
      //StopAndClose("Error: Device is not in a valid state, cannot calibrate.");

      DoCalibrate();
   }

   public void DoCalibrate(){
      System.out.println("DoCalibrate");
      reSamplingCount = 0;

      System.out.println("isCalibrating: " +GazeManager.getInstance().isCalibrating());

      calibrationPoints = createPointList();
      currentPoint = PickNextPoint();      

      if (GazeManager.getInstance().isCalibrating()){ //I am not sure if this is the best way to do it
         GazeManager.getInstance().calibrationAbort();
         GazeManager.getInstance().calibrationClear();
      }

      // Signal tracker server that we're about to start a calibration
      GazeManager.getInstance().calibrationStart(number_points, this);

   }

   public void Step(Point2D point){
      //View.newPos((int)point.getX(),(int)point.getY()); //Put a new point graphically
      
      try{Thread.sleep(500);}catch (Exception e){}; //wait for the gaze to meet the point
      GazeManager.getInstance().calibrationPointStart((int)point.getX(),(int)point.getY()); //start the calibration process
      
      try{Thread.sleep(500);}catch (Exception e){}; //wait for the calibration process to take the data
      GazeManager.getInstance().calibrationPointEnd(); //end the calibration process
   }

   @Override
   public void onCalibrationStarted() {
      // tracker engine is ready to calibrate - check if we can start to calibrate
      //calibrationServiceReady = true;
      if (currentPoint != null)//if there is another poitn to calibrate, do it
         Step(currentPoint);
      else{
         StopAndClose("onCalibrationStarted: currentPoint is null"); //otherwise Close
      }
   }

   @Override
   public void onCalibrationProgress(double progress) {
      if (calibrationPoints.size() > 0){ //The process will be done as long as there are points to be calibrarted
         currentPoint = PickNextPoint();
         Step(currentPoint);
      }       
   }

   @Override
   public void onCalibrationProcessing() {
      System.out.println("--------------onCalibrationProcessing");
   }

   @Override
   public void onCalibrationResult(CalibrationResult res) {
      System.out.println("--------------onCalibrationResult ");

      //If there is not result, Stop
      if (res == null || res.calibpoints == null){
         StopAndClose("Error: Calibration result is empty.");
      }

      //There might points that need to be recalibrated
      for (CalibrationPoint calPoint : res.calibpoints){
         if (calPoint == null || calPoint.coordinates == null)
            continue;

         //information is taken from the Tracker
         if (calPoint.state == CalibrationPoint.STATE_RESAMPLE || calPoint.state == CalibrationPoint.STATE_NO_DATA){
            calibrationPoints.add(new Point2D((int)calPoint.coordinates.x, (int)calPoint.coordinates.y));
         }
      }

      //The process will not run forever.
      //-> there is a fixed number for recalibration
      //-> the calibration is done again if there are not so many points to be recalibrated
      if (reSamplingCount++ >= NUM_MAX_CALIBRATION_ATTEMPTS || calibrationPoints.size() >= NUM_MAX_RESAMPLE_POINTS){
         StopAndClose("Failure: Unable to calibrate.");
      }

      currentPoint = null;
      if (calibrationPoints.size() > 0)
         currentPoint = PickNextPoint();

      if (currentPoint != null){
         Step(currentPoint);
      }else{
         StopAndClose(RatingFunction(res.averageErrorDegree));
      }
   }

   private void StopAndClose(String msg){
      System.out.println("Done!");
      //View.end_calibration(msg); //tell the graphics to stop
      return;
      //View.close(); //close the window
      //System.exit(0);
   }

   public String RatingFunction(double accuracy){
      if (accuracy < 0.5)
         return "Calibration Quality: PERFECT";

      if (accuracy < 0.7)
         return "Calibration Quality: GOOD";

      if (accuracy < 1)
         return "Calibration Quality: MODERATE";

      if (accuracy < 1.5)
         return "Calibration Quality: POOR";

      return "Calibration Quality: REDO";
   }

   public Queue<Point2D> createPointList(){
      System.out.println("createPointList()");
      Queue<Point2D> res = new LinkedList<Point2D>();
      //Create the points taking into account the size of the current screen
      return res;
   }

   private Point2D PickNextPoint(){
      if (calibrationPoints == null)
         calibrationPoints = createPointList();

      if (calibrationPoints.size() != 0)
         return calibrationPoints.remove();

      return null;
   }
}


class GazeListener implements IGazeListener
{

   @Override
   public void onGazeUpdate(GazeData gazeData) {
   }

}
carlos.gomes
 
Posts: 4
Joined: 18 Dec 2013, 12:06

Re: calibration

Postby alina » 29 Oct 2014, 16:26

Hi,

first of all, carlos, your code was very helpful, thanks a lot! But I was wondering whether it actually works if there are points to be resampled:
In that case, I get an exception "Exception while calling ICalibrationProcessHandler.OnCalibrationResult() on listener eyeTracker.CalibrationHandler@5154e1cc: null". Is there anything I can do about that? Or can anyone tell me what goes wrong?

Also, I often get errors because either calibration is already running (despite of a call to calibrationAbort() before) or because the tracker is not calibrating when the first calls to calibrationPointStart(..) are made (despite of checking isCalibrating() before). The latter case doesn't go well with the impossibility to recalibrate a single point, too.... Any help? Did I miss something?
alina
 
Posts: 6
Joined: 08 Aug 2014, 11:29

Re: calibration

Postby Anders » 03 Nov 2014, 18:33

Hi Alina

I get an exception "Exception while calling ICalibrationProcessHandler.OnCalibrationResult() on listener eyeTracker.CalibrationHandler@5154e1cc: null".


From your message, it is clear that something is going on in your implementation of ICalibrationProcessHandler. I am guessing a NPE that is not handled. That means an error in your side of the code.

As mentioned earlier in this thread, maybe this post can help you understand the calibration and how to handle the resampling procedure better.

Best of luck.

BR,
Anders
Anders
 
Posts: 124
Joined: 29 Oct 2013, 16:23

Re: calibration

Postby alina » 10 Dec 2014, 11:55

Hi,

I recently revisited my problem and found the source of the NPE, it happened because I used the Point2D class as a key in an Hash-Map but the class doesn't implement the hashCode Method, maybe you want to include this in future releases.

But solving this stll didn't enable me to resample some points (I'd like to resample points with too low accuracy, because a good average accuracy usually doesn't mean that the accuracy is very high when you lok at the outer regions of the screen):
I've been looking at the code of the C# calibration example, but I still don't get how to restart the calibration for the points I want to resample:
By the time onCalibrationResult is called, isCalibrating is false, so I have to start a new calibration, otherwise "calibrationPointStart" will throw an error. But this means I have to sample all points again, doesn't it?

I'm sorry for the probably stupid question, but I just can't find the difference between my code and the C# example...
alina
 
Posts: 6
Joined: 08 Aug 2014, 11:29

Re: calibration

Postby Anders » 10 Dec 2014, 12:48

Hi Alina

Your resampling algorithm should look something like this

Code: Select all
   private final int NUM_MAX_CALIBRATION_ATTEMPTS = 3;
   private final int NUM_MAX_RESAMPLE_POINTS = 4;
   private int resampleCount;

   @Override
   public void onCalibrationResult(final CalibrationResult calibResult)
   {               
       if(calibResult.result)
       {
           //Success, update state of UI and/or proceed in flow
       }
       else
       {
           //resampling needed
           final ArrayList<Point2D> resamplePoints = new ArrayList<Point2D>();

           //Evaluate results
           for (CalibrationPoint calibPoint : calibResult.calibpoints)
           {
               if (calibPoint.state == CalibrationPoint.STATE_RESAMPLE || calibPoint.state == CalibrationPoint.STATE_NO_DATA)
               {
                   resamplePoints.add(new Point2D(Math.round(calibPoint.coordinates.x), Math.round(calibPoint.coordinates.y)));
               }
           }

           //Should we abort?
           if (resampleCount++ >= NUM_MAX_CALIBRATION_ATTEMPTS || resamplePoints.size() == 0|| resamplePoints.size() >= NUM_MAX_RESAMPLE_POINTS)
           {
               GazeManager.getInstance().calibrationAbort();

               //Resampling failed despite retries, update UI explaining that calibration failed

               resampleCount = 0;

               return;
           }

           //TODO: Set up UI with identified resampling points and re-run calibration process for these
       }
   }


Hope this help!

Also, you might wanna reconsider using hashcode as a key depending on your scenario. See point #2 here.

BTW make sure you update to latest version of the Java SDK

BR,
Anders
Anders
 
Posts: 124
Joined: 29 Oct 2013, 16:23

Re: calibration

Postby alina » 10 Dec 2014, 15:11

Hi,

ok, I think now I understand the problem and it has nothing to do with the code. What I wanted to do is just not possible, and - thinking again - also doesn't make any sense at all. Shame on me and sorry for wasting your time ;)
Last edited by alina on 10 Dec 2014, 17:12, edited 2 times in total.
alina
 
Posts: 6
Joined: 08 Aug 2014, 11:29

Next

Return to Java



cron