private void listBoxFiles_SelectedIndexChanged(object sender, EventArgs e) { if (listBoxFiles.SelectedIndex >= 0 && listBoxFiles.SelectedIndex < _faceData.Count) { FaceData item = _faceData[listBoxFiles.SelectedIndex]; Bitmap bitmap1 = null; Bitmap bitmap2 = null; if (false == item.DoTransform) { item.Transform.Reset(); bitmap1 = CreateFaceTxfm(item, item.Transform); if (_fileType == FaceData.FaceDataTypeEnum.FaceReco) { bitmap2 = CreateFaceTxfm(item, null); } else { bitmap2 = bitmap1; } } else { bitmap1 = CreateFaceTxfm(item, item.Transform); bitmap2 = bitmap1; } pictureBox1.Image = (Image)bitmap1; pictureBox2.Image = (Image)bitmap2; pictureBox2.Left = pictureBox1.Right + 20; } }
private void PopulateListBox(string suiteFile) { listBoxFiles.Items.Clear(); FaceDataFile suiteReader = null; try { suiteReader = new FaceDataFile(suiteFile, _fileType); } catch (Exception e) { Console.WriteLine("{0}", e.Message); } if (null == suiteReader) { return; } FaceData item = null; _faceData = new List <FaceData>(); while ((item = suiteReader.GetNext()) != null) { listBoxFiles.Items.Add(Path.GetFileName(item.Filename)); SetTrueEyes(ref item, item.TrueLeftEye, item.TrueRightEye); SetRecoEyes(ref item, item.RecoLeftEye, item.RecoRightEye); _faceData.Add(item); } suiteReader.Dispose(); }
private FaceData ReadEyeDetectFile(string filename, string line, int iLine) { FaceData item = new FaceData(filename, line, FaceData.FaceDataTypeEnum.EyeDetect); SetTrueEyes(ref item, item.TrueLeftEye, item.TrueRightEye); SetRecoEyes(ref item, item.RecoLeftEye, item.RecoRightEye); return(item); }
private void SetRecoEyes(ref FaceData item, System.Windows.Point leftEye, System.Windows.Point rightEye) { item.RecoLeftRect.X = (int)((leftEye.X - _eyeMark2) * item.faceRect.Width); item.RecoLeftRect.Width = (int)(_eyeMark * item.faceRect.Width); item.RecoLeftRect.Y = (int)((leftEye.Y - _eyeMark2) * item.faceRect.Width); item.RecoLeftRect.Height = (int)(_eyeMark * item.faceRect.Width); item.RecoRightRect.X = (int)((rightEye.X - _eyeMark2) * item.faceRect.Width); item.RecoRightRect.Width = (int)(_eyeMark * item.faceRect.Width); item.RecoRightRect.Y = (int)((rightEye.Y - _eyeMark2) * item.faceRect.Width); item.RecoRightRect.Height = (int)(_eyeMark * item.faceRect.Width); }
private void buttonRotate_Click(object sender, EventArgs e) { if (listBoxFiles.SelectedIndex >= 0 && listBoxFiles.SelectedIndex < _faceData.Count) { FaceData face = _faceData[listBoxFiles.SelectedIndex]; _transform.Theta = (double)numericUpDownTheta.Value; _transform.X = (double)numericUpDownX.Value; _transform.Y = (double)numericUpDownY.Value; _transform.SetImageSize(face.FaceWindowsRect); pictureBox2.Image = CreateFaceTxfm(face, _transform); RotateRecoEyes(_faceData[listBoxFiles.SelectedIndex], _transform); } }
private FaceData ReadFaceRecoFile(string filename, string line, int iLine) { FaceData item = new FaceData(filename, line, FaceData.FaceDataTypeEnum.FaceReco); item.NormNose.X = normNose.X * item.faceRect.Width; item.NormNose.Y = normNose.Y * item.faceRect.Height; item.NormLeftMouth.X = normLeftMouth.X * item.faceRect.Width; item.NormLeftMouth.Y = normLeftMouth.Y * item.faceRect.Height; item.NormRightMouth.X = normRightMouth.X * item.faceRect.Width; item.NormRightMouth.Y = normRightMouth.Y * item.faceRect.Height; double defaultRectSize = 10.0 / 41.0; double smallRectSize = 8.0 / 41.0; SetFeatureRectFromPoint(item.TrueLeftEye, ref item.TrueLeftRect, item.faceRect, defaultRectSize); SetFeatureRectFromPoint(item.TrueRightEye, ref item.TrueRightRect, item.faceRect, defaultRectSize); SetFeatureRectFromPointNorm(item.RecoLeftEye, ref item.RecoLeftRect, item.faceRect, defaultRectSize); SetFeatureRectFromPointNorm(item.RecoRightEye, ref item.RecoRightRect, item.faceRect, defaultRectSize); Rect destRect = new Rect(0, 0, item.faceRect.Width, item.faceRect.Height); item.AffineMat = GetFaceAffine(item.ConvertDrawingToRect(item.faceRect), item.TrueLeftEye, item.TrueRightEye, destRect, item.RecoLeftEye, item.RecoRightEye); item.Nose = TransformPoint(item.AffineMat, destRect, item.NormNose, item.ConvertDrawingToRect(item.faceRect)); SetFeatureRectFromPoint(item.Nose, ref item.NoseRect, item.faceRect, defaultRectSize); SetFeatureRectFromPointNorm(item.NormNose, ref item.NormNoseRect, item.faceRect, defaultRectSize); item.LeftMouth = TransformPoint(item.AffineMat, destRect, item.NormLeftMouth, item.ConvertDrawingToRect(item.faceRect)); SetFeatureRectFromPoint(item.LeftMouth, ref item.LeftMouthRect, item.faceRect, smallRectSize); SetFeatureRectFromPointNorm(item.NormLeftMouth, ref item.NormLeftMouthRect, item.faceRect, smallRectSize); item.RightMouth = TransformPoint(item.AffineMat, destRect, item.NormRightMouth, item.ConvertDrawingToRect(item.faceRect)); SetFeatureRectFromPoint(item.RightMouth, ref item.RightMouthRect, item.faceRect, smallRectSize); SetFeatureRectFromPointNorm(item.NormRightMouth, ref item.NormRightMouthRect, item.faceRect, smallRectSize); item.MouthRect = item.LeftMouthRect; item.MouthRect.Width = item.RightMouthRect.Right - item.LeftMouthRect.X; item.MouthRect.Height = item.RightMouthRect.Bottom - item.LeftMouthRect.Y; item.NormMouthRect = item.NormLeftMouthRect; item.NormMouthRect.Width = item.NormRightMouthRect.Right - item.NormLeftMouthRect.X; item.NormMouthRect.Height = item.NormRightMouthRect.Bottom - item.NormLeftMouthRect.Y; return(item); }
/// <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); }
private void pictureBox2_Paint(object sender, PaintEventArgs e) { if (null != _faceData && listBoxFiles.SelectedIndex >= 0) { FaceData face = _faceData[listBoxFiles.SelectedIndex]; if (_fileType == FaceData.FaceDataTypeEnum.EyeDetect) { e.Graphics.DrawEllipse(_pen, face.RecoLeftRect); e.Graphics.DrawEllipse(_pen, face.RecoRightRect); } else if (_fileType == FaceData.FaceDataTypeEnum.FaceReco) { e.Graphics.DrawRectangle(_pen, face.RecoLeftRect); e.Graphics.DrawRectangle(_pen, face.RecoRightRect); e.Graphics.DrawRectangle(_pen, face.NormNoseRect); e.Graphics.DrawRectangle(_pen, face.NormLeftMouthRect); e.Graphics.DrawRectangle(_pen, face.NormRightMouthRect); //e.Graphics.DrawRectangle(_pen, face.NormMouthRect); } } }
public FaceData GetNext() { FaceData faceData = null; if (null != _sr) { string imageFile = _sr.ReadLine(); string line = null; if (imageFile != null) { ++_lineCount; line = _sr.ReadLine(); } if (null != line && null != imageFile) { ++_lineCount; faceData = new FaceData(imageFile, line, _fileType); } } return(faceData); }
private void RotateTrueEyes(FaceData item) { SetTrueEyes(ref item, RotateEye(item.TrueLeftEye, item.Transform), RotateEye(item.TrueRightEye, item.Transform)); }
private void RotateRecoEyes(FaceData item, GenPositionData.TransformSample trans) { SetRecoEyes(ref item, RotateEye(item.TrueLeftEye, trans), RotateEye(item.TrueRightEye, trans)); }