Example #1
0
        public TrackData()
        {
            eyesROI = new Rectangle();
            leftROI = new Rectangle();
            rightROI = new Rectangle();

            pupilDataLeft = new PupilData();
            pupilDataRight = new PupilData();

            glintDataLeft = new GlintData();
            glintDataRight = new GlintData();

            calibrationDataLeft = new CalibrationData();
            calibrationDataRight = new CalibrationData();

            gazeDataRaw = new GTGazeData();
            gazeDataSmoothed = new GTGazeData();

            //eyeMovement = new GazeTrackingLibrary.EyeMovement.Classifier();

            eyesDetected = false;
            eyeDetected = false;
            pupilLeftDetected = false;
            pupilRightDetected = false;
            glintsLeftDetected = false;
            glintsRightDetected = false;
        }
Example #2
0
        public override bool Calibrate()
        {
            if (NumImages == 0)
            {
                //throw new ArgumentException("numImages=0 in Calibrate()");
                return false;
            }

            try
            {
                CalibrationDataLeft = new CalibrationData();
                CalibrationDataRight = new CalibrationData();

                var targets = new Matrix<double>(NumImages, 3);
                var designMatrixLeft = new Matrix<double>(NumImages, 6);
                var designMatrixRight = new Matrix<double>(NumImages, 6);

                var rowLeft = new double[6];
                var rowRight = new double[6];

                int k = 0;

                foreach (CalibrationTarget ct in CalibrationTargets)
                {
                    for (int j = 0; j < ct.NumImages; j++)
                    {
                        targets[k, 0] = ct.targetCoordinates.X;
                        targets[k, 1] = ct.targetCoordinates.Y;

                        double xLeft = ct.pupilCentersLeft[j].X;
                        double yLeft = ct.pupilCentersLeft[j].Y;

                        rowLeft[0] = 1;
                        rowLeft[1] = xLeft;
                        rowLeft[2] = yLeft;
                        rowLeft[3] = xLeft*yLeft;
                        rowLeft[4] = xLeft*xLeft;
                        rowLeft[5] = yLeft*yLeft;

                        for (int r = 0; r < 6; r++)
                        {
                            designMatrixLeft[k, r] = rowLeft[r];
                        }

                        if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                        {
                            double xRight = ct.pupilCentersRight[j].X;
                            double yRight = ct.pupilCentersRight[j].Y;

                            rowRight[0] = 1;
                            rowRight[1] = xRight;
                            rowRight[2] = yRight;
                            rowRight[3] = xRight*yRight;
                            rowRight[4] = xRight*xRight;
                            rowRight[5] = yRight*yRight;

                            for (int r = 0; r < 6; r++)
                            {
                                designMatrixRight[k, r] = rowRight[r];
                            }
                        }
                        k++;
                    }
                }

                CalibrationDataLeft.CoeffsX = new Matrix<double>(6, 1);
                CalibrationDataLeft.CoeffsY = new Matrix<double>(6, 1);
                CalibrationDataLeft.CoeffsX = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(0));
                CalibrationDataLeft.CoeffsY = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(1));

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                {
                    CalibrationDataRight.CoeffsX = new Matrix<double>(6, 1);
                    CalibrationDataRight.CoeffsY = new Matrix<double>(6, 1);
                    CalibrationDataRight.CoeffsX = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(0));
                    CalibrationDataRight.CoeffsY = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(1));
                }

                // For each image we calculate the estimated gaze coordinates
                foreach (CalibrationTarget ct in CalibrationTargets)
                {
                    // We might be recalibrating so clear estGazeCoords first
                    ct.estimatedGazeCoordinatesLeft.Clear();
                    ct.estimatedGazeCoordinatesRight.Clear();

                    for (int j = 0; j < ct.NumImages; j++)
                    {
                        PupilCenterLeft = ct.pupilCentersLeft[j];
                        ct.estimatedGazeCoordinatesLeft.Add(GetGazeCoordinates(EyeEnum.Left));

                        if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                        {
                            PupilCenterRight = ct.pupilCentersRight[j];
                            ct.estimatedGazeCoordinatesRight.Add(GetGazeCoordinates(EyeEnum.Right));
                        }
                    }

                    ct.CalculateAverageCoords();
                    ct.averageErrorLeft = Operations.Distance(ct.meanGazeCoordinatesLeft, ct.targetCoordinates);

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                        ct.averageErrorRight = Operations.Distance(ct.meanGazeCoordinatesRight, ct.targetCoordinates);
                }

                //calibrated = true;
                CalibrationDataLeft.Calibrated = true;
                CalculateAverageErrorLeft();
                CalculateDegreesLeft();

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                {
                    CalibrationDataRight.Calibrated = true;
                    CalculateAverageErrorRight();
                    CalculateDegreesRight();
                }
            }
            catch (Exception ex)
            {
                //IsCalibrated = false;
                return true; // what to do here
            }

            IsCalibrated = true;
            return IsCalibrated;

            //OnCalibrationComplete(EventArgs.Empty); // Raise event
        }
Example #3
0
        public override bool Calibrate()
        {
            if (NumImages == 0)
            {
                //throw new ArgumentException("numImages=0 in Calibrate()");
                return(false);
            }

            try
            {
                CalibrationDataLeft  = new CalibrationData();
                CalibrationDataRight = new CalibrationData();

                var targets           = new Matrix <double>(NumImages, 3);
                var designMatrixLeft  = new Matrix <double>(NumImages, 6);
                var designMatrixRight = new Matrix <double>(NumImages, 6);

                var rowLeft  = new double[6];
                var rowRight = new double[6];

                int k = 0;

                foreach (CalibrationTarget ct in CalibrationTargets)
                {
                    for (int j = 0; j < ct.NumImages; j++)
                    {
                        targets[k, 0] = ct.targetCoordinates.X;
                        targets[k, 1] = ct.targetCoordinates.Y;

                        double xLeft = ct.pupilCentersLeft[j].X;
                        double yLeft = ct.pupilCentersLeft[j].Y;

                        rowLeft[0] = 1;
                        rowLeft[1] = xLeft;
                        rowLeft[2] = yLeft;
                        rowLeft[3] = xLeft * yLeft;
                        rowLeft[4] = xLeft * xLeft;
                        rowLeft[5] = yLeft * yLeft;

                        for (int r = 0; r < 6; r++)
                        {
                            designMatrixLeft[k, r] = rowLeft[r];
                        }

                        if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                        {
                            double xRight = ct.pupilCentersRight[j].X;
                            double yRight = ct.pupilCentersRight[j].Y;

                            rowRight[0] = 1;
                            rowRight[1] = xRight;
                            rowRight[2] = yRight;
                            rowRight[3] = xRight * yRight;
                            rowRight[4] = xRight * xRight;
                            rowRight[5] = yRight * yRight;

                            for (int r = 0; r < 6; r++)
                            {
                                designMatrixRight[k, r] = rowRight[r];
                            }
                        }
                        k++;
                    }
                }

                CalibrationDataLeft.CoeffsX = new Matrix <double>(6, 1);
                CalibrationDataLeft.CoeffsY = new Matrix <double>(6, 1);
                CalibrationDataLeft.CoeffsX = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(0));
                CalibrationDataLeft.CoeffsY = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(1));

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                {
                    CalibrationDataRight.CoeffsX = new Matrix <double>(6, 1);
                    CalibrationDataRight.CoeffsY = new Matrix <double>(6, 1);
                    CalibrationDataRight.CoeffsX = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(0));
                    CalibrationDataRight.CoeffsY = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(1));
                }

                // For each image we calculate the estimated gaze coordinates
                foreach (CalibrationTarget ct in CalibrationTargets)
                {
                    // We might be recalibrating so clear estGazeCoords first
                    ct.estimatedGazeCoordinatesLeft.Clear();
                    ct.estimatedGazeCoordinatesRight.Clear();

                    for (int j = 0; j < ct.NumImages; j++)
                    {
                        PupilCenterLeft = ct.pupilCentersLeft[j];
                        ct.estimatedGazeCoordinatesLeft.Add(GetGazeCoordinates(EyeEnum.Left));

                        if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                        {
                            PupilCenterRight = ct.pupilCentersRight[j];
                            ct.estimatedGazeCoordinatesRight.Add(GetGazeCoordinates(EyeEnum.Right));
                        }
                    }

                    ct.CalculateAverageCoords();
                    ct.averageErrorLeft = Operations.Distance(ct.meanGazeCoordinatesLeft, ct.targetCoordinates);

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    {
                        ct.averageErrorRight = Operations.Distance(ct.meanGazeCoordinatesRight, ct.targetCoordinates);
                    }
                }

                //calibrated = true;
                CalibrationDataLeft.Calibrated = true;
                CalculateAverageErrorLeft();
                CalculateDegreesLeft();

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                {
                    CalibrationDataRight.Calibrated = true;
                    CalculateAverageErrorRight();
                    CalculateDegreesRight();
                }
            }
            catch (Exception ex)
            {
                //IsCalibrated = false;
                return(true); // what to do here
            }

            IsCalibrated = true;
            return(IsCalibrated);

            //OnCalibrationComplete(EventArgs.Empty); // Raise event
        }
Example #4
0
        public override bool Calibrate()
        {
            if (numOutliersRemovedLeft == 0 && numOutliersRemovedRight == 0)
                RemoveOutliers(); // Only works sometimes, tried fixing it..

            if (NumImages == 0)
            {
                //throw new ArgumentException("numImages=0 in Calibrate()");
                IsCalibrated = false;
                return false;
            }

            #region Initialize variabels

            CalibrationDataLeft = new CalibrationData();
            CalibrationDataRight = new CalibrationData();

            var targets = new Matrix<double>(NumImages, 3);
            var designMatrixLeft = new Matrix<double>(NumImages, 6);
            var designMatrixRight = new Matrix<double>(NumImages, 6);

            var rowLeft = new double[6];
            var rowRight = new double[6];

            int k = 0;

            #endregion

            #region Build matrices

            foreach (CalibrationTarget ct in CalibrationTargets)
            {
                for (int j = 0; j < ct.NumImages; j++)
                {
                    #region Left

                    if (j < ct.pupilCentersLeft.Count && j < ct.glintsLeft.Count)
                    {
                        GTPoint pupilCenterLeft = ct.pupilCentersLeft.ElementAt(j);
                        GlintConfiguration glintsLeft = ct.glintsLeft.ElementAt(j);

                        if (pupilCenterLeft != null && glintsLeft != null && glintsLeft.Count > 0)
                        {
                            targets[k, 0] = ct.targetCoordinates.X;
                            targets[k, 1] = ct.targetCoordinates.Y;

                            double xLeft = pupilCenterLeft.X - glintsLeft.AverageCenter.X;
                            double yLeft = pupilCenterLeft.Y - glintsLeft.AverageCenter.Y;

                            rowLeft[0] = 1;
                            rowLeft[1] = xLeft;
                            rowLeft[2] = yLeft;
                            rowLeft[3] = xLeft*yLeft;
                            rowLeft[4] = xLeft*xLeft;
                            rowLeft[5] = yLeft*yLeft;

                            for (int r = 0; r < 6; r++)
                                designMatrixLeft[k, r] = rowLeft[r];
                        }
                    }

                    #endregion

                    #region Right

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    {
                        if (ct.pupilCentersRight.Count - 1 > j && ct.glintsRight.Count - 1 > j)
                        {
                            GTPoint pupilCenterRight = ct.pupilCentersRight.ElementAt(j);
                            GlintConfiguration glintsRight = ct.glintsRight.ElementAt(j);

                            if (pupilCenterRight != null && glintsRight != null && glintsRight.Count > 0)
                            {
                                double xRight = pupilCenterRight.X - glintsRight.AverageCenter.X;
                                double yRight = pupilCenterRight.Y - glintsRight.AverageCenter.Y;

                                rowRight[0] = 1;
                                rowRight[1] = xRight;
                                rowRight[2] = yRight;
                                rowRight[3] = xRight*yRight;
                                rowRight[4] = xRight*xRight;
                                rowRight[5] = yRight*yRight;

                                for (int r = 0; r < 6; r++)
                                {
                                    designMatrixRight[k, r] = rowRight[r];
                                }
                            }
                        }
                    }

                    #endregion

                    k++;
                }
            }

            #endregion

            #region SolveLeastSquares

            CalibrationDataLeft.CoeffsX = new Matrix<double>(6, 1);
            CalibrationDataLeft.CoeffsY = new Matrix<double>(6, 1);
            CalibrationDataLeft.CoeffsX = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(0));
            CalibrationDataLeft.CoeffsY = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(1));

            if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
            {
                CalibrationDataRight.CoeffsX = new Matrix<double>(6, 1);
                CalibrationDataRight.CoeffsY = new Matrix<double>(6, 1);
                CalibrationDataRight.CoeffsX = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(0));
                CalibrationDataRight.CoeffsY = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(1));
            }

            #endregion

            #region Calculated est. gaze coordinates (per image)

            // For each image we calculate the estimated gaze coordinates
            foreach (CalibrationTarget ct in CalibrationTargets)
            {
                // We might be recalibrating so clear estGazeCoords first
                ct.estimatedGazeCoordinatesLeft.Clear();
                ct.estimatedGazeCoordinatesRight.Clear();

                for (int j = 0; j < ct.NumImages; j++)
                {
                    #region Left

                    if (ct.pupilCentersLeft.Count - 1 >= j && ct.glintsLeft.Count - 1 >= j)
                    {
                        var pupilCenterLeft = new GTPoint(0, 0);
                        var glintConfigLeft = new GlintConfiguration(new Blobs());

                        if (ct.pupilCentersLeft.ElementAt(j) != null)
                            pupilCenterLeft = ct.pupilCentersLeft[j];

                        if (ct.glintsLeft.ElementAt(j) != null)
                            glintConfigLeft = ct.glintsLeft[j];

                        if (pupilCenterLeft.Y != 0)
                            ct.estimatedGazeCoordinatesLeft.Add(GetGazeCoordinates(EyeEnum.Left, pupilCenterLeft,
                                                                                   glintConfigLeft));
                    }

                    #endregion

                    #region Right

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    {
                        if (ct.pupilCentersRight.Count - 1 > j && ct.glintsRight.Count - 1 > j)
                        {
                            var pupilCenterRight = new GTPoint(0, 0);
                            var glintConfigRight = new GlintConfiguration(new Blobs());

                            if (ct.pupilCentersRight.ElementAt(j) != null)
                                pupilCenterRight = ct.pupilCentersRight[j];

                            if (ct.glintsRight.ElementAt(j) != null)
                                glintConfigRight = ct.glintsRight[j];

                            if (pupilCenterRight.Y != 0)
                                ct.estimatedGazeCoordinatesRight.Add(GetGazeCoordinates(EyeEnum.Right, pupilCenterRight,
                                                                                        glintConfigRight));
                        }
                    }

                    #endregion
                }

                ct.CalculateAverageCoords();
                ct.averageErrorLeft = Operations.Distance(ct.meanGazeCoordinatesLeft, ct.targetCoordinates);

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    ct.averageErrorRight = Operations.Distance(ct.meanGazeCoordinatesRight, ct.targetCoordinates);
            }

            CalibrationDataLeft.Calibrated = true;
            CalculateAverageErrorLeft();
            CalculateDegreesLeft();

            if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
            {
                CalibrationDataRight.Calibrated = true;
                CalculateAverageErrorRight();
                CalculateDegreesRight();
            }

            #endregion

            IsCalibrated = true;
            return IsCalibrated;
        }
Example #5
0
        public override bool Calibrate()
        {
            if (numOutliersRemovedLeft == 0 && numOutliersRemovedRight == 0)
            {
                RemoveOutliers(); // Only works sometimes, tried fixing it..
            }
            if (NumImages == 0)
            {
                //throw new ArgumentException("numImages=0 in Calibrate()");
                IsCalibrated = false;
                return(false);
            }

            #region Initialize variabels

            CalibrationDataLeft  = new CalibrationData();
            CalibrationDataRight = new CalibrationData();


            var targets           = new Matrix <double>(NumImages, 3);
            var designMatrixLeft  = new Matrix <double>(NumImages, 6);
            var designMatrixRight = new Matrix <double>(NumImages, 6);

            var rowLeft  = new double[6];
            var rowRight = new double[6];

            int k = 0;

            #endregion

            #region Build matrices

            foreach (CalibrationTarget ct in CalibrationTargets)
            {
                for (int j = 0; j < ct.NumImages; j++)
                {
                    #region Left

                    if (j < ct.pupilCentersLeft.Count && j < ct.glintsLeft.Count)
                    {
                        GTPoint            pupilCenterLeft = ct.pupilCentersLeft.ElementAt(j);
                        GlintConfiguration glintsLeft      = ct.glintsLeft.ElementAt(j);

                        if (pupilCenterLeft != null && glintsLeft != null && glintsLeft.Count > 0)
                        {
                            targets[k, 0] = ct.targetCoordinates.X;
                            targets[k, 1] = ct.targetCoordinates.Y;

                            double xLeft = pupilCenterLeft.X - glintsLeft.AverageCenter.X;
                            double yLeft = pupilCenterLeft.Y - glintsLeft.AverageCenter.Y;

                            rowLeft[0] = 1;
                            rowLeft[1] = xLeft;
                            rowLeft[2] = yLeft;
                            rowLeft[3] = xLeft * yLeft;
                            rowLeft[4] = xLeft * xLeft;
                            rowLeft[5] = yLeft * yLeft;

                            for (int r = 0; r < 6; r++)
                            {
                                designMatrixLeft[k, r] = rowLeft[r];
                            }
                        }
                    }

                    #endregion

                    #region Right

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    {
                        if (ct.pupilCentersRight.Count - 1 > j && ct.glintsRight.Count - 1 > j)
                        {
                            GTPoint            pupilCenterRight = ct.pupilCentersRight.ElementAt(j);
                            GlintConfiguration glintsRight      = ct.glintsRight.ElementAt(j);

                            if (pupilCenterRight != null && glintsRight != null && glintsRight.Count > 0)
                            {
                                double xRight = pupilCenterRight.X - glintsRight.AverageCenter.X;
                                double yRight = pupilCenterRight.Y - glintsRight.AverageCenter.Y;

                                rowRight[0] = 1;
                                rowRight[1] = xRight;
                                rowRight[2] = yRight;
                                rowRight[3] = xRight * yRight;
                                rowRight[4] = xRight * xRight;
                                rowRight[5] = yRight * yRight;

                                for (int r = 0; r < 6; r++)
                                {
                                    designMatrixRight[k, r] = rowRight[r];
                                }
                            }
                        }
                    }

                    #endregion

                    k++;
                }
            }

            #endregion

            #region SolveLeastSquares

            CalibrationDataLeft.CoeffsX = new Matrix <double>(6, 1);
            CalibrationDataLeft.CoeffsY = new Matrix <double>(6, 1);
            CalibrationDataLeft.CoeffsX = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(0));
            CalibrationDataLeft.CoeffsY = Operations.SolveLeastSquares(designMatrixLeft, targets.GetCol(1));

            if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
            {
                CalibrationDataRight.CoeffsX = new Matrix <double>(6, 1);
                CalibrationDataRight.CoeffsY = new Matrix <double>(6, 1);
                CalibrationDataRight.CoeffsX = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(0));
                CalibrationDataRight.CoeffsY = Operations.SolveLeastSquares(designMatrixRight, targets.GetCol(1));
            }

            #endregion

            #region Calculated est. gaze coordinates (per image)

            // For each image we calculate the estimated gaze coordinates
            foreach (CalibrationTarget ct in CalibrationTargets)
            {
                // We might be recalibrating so clear estGazeCoords first
                ct.estimatedGazeCoordinatesLeft.Clear();
                ct.estimatedGazeCoordinatesRight.Clear();

                for (int j = 0; j < ct.NumImages; j++)
                {
                    #region Left

                    if (ct.pupilCentersLeft.Count - 1 >= j && ct.glintsLeft.Count - 1 >= j)
                    {
                        var pupilCenterLeft = new GTPoint(0, 0);
                        var glintConfigLeft = new GlintConfiguration(new Blobs());

                        if (ct.pupilCentersLeft.ElementAt(j) != null)
                        {
                            pupilCenterLeft = ct.pupilCentersLeft[j];
                        }

                        if (ct.glintsLeft.ElementAt(j) != null)
                        {
                            glintConfigLeft = ct.glintsLeft[j];
                        }

                        if (pupilCenterLeft.Y != 0)
                        {
                            ct.estimatedGazeCoordinatesLeft.Add(GetGazeCoordinates(EyeEnum.Left, pupilCenterLeft,
                                                                                   glintConfigLeft));
                        }
                    }

                    #endregion

                    #region Right

                    if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                    {
                        if (ct.pupilCentersRight.Count - 1 > j && ct.glintsRight.Count - 1 > j)
                        {
                            var pupilCenterRight = new GTPoint(0, 0);
                            var glintConfigRight = new GlintConfiguration(new Blobs());

                            if (ct.pupilCentersRight.ElementAt(j) != null)
                            {
                                pupilCenterRight = ct.pupilCentersRight[j];
                            }

                            if (ct.glintsRight.ElementAt(j) != null)
                            {
                                glintConfigRight = ct.glintsRight[j];
                            }

                            if (pupilCenterRight.Y != 0)
                            {
                                ct.estimatedGazeCoordinatesRight.Add(GetGazeCoordinates(EyeEnum.Right, pupilCenterRight,
                                                                                        glintConfigRight));
                            }
                        }
                    }

                    #endregion
                }

                ct.CalculateAverageCoords();
                ct.averageErrorLeft = Operations.Distance(ct.meanGazeCoordinatesLeft, ct.targetCoordinates);

                if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
                {
                    ct.averageErrorRight = Operations.Distance(ct.meanGazeCoordinatesRight, ct.targetCoordinates);
                }
            }

            CalibrationDataLeft.Calibrated = true;
            CalculateAverageErrorLeft();
            CalculateDegreesLeft();

            if (Settings.Instance.Processing.TrackingMode == TrackingModeEnum.Binocular)
            {
                CalibrationDataRight.Calibrated = true;
                CalculateAverageErrorRight();
                CalculateDegreesRight();
            }

            #endregion

            IsCalibrated = true;
            return(IsCalibrated);
        }