private static void Calibrate(IEyeTracker eyeTracker)
        {
            // Create a calibration object.
            var calibration = new ScreenBasedCalibration(eyeTracker);


            // Define the points on screen we should calibrate at.
            // The coordinates are normalized, i.e. (0.0f, 0.0f) is the upper left corner and (1.0f, 1.0f) is the lower right corner.
            var pointsToCalibrate = new NormalizedPoint2D[] {
                new NormalizedPoint2D(0.5f, 0.5f),
                new NormalizedPoint2D(0.1f, 0.1f),
                new NormalizedPoint2D(0.1f, 0.9f),
                new NormalizedPoint2D(0.9f, 0.1f),
                new NormalizedPoint2D(0.9f, 0.9f),
            };

            // Enter calibration mode.
            calibration.EnterCalibrationMode();

            // Collect data.
            foreach (var point in pointsToCalibrate)
            {
                // Show an image on screen where you want to calibrate.
                Console.WriteLine("Show point on screen at ({0}, {1})", point.X, point.Y);
                // Wait a little for user to focus.
                //System.Threading.Thread.Sleep(700);
                // Collect data.,,
                CalibrationStatus status = calibration.CollectData(point);

                if (status != CalibrationStatus.Success)
                {
                    // Try again if it didn't go well the first time.
                    // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                    calibration.CollectData(point);
                }
            }
            // Compute and apply the calibration.
            CalibrationResult calibrationResult = calibration.ComputeAndApply();

            Console.WriteLine("Compute and apply returned {0} and collected at {1} points.",
                              calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
            // Analyze the data and maybe remove points that weren't good.
            calibration.DiscardData(new NormalizedPoint2D(0.1f, 0.1f));
            // Redo collection at the discarded point.
            Console.WriteLine("Show point on screen at ({0}, {1})", 0.1f, 0.1f);
            calibration.CollectData(new NormalizedPoint2D(0.1f, 0.1f));
            // Compute and apply again.
            calibrationResult = calibration.ComputeAndApply();
            Console.WriteLine("Second compute and apply returned {0} and collected at {1} points.",
                              calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
            // See that you're happy with the result.
            // The calibration is done. Leave calibration mode.
            calibration.LeaveCalibrationMode();
        }
        private void CalibrationMode()
        {
            calibration.EnterCalibrationMode();
            var pointsToCalibrate = new NormalizedPoint2D[] {
                new NormalizedPoint2D(0.5f, 0.5f),
                new NormalizedPoint2D(0.1f, 0.1f),
                new NormalizedPoint2D(0.1f, 0.9f),
                new NormalizedPoint2D(0.9f, 0.1f),
                new NormalizedPoint2D(0.9f, 0.9f),
            };

            foreach (var point in pointsToCalibrate)
            {
                //this.Dispatcher.Invoke(() =>
                //{
                //    Connect.Text = $"Please look at {point.X},{point.Y}.";
                //});
                //CoPoint.Text = $"Please look at {point.X},{point.Y}.";

                //ThreadPool.QueueUserWorkItem((o) =>
                //{

                //});
                Dispatcher.Invoke((Action)(() => Connect.Text = $"Please look at {point.X},{point.Y}."));
                System.Threading.Thread.Sleep(1000);

                CalibrationStatus status = calibration.CollectData(point);
                if (status != CalibrationStatus.Success)
                {
                    calibration.CollectData(point);
                }
            }
            CalibrationResult calibrationResult = calibration.ComputeAndApply();

            CoPoint.Text = $"Compute and apply returned {calibrationResult.Status} and collected at {calibrationResult.CalibrationPoints.Count} points.";
            Thread.Sleep(1000);
            //calibration.DiscardData(new NormalizedPoint2D(0.1f, 0.1f));
            //calibration.CollectData(new NormalizedPoint2D(0.1f, 0.1f));
            //calibrationResult = calibration.ComputeAndApply();

            calibration.LeaveCalibrationMode();
        }
Exemple #3
0
        private void Calibrate(Form CalibrationForm, IEyeTracker eyeTracker)
        {
            // Define the points on screen we should calibrate at.
            // The coordinates are normalized, i.e. (0.0f, 0.0f) is the upper left corner and (1.0f, 1.0f) is the lower right corner.
            var pointsToCalibrate = new NormalizedPoint2D[] {
                new NormalizedPoint2D(0.5f, 0.5f),
                new NormalizedPoint2D(0.1f, 0.1f),
                new NormalizedPoint2D(0.1f, 0.9f),
                new NormalizedPoint2D(0.9f, 0.1f),
                new NormalizedPoint2D(0.9f, 0.9f),
            };

            var calibration = new ScreenBasedCalibration(eyeTracker);

            // Enter calibration mode.
            calibration.EnterCalibrationMode();

            // Collect data.

            Panel AnimatedPointPanel = new Panel();

            AnimatedPointPanel.Width  = CalibrationForm.Width;
            AnimatedPointPanel.Height = CalibrationForm.Height;
            Graphics AnimatedPointGraphics = AnimatedPointPanel.CreateGraphics();

            CalibrationForm.Controls.Add(AnimatedPointPanel);

            int w = CalibrationForm.Width;
            int h = CalibrationForm.Height;

            MovingPoint(AnimatedPointGraphics, w, h, new NormalizedPoint2D(0.5f, 0.1f), new NormalizedPoint2D(0.5f, 0.5f));
            for (int i = 0; i < pointsToCalibrate.Length; i++)
            {
                var point = pointsToCalibrate[i];
                // Show an image on screen where you want to calibrate.
                DrawPointOnForm(AnimatedPointGraphics, w, h, point);
                Console.WriteLine("Show point on screen at ({0}, {1})", point.X, point.Y);
                // Wait a little for user to focus.
                System.Threading.Thread.Sleep(700);
                // Collect data.
                CalibrationStatus status = calibration.CollectData(point);
                if (status != CalibrationStatus.Success)
                {
                    // Try again if it didn't go well the first time.
                    // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                    calibration.CollectData(point);
                }
                if (i + 1 < pointsToCalibrate.Length)
                {
                    MovingPoint(AnimatedPointGraphics, w, h, point, pointsToCalibrate[i + 1]);
                }
            }
            // Compute and apply the calibration.
            CalibrationResult calibrationResult = calibration.ComputeAndApply();

            Console.WriteLine("Compute and apply returned {0} and collected at {1} points.",
                              calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
            // Analyze the data and maybe remove points that weren't good.
            calibration.DiscardData(new NormalizedPoint2D(0.1f, 0.1f));
            // Redo collection at the discarded point.
            Console.WriteLine("Show point on screen at ({0}, {1})", 0.1f, 0.1f);
            calibration.CollectData(new NormalizedPoint2D(0.1f, 0.1f));
            // Compute and apply again.
            calibrationResult = calibration.ComputeAndApply();
            Console.WriteLine("Second compute and apply returned {0} and collected at {1} points.",
                              calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
            // See that you're happy with the result.
            // The calibration is done. Leave calibration mode.
            calibration.LeaveCalibrationMode();
            CalibrationForm.Close();
        }
        private void CalibrationTobii_Paint(object sender, PaintEventArgs e)
        {
            if (!justOneTime)
            {
                justOneTime   = true;
                gazePointList = new List <Point>();
                SolidBrush newBrush; // to have a new color that we choose

                int w = Screen.PrimaryScreen.Bounds.Width;
                int h = Screen.PrimaryScreen.Bounds.Height;


                var calibration = new ScreenBasedCalibration(mEyeTracker);

                // Define the points on screen we should calibrate at.
                // The coordinates are normalized, i.e. (0.0f, 0.0f) is the upper left corner and (1.0f, 1.0f) is the lower right corner.
                var pta = new PointF[5];

                var pointsToCalibrate = new NormalizedPoint2D[5] {
                    new NormalizedPoint2D(0.5f, 0.5f),
                    new NormalizedPoint2D(0.1f, 0.1f),
                    new NormalizedPoint2D(0.1f, 0.9f),
                    new NormalizedPoint2D(0.9f, 0.1f),
                    new NormalizedPoint2D(0.9f, 0.9f),
                };

                // Enter calibration mode.
                calibration.EnterCalibrationMode();

                foreach (var point in pointsToCalibrate)
                {
                    // Show an image on screen where you want to calibrate.
                    Console.WriteLine("Show point on screen at ({0}, {1})", point.X, point.Y);
                    RectangleF rec = new RectangleF(point.X * w - mConfiguration.calibrationPointSize / 2, point.Y * h - mConfiguration.calibrationPointSize / 2, mConfiguration.calibrationPointSize, mConfiguration.calibrationPointSize);
                    //  RectangleF rec = new RectangleF(point.X * w - 70, point.Y * h - 70, 150, 150);

                    newBrush = new SolidBrush(mConfiguration.CalibrationColor);
                    e.Graphics.FillEllipse(newBrush, rec);

                    // Wait a little for user to focus.


                    // Collect data.,,

                    // Wait a little for user to focus.
                    // System.Threading.Thread.Sleep(700);

                    // getGazeData((int)point.X * w, (int)point.Y * h);

                    int X = (int)(point.X * w); // circle with r=70 ,
                    int Y = (int)(point.Y * h);

                    //compareGazeWithShape(X, Y);



                    CalibrationStatus status = CalibrationStatus.Failure;



                    while (status != CalibrationStatus.Success && gazeIsRight == false)
                    {
                        gazePointList = new List <Point>();
                        gazePointList.Add(getGazePoint());
                        //compareGazeWithShape(X, Y);
                        //e.Graphics.FillEllipse(Brushes.Red, rec);
                        // Try again if it didn't go well the first time.
                        // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                        //vaghti cheshmo nabine ghermez mishe

                        for (int i = 0; i < gazePointList.Count; i++)
                        {
                            //Console.WriteLine(new Point(X, Y));
                            //Console.WriteLine(gazePointList[i]);
                            //Console.WriteLine("+++");

                            int gazeX = gazePointList[i].X;
                            int gazeY = gazePointList[i].Y;
                            if (Math.Pow(gazeX - X, 2) + Math.Pow(gazeY - Y, 2) <= Math.Pow(80, 2))//150 circel
                            {
                                e.Graphics.FillEllipse(Brushes.Green, gazeX, gazeY, 10, 10);
                                gazeIsRight = true;
                                System.Threading.Thread.Sleep(1700);
                                status = calibration.CollectData(point);
                                break;
                            }

                            else
                            {
                                e.Graphics.FillEllipse(Brushes.Red, gazeX, gazeY, 10, 10);
                                gazeIsRight = false;
                            }
                        }
                    }

                    if (status == CalibrationStatus.Success && gazeIsRight == true)
                    {
                        e.Graphics.Clear(Color.Black);
                        e.Graphics.FillEllipse(Brushes.Black, rec);
                    }
                    gazeIsRight = false;
                    Invalidate();
                }
                // Compute and apply the calibration.
                CalibrationResult calibrationResult = calibration.ComputeAndApply();
                Console.WriteLine("Compute and apply returned {0} and collected at {1} points.", calibrationResult.Status, calibrationResult.CalibrationPoints.Count);

                //textBox1.Text += "Compute and apply returned" + calibrationResult.Status+" and collected at " + calibrationResult.CalibrationPoints.Count+" points." +"\n";

                // Analyze the data and maybe remove points that weren't good.
                calibration.DiscardData(new NormalizedPoint2D(0.1f, 0.1f));
                // Redo collection at the discarded point.
                Console.WriteLine("Show point on screen at ({0}, {1})", 0.1f, 0.1f);
                calibration.CollectData(new NormalizedPoint2D(0.1f, 0.1f));

                RectangleF rec2 = new RectangleF(0.1f * w, 0.1f * h, 30, 30);
                e.Graphics.FillEllipse(Brushes.Yellow, rec2);

                // Compute and apply again.
                calibrationResult = calibration.ComputeAndApply();

                Console.WriteLine("Second compute and apply returned {0} and collected at {1} points.",
                                  calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
                // textBox1.Text += "Compute and apply returned" + calibrationResult.Status + " and collected at " + calibrationResult.CalibrationPoints.Count + " points." + "\n";
                // See that you're happy with the result.
                // The calibration is done. Leave calibration mode.
                calibration.LeaveCalibrationMode();


                this.Close();
            }
            this.Close();
            //  }

            // calibrationBegin = false;
        }
Exemple #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int w = Screen.PrimaryScreen.Bounds.Width;
            int h = Screen.PrimaryScreen.Bounds.Height;


            //label1.ResetText = "Look at each dot until its color changes!";
            //label1.ForeColor = Color.White;

            //  label1.Text = "Look at each dot until its color changes!";
            RectangleF recBegin = new RectangleF(0.5f * w, 0.5f * h, 30, 30);

            e.Graphics.FillEllipse(Brushes.White, recBegin);

            /*RectangleF rec2 = new RectangleF(0.1f * w, 0.1f * h, 20, 20);
             * e.Graphics.FillEllipse(Brushes.Black, rec2);
             *
             * RectangleF rec3 = new RectangleF(0.1f * w, 0.9f * h, 20, 20);
             * e.Graphics.FillEllipse(Brushes.Black, rec3);
             *
             * RectangleF rec4 = new RectangleF(0.9f * w, 0.1f * h, 20, 20);
             * e.Graphics.FillEllipse(Brushes.Black, rec4);
             *
             * RectangleF rec5 = new RectangleF(0.9f * w, 0.9f * h, 20, 20);
             * e.Graphics.FillEllipse(Brushes.Black, rec5);*/

            if (calibrationBegin2 == 1)
            {
                //   label1.Text = "";
                e.Graphics.FillEllipse(Brushes.Yellow, recBegin);

                var calibration = new ScreenBasedCalibration(mEyeTracker);

                // Define the points on screen we should calibrate at.
                // The coordinates are normalized, i.e. (0.0f, 0.0f) is the upper left corner and (1.0f, 1.0f) is the lower right corner.
                var pta = new PointF[5];

                var pointsToCalibrate = new NormalizedPoint2D[5] {
                    new NormalizedPoint2D(0.5f, 0.5f),
                    new NormalizedPoint2D(0.1f, 0.1f),
                    new NormalizedPoint2D(0.1f, 0.9f),
                    new NormalizedPoint2D(0.9f, 0.1f),
                    new NormalizedPoint2D(0.9f, 0.9f),
                };

                // Enter calibration mode.
                calibration.EnterCalibrationMode();

                foreach (var point in pointsToCalibrate)
                {
                    // Show an image on screen where you want to calibrate.
                    Console.WriteLine("Show point on screen at ({0}, {1})", point.X, point.Y);


                    RectangleF rec = new RectangleF(point.X * w, point.Y * h, 30, 30);
                    e.Graphics.FillEllipse(Brushes.White, rec);

                    // Collect data.,,
                    CalibrationStatus status = calibration.CollectData(point);
                    // Wait a little for user to focus.
                    System.Threading.Thread.Sleep(700);

                    if (status != CalibrationStatus.Success)
                    {
                        // Try again if it didn't go well the first time.
                        // Not all eye tracker models will fail at this point, but instead fail on ComputeAndApply.
                        //vaghti cheshmo nabine ghermez mishe
                        calibration.CollectData(point);
                        e.Graphics.FillEllipse(Brushes.Red, rec);
                    }

                    if (status == CalibrationStatus.Success)
                    {
                        e.Graphics.FillEllipse(Brushes.Black, rec);
                    }
                }
                // Compute and apply the calibration.
                CalibrationResult calibrationResult = calibration.ComputeAndApply();
                Console.WriteLine("Compute and apply returned {0} and collected at {1} points.", calibrationResult.Status, calibrationResult.CalibrationPoints.Count);

                //textBox1.Text += "Compute and apply returned" + calibrationResult.Status+" and collected at " + calibrationResult.CalibrationPoints.Count+" points." +"\n";

                // Analyze the data and maybe remove points that weren't good.
                calibration.DiscardData(new NormalizedPoint2D(0.1f, 0.1f));
                // Redo collection at the discarded point.
                Console.WriteLine("Show point on screen at ({0}, {1})", 0.1f, 0.1f);
                calibration.CollectData(new NormalizedPoint2D(0.1f, 0.1f));

                RectangleF rec2 = new RectangleF(0.1f * w, 0.1f * h, 30, 30);
                e.Graphics.FillEllipse(Brushes.Yellow, rec2);

                // Compute and apply again.
                calibrationResult = calibration.ComputeAndApply();

                Console.WriteLine("Second compute and apply returned {0} and collected at {1} points.",
                                  calibrationResult.Status, calibrationResult.CalibrationPoints.Count);
                // textBox1.Text += "Compute and apply returned" + calibrationResult.Status + " and collected at " + calibrationResult.CalibrationPoints.Count + " points." + "\n";
                // See that you're happy with the result.
                // The calibration is done. Leave calibration mode.
                calibration.LeaveCalibrationMode();

                calibrationBegin2 = 0;
                this.Close();
            }

            // calibrationBegin = false;
        }