예제 #1
0
        private double[,] GetFaceAffine(Rect origRect, Point origLeftEye, Point origRightEye, Rect targetRect, Point targetLeftEye, Point targetRightEye)
        {
            // Step 1 - Construct the affine transformation
            // Find mapping between orig and desired EyePosAsMatrix locations + a
            // fake point located at right angles to the vector joing the two eyes
            //INumArray<float> origMat = ArrFactory.FloatArray(3, 2);
            //INumArray<float> targetMat = ArrFactory.FloatArray(3, 3);
            INumArray <float> targetMat = ArrFactory.FloatArray(3, 2);
            INumArray <float> origMat   = ArrFactory.FloatArray(3, 3);

            FaceSortUI.ImageUtils.EyePosAsMatrix(origRect, origLeftEye, origRightEye, ref origMat);
            FaceSortUI.ImageUtils.EyePosAsMatrix(targetRect, targetLeftEye, targetRightEye, ref targetMat);
            //targetMat[0, 2] = 1.0F;
            //targetMat[1, 2] = 1.0F;
            //targetMat[2, 2] = 1.0F;
            //SVDFloat svd = new SVDFloat(targetMat);
            //INumArray<float> sss = svd.Solve(origMat);
            origMat[0, 2] = 1.0F;
            origMat[1, 2] = 1.0F;
            origMat[2, 2] = 1.0F;
            SVDFloat          svd = new SVDFloat(origMat);
            INumArray <float> sss = svd.Solve(targetMat);
            INumArray <float> mmm = (INumArray <float>)sss.Transpose();

            double[,] affineMat = ArrFactory.DoubleArray(mmm).ToArray();

            return(affineMat);
        }
예제 #2
0
        /// <summary>
        /// The function to calculate the distance matrix of the elements listed in frontUIData
        /// </summary>
        /// <param name="frontUIData">front-backend Data Exchange</param>
        public void RankOneDistance(DataExchange frontUIData)
        {
            ParseConfig(frontUIData);
            string leftMat  = m_strLeftMatFileName;
            string rightMat = m_strRightMatFileName;

            _leftMatrix  = ArrFactory.DoubleArray(leftMat);
            _rightMatrix = ArrFactory.DoubleArray(rightMat);

            List <INumArray <double> > listImgVec = RankOneProjImgList(frontUIData);
            int nEl = listImgVec.Count;

            double[,] matrixDistance = new double[nEl, nEl];

            for (int i = 0; i < nEl; i++)
            {
                for (int j = i; j < nEl; j++)
                {
                    matrixDistance[i, j] = (listImgVec[i].Sub(listImgVec[j])).Magnitude();
                    matrixDistance[j, i] = matrixDistance[i, j];
                }
            }

            frontUIData.DistanceMatrix = matrixDistance;
        }
예제 #3
0
        /// <summary>
        /// Extract a normalized face from an input image. Normalization is done
        /// by ensuring that the eye positions in the original image
        /// map to the specified position in the face image. The input
        /// inage is assumed to be 1 byte per channel. Steps involved
        /// 1. Construct an affine mapping from Destination to original eye location
        /// 2. Fill in the destination image using the mapping
        /// </summary>
        /// <param name="origImage">Input image as a byte array</param>
        /// <param name="origRect">Size of the original image</param>
        /// <param name="origLeftEye">Left eye location in source image</param>
        /// <param name="origRightEye">Right eye location in source</param>
        /// <param name="bytePerPix"># bytes per Pixel in original image.Since we assume 1 byte per channel this is same as # channels Face is constructed with same</param>
        /// <param name="faceRect">Desired face size</param>
        /// <param name="faceLeftEye">Desired left eye location in face</param>
        /// <param name="faceRightEye">Desired right eye loc in face</param>
        /// <returns>Images array representing the colour plane of extracted face</returns>
        static public Image[] ExtractNormalizeFace(Image[] origImage, Rect origRect, Point origLeftEye, Point origRightEye, int bytePerPix,
                                                   Rect faceRect, Point faceLeftEye, Point faceRightEye)
        {
            // Sanity check eye location
            if (false == origRect.Contains(origLeftEye) || false == origRect.Contains(origRightEye))
            {
                return(null);
            }

            // Step 1 - Construct the affine transformation
            // Find mapping between orig and desired EyePosAsMatrix locations + a
            // fake point located at right angles to the vector joing the two eyes
            INumArray <float> origMat = ArrFactory.FloatArray(3, 2);
            INumArray <float> faceMat = ArrFactory.FloatArray(3, 3);

            EyePosAsMatrix(origRect, origLeftEye, origRightEye, ref origMat);
            EyePosAsMatrix(faceRect, faceLeftEye, faceRightEye, ref faceMat);
            faceMat[0, 2] = 1.0F;
            faceMat[1, 2] = 1.0F;
            faceMat[2, 2] = 1.0F;
            SVDFloat          svd = new SVDFloat(faceMat);
            INumArray <float> sss = svd.Solve(origMat);
            INumArray <float> mmm = (INumArray <float>)sss.Transpose();

            double [,] affineMat = ArrFactory.DoubleArray(mmm).ToArray();

            return(TransformImage(origImage, origRect, faceRect, affineMat, bytePerPix));
        }
예제 #4
0
        /// <summary>
        /// place the coordinates to more efficiently use the screen
        /// space based on their orders in both x and y directions
        /// </summary>
        /// <param name="arrData">input data array</param>
        /// <returns></returns>
        private double[,] RMapData2Screen(double[,] arrData)
        {
            INumArray <double> shoArrData = ArrFactory.DoubleArray(arrData);
            INumArray <double> shoArrDataSorted;
            int nEl  = shoArrData.size0;
            int nDim = shoArrData.size1;

            INumArray <int> shoArrInd = ArrFactory.IntArray(nEl, nDim);

            shoArrDataSorted = shoArrData.SortIndex(1, out shoArrInd);

            double[] arrCellStep = new double[nDim];
            double[] arrCurCoord = new double[nDim];
            double[,] arrNewData = new double[nEl, nDim];

            int i, j;
            int index;

            for (i = 0; i < nDim; i++)
            {
                arrCellStep[i] = (double)((_maxCoord[i] - 10) / nEl);
                arrCurCoord[i] = 5.0;
            }

            for (i = 0; i < nEl; i++)
            {
                for (j = 0; j < nDim; j++)
                {
                    index = shoArrInd[i, j];
                    arrNewData[index, j] = arrCurCoord[j];
                    arrCurCoord[j]      += arrCellStep[j];
                }
            }

            return(MapData2Screen(arrNewData));
        }
 public void InsertCmdItems(INumArray pCmds, INumArray pInsertPos, int nFlags = 0, IUIX_CmdMenu pSubMenu = null)
 {
 }
예제 #6
0
        /// <summary>
        /// Fill in a 2x2 matrix representation of eye positions with
        /// respect centre of the image. Beside the two eye positions  trick is used
        /// to create a third point which is a right angles to teh vector left -> right eye
        /// </summary>
        /// <param name="width">Image width</param>
        /// <param name="height">Image height</param>
        /// <param name="leftEye">Absolute position of left eye</param>
        /// <param name="rightEye">Absolute pos of right eye</param>
        /// <param name="mat">Filled in 2x2 matrix</param>
        static public void EyePosAsMatrix(Rect imageRect, Point leftEye, Point rightEye, ref INumArray <float> mat)
        {
            double cx = imageRect.Width / 2.0;
            double cy = imageRect.Height / 2.0;

            mat[0, 0] = (float)(leftEye.X - cx);
            mat[0, 1] = (float)(leftEye.Y - cy);

            mat[1, 0] = (float)(rightEye.X - cx);
            mat[1, 1] = (float)(rightEye.Y - cy);

            float dx = mat[1, 0] - mat[0, 0];
            float dy = mat[1, 1] - mat[0, 1];

            // Trick.  You need to specify 3 points in correspondance to
            // determine a GLR matrix.  This is a *fake* point which is lies in a RIGHT TRIAGLE
            // with the left and right eye.  You do the same thing with both the source and
            // target points.
            mat[2, 0] = mat[0, 0] - dy;
            mat[2, 1] = mat[0, 1] + dx;
        }
예제 #7
0
 public void InsertCmdItems(INumArray pCmds, INumArray pInsertPos, int nFlags = 0, IUIX_CmdMenu pSubMenu = null)
 {
     throw new NotImplementedException();
 }