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();
        }
        /// <summary>
        /// Calibrates the Screen Based Tobii Eye Tracker using a Windows Form
        /// Based on http://devtobiipro.azurewebsites.net/tobii.research/dotnet/reference/1.7.2.7-alpha-g369155c3/class_tobii_1_1_research_1_1_screen_based_calibration.html
        /// </summary>
        /// <returns></returns>
        public override async Task <ApiResponseData> CalibrateEyeTrackerAsync()
        {
            //EyeTracker == null ? new ApiResponseData { Message = "No connection to an eye tracker has been established. Connect to an eye tracker first." } : null;

            throw new NotImplementedException();
            var calibration = new ScreenBasedCalibration(EyeTracker);
            await calibration.EnterCalibrationModeAsync();

            // 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),
            };

            // Display Windows Form for Calibration Drawing
            CalibrationForm calibrationForm = new CalibrationForm();

            calibrationForm.Show();

            System.Threading.Thread.Sleep(3000);

            // Get screen resolution
            Screen myScreen   = Screen.FromControl(calibrationForm);
            float  screenResX = myScreen.WorkingArea.Width;
            float  screenResY = myScreen.WorkingArea.Height;

            // Collect data.
            foreach (var point in pointsToCalibrate)
            {
                // Get screen coodrinates from normalized coordinates
                float x = point.X * screenResX;
                float y = point.Y * screenResY;

                // Show an image on screen where you want to calibrate.
                Console.WriteLine("Show point on screen from UI thread at ({0}, {1})", x, y);

                calibrationForm.Paint += (sender, e) =>
                {
                    e.Graphics.DrawEllipse(Pens.Red, x, y, 100, 100);
                };

                // Wait a little for user to focus.
                System.Threading.Thread.Sleep(700);
                // Collect data.
                CalibrationStatus status = await calibration.CollectDataAsync(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 ComputeAndApplyAsync.
                    await calibration.CollectDataAsync(point);
                }
            }
            // Compute and apply the calibration.
            CalibrationResult calibrationResult = await calibration.ComputeAndApplyAsync();

            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 from UI thread at ({0}, {1})", 0.1f, 0.1f);
            await calibration.CollectDataAsync(new NormalizedPoint2D(0.1f, 0.1f));

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

            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.
            await calibration.LeaveCalibrationModeAsync();
        }
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();
        }
Exemple #4
0
        /// <summary>
        /// The thread function that calls the blocking calibration methods.
        /// </summary>
        private void ThreadFunction()
        {
            var eyeTracker = EyeTrackerIF;

            if (eyeTracker == null)
            {
                return;
            }

            Running = true;

            // Create the calibration object.
            ScreenBasedCalibration screenBasedCalibration = null;
            HMDBasedCalibration    hmdBasedCalibration    = null;

            if (ScreenBased)
            {
                screenBasedCalibration = new ScreenBasedCalibration(eyeTracker);
            }
            else
            {
                hmdBasedCalibration = new HMDBasedCalibration(eyeTracker);
            }

            // Find out how long the calls took using a stopwatch.
            var stopWatch = new System.Diagnostics.Stopwatch();

            // Handle the calibration commands.
            while (Running)
            {
                var currentResult = MethodResult.CurrentResult;
                stopWatch.Reset();
                stopWatch.Start();

                if (currentResult == null)
                {
                    Thread.Sleep(25);
                }
                else
                {
                    switch (currentResult.Command)
                    {
                    case MethodResult.CommandType.Invalid:
                        Thread.Sleep(25);
                        break;

                    case MethodResult.CommandType.Enter:
                        if (screenBasedCalibration != null)
                        {
                            screenBasedCalibration.EnterCalibrationMode();
                        }
                        else
                        {
                            hmdBasedCalibration.EnterCalibrationMode();
                        }

                        stopWatch.Stop();
                        currentResult.Finished(CalibrationStatus.Success, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Collect:
                        var collectResult = screenBasedCalibration != null?
                                            screenBasedCalibration.CollectData(MethodResult.CurrentPoint) :
                                                hmdBasedCalibration.CollectData(MethodResult.CurrentPoint);

                        stopWatch.Stop();
                        currentResult.Finished(collectResult, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Compute:
                        CalibrationStatus status = screenBasedCalibration != null?
                                                   screenBasedCalibration.ComputeAndApply().Status:
                                                   hmdBasedCalibration.ComputeAndApply().Status;

                        stopWatch.Stop();
                        currentResult.Finished(status, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    case MethodResult.CommandType.Leave:
                        if (screenBasedCalibration != null)
                        {
                            screenBasedCalibration.LeaveCalibrationMode();
                        }
                        else
                        {
                            hmdBasedCalibration.LeaveCalibrationMode();
                        }

                        stopWatch.Stop();
                        currentResult.Finished(CalibrationStatus.Success, (int)stopWatch.ElapsedMilliseconds);
                        break;

                    default:
                        Thread.Sleep(25);
                        break;
                    }
                }
            }

            if (hmdBasedCalibration != null)
            {
                hmdBasedCalibration.Dispose();
            }

            if (screenBasedCalibration != null)
            {
                screenBasedCalibration.Dispose();
            }
        }
Exemple #5
0
        private async void Calibrate()
        {
            ClearSurface();
            // Create a calibration object.
            var calibration = new ScreenBasedCalibration(_tracker);
            // Enter calibration mode.
            await calibration.EnterCalibrationModeAsync();

            // 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[]
            {
                new NormalizedPoint2D(0.5f, 0.5f),
                new NormalizedPoint2D(0.2f, 0.5f),
                new NormalizedPoint2D(0.8f, 0.5f),
                new NormalizedPoint2D(0.5f, 0.2f),
                new NormalizedPoint2D(0.5f, 0.8f),
            };

            // Collect data.
            foreach (var point in pointsToCalibrate)
            {
                // Show an image on screen where you want to calibrate.

                DrawCircle(ToPoint(point));
                // Wait a little for user to focus.
                System.Threading.Thread.Sleep(1000);
                // Collect data.
                var status = await calibration.CollectDataAsync(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.
                    await calibration.CollectDataAsync(point);
                }

                ClearSurface();
            }

            // Compute and apply the calibration.
            var calibrationResult = await calibration.ComputeAndApplyAsync();

            var drawErrorCount = 0;

            foreach (var point in calibrationResult.CalibrationPoints)
            {
                var pointPosition = ToPoint(point.PositionOnDisplayArea);
                DrawCircle(pointPosition, _grayBrush);
                foreach (var sample in point.CalibrationSamples)
                {
                    var leftPosition  = sample.LeftEye.PositionOnDisplayArea;
                    var rightPosition = sample.RightEye.PositionOnDisplayArea;
                    var leftValidity  = sample.LeftEye.Validity == CalibrationEyeValidity.ValidAndUsed;
                    var rightValidity = sample.RightEye.Validity == CalibrationEyeValidity.ValidAndUsed;
                    var leftPoint     = ToPoint(leftPosition);
                    var rightPoint    = ToPoint(rightPosition);

                    if (double.IsNaN(leftPoint.X) || double.IsNaN(leftPoint.Y))
                    {
                        drawErrorCount++;
                    }
                    else
                    {
                        DrawLine(pointPosition, leftPoint, leftValidity ? _blueBrush : _redBrush);
                    }

                    if (double.IsNaN(rightPoint.X) || double.IsNaN(rightPoint.Y))
                    {
                        drawErrorCount++;
                    }
                    else
                    {
                        DrawLine(pointPosition, rightPoint, rightValidity ? _greenBrush : _redBrush);
                    }
                }
            }

            LegendPanel.Visibility = Visibility.Visible;
            _status = Status.CalibrationCompleted;
            MessageLabel.Content    = "Калибровка завершена. Нажмите \"Пробел\" для визуализации";
            MessageLabel.Visibility = Visibility.Visible;

            if (drawErrorCount > 0)
            {
                MessageBox.Show($"{drawErrorCount} points were not been drawn");
            }

            await calibration.LeaveCalibrationModeAsync();
        }
        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 #7
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;
        }