Exemple #1
0
        internal static Point3D NormalizedPoint2DToPoint3D(this NormalizedPoint2D point2D, DisplayArea displayArea)
        {
            var dx = displayArea.TopRight.Sub(displayArea.TopLeft).Mul(point2D.X);
            var dy = displayArea.BottomLeft.Sub(displayArea.TopLeft).Mul(point2D.Y);

            return(displayArea.TopLeft.Add(dx.Add(dy)));
        }
Exemple #2
0
        private void DrawPointOnForm(Graphics g, int w, int h, NormalizedPoint2D point)
        {
            int radius = 30;

            g.DrawEllipse(CalBrush, point.X * w - radius, point.Y * h - radius,
                          radius + radius, radius + radius);
        }
Exemple #3
0
        private void CalibrateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                //create calibration interface
                NormalizedPoint2D[] 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),
                };
                Form CalibrationForm = CreateCalibrationForm(pointsToCalibrate);

                IEyeTracker SelectedTracker = AvailableTrackers.ElementAt(TrackerListComboBox.SelectedIndex);
                CalibrationForm.KeyPress += (keySender, keyEvent) =>
                {
                    if (keyEvent.KeyChar == ' ')
                    {
                        Calibrate(CalibrationForm, SelectedTracker);
                    }
                };



                CalibrationForm.Show();
            }
            catch (Exception exp)
            {
                //do nothing
                Console.Write(exp);
            }
        }
Exemple #4
0
        private void MovingPoint(Graphics g, int w, int h, NormalizedPoint2D from, NormalizedPoint2D to)
        {
            float fromX           = from.X * w;
            float fromY           = from.Y * h;
            float toX             = to.X * w;
            float toY             = to.Y * h;
            float tempX           = fromX;
            float tempY           = fromY;
            float movingIntervalX = (toX - fromX) / 80;
            float movingIntervalY = (toY - fromY) / 80;
            int   radius          = 30;

            while ((toX - tempX) * movingIntervalX > 0 || (toY - tempY) * movingIntervalY > 0)
            {
                g.Clear(Color.White);
                g.DrawEllipse(CalBrush, tempX - radius, tempY - radius,
                              radius + radius, radius + radius);
                System.Threading.Thread.Sleep(10);
                tempX += movingIntervalX;
                tempY += movingIntervalY;
            }
            g.Clear(Color.White);
            g.DrawEllipse(CalBrush, toX - radius, toY - radius,
                          radius + radius, radius + radius);
        }
Exemple #5
0
 public void Draw(NormalizedPoint2D target)
 {
     if (ActivateFor(target))
     {
         var position = GetAnnotationLayer().GetLocalPosition(target, rotationAngle, isMirrored);
         transform.localPosition = position;
     }
 }
 public void Draw(NormalizedPoint2D target)
 {
     if (ActivateFor(target))
     {
         var position = GetScreenRect().GetPoint(target, rotationAngle, isMirrored);
         transform.localPosition = position;
     }
 }
        public void LeaveValidationMode()
        {
            if (State == ValidationState.Idle)
            {
                throw new InvalidOperationException("Not in validation mode");
            }

            _eyeTracker.GazeDataReceived -= OnGazeDataReceived;
            _currentPoint = null;
            State         = ValidationState.Idle;
        }
        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();
        }
        public void StartCollectingData(NormalizedPoint2D calibrationPointCoordinates)
        {
            if (State == ValidationState.Collecting)
            {
                throw new InvalidOperationException("Already in collecting data state");
            }

            _currentPoint = calibrationPointCoordinates;
            _timeKeeper.Restart();
            State = ValidationState.Collecting;
        }
Exemple #10
0
        private void ConnectToEyeTracker()
        {
            var eyeTracker = EyeTrackingOperations.FindAllEyeTrackers().FirstOrDefault();

            Console.WriteLine("Found eye tracker {0}", eyeTracker.Address);

            var calibrationValidation = new ScreenBasedCalibrationValidation(eyeTracker);

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

            calibrationValidation.EnterValidationMode();

            foreach (var point in points)
            {
                Console.WriteLine("Collecting for point {0}, {1}", point.X, point.Y);

                calibrationValidation.StartCollectingData(point);
                while (calibrationValidation.State == ScreenBasedCalibrationValidation.ValidationState.CollectingData)
                {
                    System.Threading.Thread.Sleep(25);
                }
            }

            var result = calibrationValidation.Compute();

            Console.WriteLine(calibrationValidation);
            calibrationValidation.LeaveValidationMode();


            // mogucnost 2

            /*
             * var host = new Host();
             * var gazePointDataStream = host.Streams.CreateGazePointDataStream();
             * gazePointDataStream.GazePoint((gazePointX, gazePointY, _) => Console.WriteLine("X: {0} Y:{1}", gazePointX, gazePointY));
             */
        }
        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();
        }
 public CalibrationValidationPoint(
     NormalizedPoint2D coordinates,
     float accuracyLeftEye,
     float precisionLeftEye,
     float accuracyRightEye,
     float precisionRightEye,
     float precisionLeftEyeRMS,
     float precisionRightEyeRMS,
     bool timedOut,
     GazeDataEventArgs[] gazeData)
 {
     Coordinates          = coordinates;
     AccuracyLeftEye      = accuracyLeftEye;
     PrecisionLeftEye     = precisionLeftEye;
     AccuracyRightEye     = accuracyRightEye;
     PrecisionRightEye    = precisionRightEye;
     PrecisionLeftEyeRMS  = precisionLeftEyeRMS;
     PrecisionRightEyeRMS = precisionRightEyeRMS;
     TimedOut             = timedOut;
     GazeData             = gazeData;
 }
        public void DiscardData(NormalizedPoint2D calibrationPointCoordinates)
        {
            if (State == ValidationState.Idle)
            {
                throw new InvalidOperationException("Not in validation mode. No points to discard.");
            }

            lock (_lock)
            {
                if (_dataMap == null)
                {
                    throw new ArgumentException("Attempt to discard non-collected point.");
                }

                var count = _dataMap.Count;

                _dataMap = _dataMap.Where(kv => kv.Key != calibrationPointCoordinates).ToList();

                if (count == _dataMap.Count)
                {
                    throw new ArgumentException("Attempt to discard non-collected point.");
                }
            }
        }
        /// <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 #15
0
 /// <summary>
 ///   Get the coordinates represented by <paramref name="point2d" /> in local coordinate system.
 /// </summary>
 /// <param name="rectTransform">
 ///   <see cref="RectTransform" /> to be used for calculating local coordinates
 /// </param>
 /// <param name="imageRotation">Counterclockwise rotation angle of the input image</param>
 /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
 public static Vector3 GetLocalPosition(this RectTransform rectTransform, NormalizedPoint2D point2d, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
 {
     return(GetLocalPositionNormalized(rectTransform, point2d.X, point2d.Y, imageRotation, isMirrored));
 }
        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;
        }
 /// <summary>
 ///   Get the coordinates represented by <paramref name="point2d" /> in the local coordinate system.
 /// </summary>
 /// <param name="rectangle">Rectangle to get a point inside</param>
 /// <param name="imageRotation">
 ///   Counterclockwise rotation angle of the input image in the image coordinate system.
 ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
 /// </param>
 /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
 public static Vector3 GetPoint(this UnityEngine.Rect rectangle, NormalizedPoint2D point2d, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
 {
     return(ImageNormalizedToPoint(rectangle, point2d.X, point2d.Y, imageRotation, isMirrored));
 }
Exemple #18
0
 private Point ToPoint(NormalizedPoint2D point)
 {
     return(new Point(PositionToWidth(point.X), PositionToHeight(point.Y)));
 }
Exemple #19
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 #20
0
 /// <summary>
 /// Convert <see cref="NormalizedPoint2D"/> to <see cref="Vector2"/> without modification.
 /// </summary>
 /// <param name="value">The <see cref="NormalizedPoint2D"/> value</param>
 /// <returns>The <see cref="Vector3"/> converted value.</returns>
 public static Vector2 ToVector2(this NormalizedPoint2D value)
 {
     return(new Vector2(value.X, value.Y));
 }
Exemple #21
0
 internal static double Magnitude(this NormalizedPoint2D vec)
 {
     return(Magnitude(vec.X, vec.Y));
 }
Exemple #22
0
 private Vector3 Tobii_Point2D_to_Vector2D(NormalizedPoint2D point2d)
 {
     return(new Vector2(point2d.X, point2d.Y));
 }
Exemple #23
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;
        }
Exemple #24
0
 /// <summary>
 /// Get the length of the vector.
 /// </summary>
 /// <param name="vector">The vector.</param>
 /// <returns>The length (magnitude) of the vector.</returns>
 public static double Magnitude(this NormalizedPoint2D vector)
 {
     return(Magnitude(vector.X, vector.Y));
 }