예제 #1
0
        private void choosePic_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            var img = Damany.Util.Extensions.MiscHelper.FromFileBuffered(this.openFileDialog1.FileName);

            this.ipl = OpenCvSharp.IplImage.FromBitmap((Bitmap)img);

            var fs  = new FaceProcessingWrapper.FaceSpecification();
            var suc = _faceComparer.CalcFeature(this.ipl, fs);

            if (!suc)
            {
                MessageBox.Show("人像不满足比对要求,请重新选择人像。",
                                this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.targetPic.Image = img;


            this.targetPic.Invalidate();
            this.compareButton.Enabled = true;
        }
예제 #2
0
        void CompareFaces(object result)
        {
            var collections = ((ICollection[])result)[0];

            var targetFs = new FaceProcessingWrapper.FaceSpecification();

            _faceComparer.CalcFeature(OpenCvSharp.IplImage.FromBitmap((Bitmap)this.targetPic.Image), targetFs);

            this.RunInUIThread(() =>
            {
                repositoryItemProgressBar1.Maximum = collections.Count;
                this.ClearFaceList();
            });

            int count = 0;

            foreach (Damany.PortraitCapturer.DAL.DTO.Portrait face in collections)
            {
                _cts.Token.ThrowIfCancellationRequested();

                var curPortrait = face;
                var curFaceImg  = curPortrait.ImageCopy;
                var clone       = AForge.Imaging.Image.Clone((Bitmap)curFaceImg);
                this.currentPic.RunInUIThread(() =>
                {
                    this.currentPic.Image = (Image)clone;
                    currentPic.Refresh();
                });

                var curFs  = new FaceProcessingWrapper.FaceSpecification();
                var clone2 = AForge.Imaging.Image.Clone((Bitmap)curFaceImg);
                var suc    = _faceComparer.CalcFeature(OpenCvSharp.IplImage.FromBitmap((Bitmap)clone2), curFs);
                ((IDisposable)clone2).Dispose();
                if (suc)
                {
                    var sim = _faceComparer.CmpFace(targetFs, curFs);
                    if (sim > Interlocked.Read(ref _currentAccuracy))
                    {
                        var clone3 = AForge.Imaging.Image.Clone((Bitmap)curFaceImg);
                        this.galleryControl1.RunInUIThread(() =>
                        {
                            var item = new GalleryItem((Image)clone3,
                                                       curPortrait.CaptureTime.ToShortDateString(),
                                                       curPortrait.CaptureTime.ToShortTimeString());
                            item.Hint = curPortrait.CaptureTime.ToString();
                            this.galleryControl1.Gallery.Groups[0].Items.Add(item);
                        });
                    }
                }

                var c = ++count;
                this.RunInUIThread(() =>
                {
                    progressBar.EditValue = c;
                    var msg         = string.Format("已比对: {0}, 待比对: {1}", c, collections.Count - c);
                    counter.Caption = msg;
                });
            }
        }
        private void addNewTarget_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                _waitForm.Show();
                _waitForm.Caption = "正在计算特征值...";

                var img = OpenCvSharp.IplImage.FromFile(openFileDialog1.FileName);
                var fs  = new FaceProcessingWrapper.FaceSpecification();
                var suc = _faceComparer.CalcFeature(img, fs);
                _waitForm.Hide();
                if (!suc)
                {
                    _messageBoxService.ShowError("人像不满足比对要求,请重新选择人像。");
                    return;
                }

                var target = new TargetPerson(_uow);
                target.EyeBrowShape  = fs.EyebrowShape;
                target.EyebrowRatio  = fs.EyebrowRatio;
                target.FeaturePoints = fs.Features;
                var path = System.IO.Path.Combine(Properties.Settings.Default.OutputPath,
                                                  @"TargetFeature\" + Guid.NewGuid() + ".txt");
                var dir = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                target.FeatureFilePath = path;
                var imgPath = path.Replace(".txt", ".jpg");
                img.SaveImage(imgPath);
                target.ImagePath = imgPath;

                var item = AddGalleryItem(img.ToBitmap());
                item.Tag = target;
                _isDirty = true;
            }
        }
        private void addNewTarget_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                _waitForm.Show();
                _waitForm.Caption = "正在计算特征值...";

                var img = OpenCvSharp.IplImage.FromFile(openFileDialog1.FileName);
                var fs = new FaceProcessingWrapper.FaceSpecification();
                var suc = _faceComparer.CalcFeature(img, fs);
                _waitForm.Hide();
                if (!suc)
                {
                    _messageBoxService.ShowError("人像不满足比对要求,请重新选择人像。");
                    return;
                }

                var target = new TargetPerson(_uow);
                target.EyeBrowShape = fs.EyebrowShape;
                target.EyebrowRatio = fs.EyebrowRatio;
                target.FeaturePoints = fs.Features;
                var path = System.IO.Path.Combine(Properties.Settings.Default.OutputPath,
                                                  @"TargetFeature\" + Guid.NewGuid() + ".txt");
                var dir = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                target.FeatureFilePath = path;
                var imgPath = path.Replace(".txt", ".jpg");
                img.SaveImage(imgPath);
                target.ImagePath = imgPath;

                var item = AddGalleryItem(img.ToBitmap());
                item.Tag = target;
                _isDirty = true;
            }
        }
예제 #5
0
        void CompareFaces(object result)
        {
            var collections = ((ICollection[])result)[0];

            var targetFs = new FaceProcessingWrapper.FaceSpecification();
            _faceComparer.CalcFeature(OpenCvSharp.IplImage.FromBitmap((Bitmap)this.targetPic.Image), targetFs);

            this.RunInUIThread(() =>
            {
                repositoryItemProgressBar1.Maximum = collections.Count;
                this.ClearFaceList();
            });

            int count = 0;
            foreach (Damany.PortraitCapturer.DAL.DTO.Portrait face in collections)
            {
                _cts.Token.ThrowIfCancellationRequested();

                var curPortrait = face;
                var curFaceImg = curPortrait.ImageCopy;
                var clone = AForge.Imaging.Image.Clone((Bitmap) curFaceImg);
                this.currentPic.RunInUIThread(() =>
                                                  {
                                                      this.currentPic.Image = (Image)clone;
                                                      currentPic.Refresh();
                                                  });

                var curFs = new FaceProcessingWrapper.FaceSpecification();
                var clone2 = AForge.Imaging.Image.Clone((Bitmap)curFaceImg);
                var suc = _faceComparer.CalcFeature(OpenCvSharp.IplImage.FromBitmap((Bitmap)clone2), curFs);
                ((IDisposable)clone2).Dispose();
                if (suc)
                {
                    var sim = _faceComparer.CmpFace(targetFs, curFs);
                    if (sim > Interlocked.Read(ref _currentAccuracy))
                    {
                        var clone3 = AForge.Imaging.Image.Clone((Bitmap)curFaceImg);
                        this.galleryControl1.RunInUIThread(() =>
                        {
                            var item = new GalleryItem((Image)clone3,
                                curPortrait.CaptureTime.ToShortDateString(),
                                curPortrait.CaptureTime.ToShortTimeString());
                            item.Hint = curPortrait.CaptureTime.ToString();
                            this.galleryControl1.Gallery.Groups[0].Items.Add(item);
                        });
                    }
                }

                var c = ++count;
                this.RunInUIThread(() =>
                                       {
                                           progressBar.EditValue = c;
                                           var msg = string.Format("已比对: {0}, 待比对: {1}", c, collections.Count - c);
                                           counter.Caption = msg;
                                       });
            }
        }
예제 #6
0
        private void choosePic_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            var img = Damany.Util.Extensions.MiscHelper.FromFileBuffered(this.openFileDialog1.FileName);
            this.ipl = OpenCvSharp.IplImage.FromBitmap((Bitmap)img);

            var fs = new FaceProcessingWrapper.FaceSpecification();
            var suc = _faceComparer.CalcFeature(this.ipl, fs);

            if (!suc)
            {
                MessageBox.Show("人像不满足比对要求,请重新选择人像。",
                    this.Text,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            this.targetPic.Image = img;

            this.targetPic.Invalidate();
            this.compareButton.Enabled = true;
        }