Exemplo n.º 1
0
        //function used for the face toRecognize : called for each frame sent by the kinect
        public EigenFace(EnumIndexableCollection <FeaturePoint, PointF> toRec)
        {
            double[,] vReduce     = new double[1, data.GetLowerBound(1)];
            double[,] vReduceM    = new double[1, distanceMouth.GetLowerBound(1)];
            double[,] vReduceEyeL = new double[1, distanceEyeLeft.GetLowerBound(1)];
            double[,] vReduceEyeR = new double[1, distanceEyeRight.GetLowerBound(1)];

            double[,] distanceToRec      = new double[n, 0];
            double[,] distanceMouthToRec = new double[coupleDistanceMouth.Length, 0];
            double[,] distanceEyeLToRec  = new double[coupledistanceEyeLeft.Length, 0];
            double[,] distanceEyeRToRec  = new double[coupledistanceEyeRight.Length, 0];


            //Calculate distances for the face to recognize
            for (int i = 0; i < coupleDistanceMouth.Length; i++)
            {
                xa = toRec.ElementAt(coupleDistanceMouth[i, 0]).X;
                xb = toRec.ElementAt(coupleDistanceMouth[i, 1]).X;
                ya = toRec.ElementAt(coupleDistanceMouth[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupleDistanceMouth[i, 1] + 1).Y;
                distanceToRec[i, 0]      = distance(xa, xb, ya, yb, 0, 0);
                distanceMouthToRec[i, 0] = distance(xa, xb, ya, yb, 0, 0);
            }
            for (int i = 0; i < coupledistanceEyeLeft.Length; i++)
            {
                xa = toRec.ElementAt(coupledistanceEyeLeft[i, 0]).X;
                xb = toRec.ElementAt(coupledistanceEyeLeft[i, 1]).X;
                ya = toRec.ElementAt(coupledistanceEyeLeft[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupledistanceEyeLeft[i, 1] + 1).Y;
                distanceToRec[i, 0]      = distance(xa, xb, ya, yb, 0, 0);
                distanceMouthToRec[i, 0] = distance(xa, xb, ya, yb, 0, 0);
            }
            for (int i = 0; i < coupledistanceEyeRight.Length; i++)
            {
                xa = toRec.ElementAt(coupledistanceEyeRight[i, 0]).X;
                xb = toRec.ElementAt(coupledistanceEyeRight[i, 1]).X;
                ya = toRec.ElementAt(coupledistanceEyeRight[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupledistanceEyeRight[i, 1] + 1).Y;
                distanceToRec[i, 0]      = distance(xa, xb, ya, yb, 0, 0);
                distanceMouthToRec[i, 0] = distance(xa, xb, ya, yb, 0, 0);
            }

            //calculations for the face to recognize
            vReduce     = distanceToRec.Subtract(vectorMean, 1);
            vReduceM    = distanceMouthToRec.Subtract(vectorMeanM, 1);
            vReduceEyeL = distanceEyeLeft.Subtract(vectorMeanEyeL, 1);
            vReduceEyeR = distanceEyeRight.Subtract(vectorMeanEyeR, 1);

            vEpsilon     = eigenVectors.GetColumns(indexOflastEigenValues).Transpose().Multiply(vReduce.Transpose());
            vEpsilonM    = eigenVectorsM.GetColumns(indexOflastEigenValuesM).Transpose().Multiply(vReduceM.Transpose());
            vEpsilonEyeL = eigenVectorsEyeL.GetColumns(indexOflastEigenValuesEyeL).Transpose().Multiply(vReduceEyeL.Transpose());
            vEpsilonEyeR = eigenVectorsEyeR.GetColumns(indexOflastEigenValuesEyeR).Transpose().Multiply(vReduceEyeR.Transpose());
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method compare the face obtained by the kinect to the database of the user to display the current facial emotion
        /// </summary>
        /// <remarks>
        /// Called each second
        /// </remarks>
        /// <param name="toRec">All data about the face to recognize = coordinates of all 3D points of the face</param>
        public EigenFace3D(EnumIndexableCollection <FeaturePoint, Vector3DF> toRec)
        {
            //it is required with the library and functions we use to work on matrix and not vectors ... [n,1] is a solution of this "problem"
            double[,] distanceToRec      = new double[n3D, 1];
            double[,] distanceMouthToRec = new double[coupleDistanceMouth3D.Length, 1];
            double[,] distanceEyeLToRec  = new double[coupleDistanceEyeLeft3D.Length, 1];
            double[,] distanceEyeRToRec  = new double[coupleDistanceEyeRight3D.Length, 1];

            double[,] vReduce     = new double[1, data.GetLength(0)];
            double[,] vReduceM    = new double[1, distanceMouth.GetLength(0)];
            double[,] vReduceEyeL = new double[1, distanceEyeLeft.GetLength(0)];
            double[,] vReduceEyeR = new double[1, distanceEyeRight.GetLength(0)];
            int n = coupleDistanceMouth3D.GetLength(0);

            //Calculate distances for the face to recognize
            for (int i = 0; i < coupleDistanceMouth3D.GetLength(0); i++)
            {
                xa = toRec.ElementAt(coupleDistanceMouth3D[i, 0]).X;
                xb = toRec.ElementAt(coupleDistanceMouth3D[i, 1]).X;
                ya = toRec.ElementAt(coupleDistanceMouth3D[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupleDistanceMouth3D[i, 1] + 1).Y;
                za = toRec.ElementAt(coupleDistanceMouth3D[i, 0] + 2).Z;
                zb = toRec.ElementAt(coupleDistanceMouth3D[i, 1] + 2).Z;
                distanceToRec[i, 0]      = distance(xa, xb, ya, yb, za, zb);
                distanceMouthToRec[i, 0] = distance(xa, xb, ya, yb, za, zb);
            }
            for (int i = 0; i < coupleDistanceEyeLeft3D.GetLength(0); i++)
            {
                xa = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 0]).X;
                xb = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 1]).X;
                ya = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 1] + 1).Y;
                za = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 0] + 2).Z;
                zb = toRec.ElementAt(coupleDistanceEyeLeft3D[i, 1] + 2).Z;
                distanceToRec[n + i, 0] = distance(xa, xb, ya, yb, za, zb);
                distanceEyeLToRec[i, 0] = distance(xa, xb, ya, yb, za, zb);
            }
            n = coupleDistanceMouth3D.GetLength(0) + coupleDistanceEyeLeft3D.GetLength(0);
            for (int i = 0; i < coupleDistanceEyeRight3D.GetLength(0); i++)
            {
                xa = toRec.ElementAt(coupleDistanceEyeRight3D[i, 0]).X;
                xb = toRec.ElementAt(coupleDistanceEyeRight3D[i, 1]).X;
                ya = toRec.ElementAt(coupleDistanceEyeRight3D[i, 0] + 1).Y;
                yb = toRec.ElementAt(coupleDistanceEyeRight3D[i, 1] + 1).Y;
                za = toRec.ElementAt(coupleDistanceEyeRight3D[i, 0] + 2).Z;
                zb = toRec.ElementAt(coupleDistanceEyeRight3D[i, 1] + 2).Z;
                distanceToRec[i + n, 0] = distance(xa, xb, ya, yb, za, zb);
                distanceEyeRToRec[i, 0] = distance(xa, xb, ya, yb, za, zb);
            }

            //calculations for the face to recognize
            vReduce     = sub(distanceToRec, vectorMean);
            vReduceM    = sub(distanceMouthToRec, vectorMeanM);
            vReduceEyeL = sub(distanceEyeLeft, vectorMeanEyeL);
            vReduceEyeR = sub(distanceEyeRight, vectorMeanEyeR);
            //calculations of distances between each faces
            vEpsilon     = lastEigenVectors.Transpose().Multiply(vReduce);
            vEpsilonM    = lastEigenVectorsM.Transpose().Multiply(vReduceM);
            vEpsilonEyeL = lastEigenVectorsEyeL.Transpose().Multiply(vReduceEyeL);
            vEpsilonEyeR = lastEigenVectorsEyeR.Transpose().Multiply(vReduceEyeR);
        }