Пример #1
0
        private System.Windows.Point RotateEye(System.Windows.Point eye, GenPositionData.TransformSample trans)
        {
            double theta = trans.ThetaRad;

            System.Windows.Point newCentre = new System.Windows.Point();
            newCentre.X = (eye.X - 0.5) * Math.Cos(theta) - (0.5 - eye.Y) * Math.Sin(theta) + 0.5 - trans.X;
            newCentre.Y = 0.5 - ((0.5 - eye.Y) * Math.Cos(theta) + (eye.X - 0.5) * Math.Sin(theta)) - trans.Y;
            return(newCentre);
        }
Пример #2
0
 public Form1()
 {
     InitializeComponent();
     pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
     pictureBox2.SizeMode = PictureBoxSizeMode.AutoSize;
     _pen       = new Pen(Color.Red, 2);
     _eyeMark   = 0.06;
     _eyeMark2  = _eyeMark / 2.0;
     _transform = new GenPositionData.TransformSample();
 }
Пример #3
0
        /// <summary>
        /// Create a face by rotating the input face theta degrees
        /// </summary>
        /// <param name="face">FaceS to rotate</param>
        /// <param name="theta">Rotation in degrees</param>
        /// <returns></returns>
        private Bitmap CreateFaceTxfm(FaceData face, GenPositionData.TransformSample trans)
        {
            if (null == face)
            {
                return(null);
            }


            Bitmap     photoBitmap  = new Bitmap(face.Filename);
            Rectangle  rect         = new Rectangle(0, 0, photoBitmap.Width, photoBitmap.Height);
            BitmapData photoData    = photoBitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int        bytePerPixel = 3;
            int        totBytes     = photoData.Height * photoData.Stride;

            byte [] dataPixs = new byte [totBytes];
            System.Runtime.InteropServices.Marshal.Copy(photoData.Scan0, dataPixs, 0, totBytes);

            System.Windows.Rect destRect = face.FaceWindowsRect;
            destRect.X = 0.0;
            destRect.Y = 0.0;
            System.Windows.Rect srcRect = new System.Windows.Rect(0, 0, photoBitmap.Width, photoBitmap.Height);

            Bitmap faceBitmap = new Bitmap(face.faceRect.Width, face.faceRect.Height, photoData.PixelFormat);

            rect.Width  = face.faceRect.Width;
            rect.Height = face.faceRect.Height;
            BitmapData faceData = faceBitmap.LockBits(rect, ImageLockMode.ReadWrite, photoData.PixelFormat);

            byte[] facePixs;

            if (null == trans)
            {
                facePixs = ImageUtils.DoAffine(dataPixs, srcRect, bytePerPixel, photoData.Stride,
                                               destRect, destRect, faceData.Stride, face.AffineMat);
            }
            else
            {
                facePixs = ImageUtils.ExtractNormalizeFace(dataPixs, srcRect, bytePerPixel, photoData.Stride,
                                                           face.FaceWindowsRect, destRect, faceData.Stride, trans);
            }
            photoBitmap.UnlockBits(photoData);


            System.Runtime.InteropServices.Marshal.Copy(facePixs, 0, faceData.Scan0, facePixs.Length);
            faceBitmap.UnlockBits(faceData);

            return(faceBitmap);
        }
Пример #4
0
 private void RotateRecoEyes(FaceData item, GenPositionData.TransformSample trans)
 {
     SetRecoEyes(ref item, RotateEye(item.TrueLeftEye, trans), RotateEye(item.TrueRightEye, trans));
 }