Example #1
0
        /// <summary>
        /// 根据图片数组的下标载入并显示图片
        /// </summary>
        /// <param name="no">图片的下标</param>
        private void ShowFaceImage(int no)
        {
            var imageName = _images[no];

            _faceImage        = new Bitmap(Image.FromFile(imageName));
            pictureBox1.Image = _faceImage;
            var locateResult = _faceDetectionService.FaceLocateResult(_faceImage);

            if (locateResult.FaceCount == 1)
            {
                btnOK.Text         = "添加人脸";
                _feature           = _faceDetectionService.GetFaceFeature(_faceImage, locateResult);
                _faceThumbnail     = PictureProcess.GetThumbnail(_faceImage, _feature);
                picThumbnail.Image = _faceThumbnail;
                _hasFace           = true;
            }
            else
            {
                var lbShowText = new Label();   // 使用 Label 在图片中显示文字
                lbShowText.Text      = string.Format("图片无有效人脸\n\n请跳过");
                lbShowText.Font      = new Font("宋体", 14, FontStyle.Bold);
                lbShowText.ForeColor = Color.Red;
                lbShowText.Location  = new Point(0, 00);
                lbShowText.Width     = 150;
                lbShowText.Height    = 150;
                lbShowText.TextAlign = ContentAlignment.MiddleCenter;
                lbShowText.Parent    = picThumbnail;
                btnOK.Text           = "跳过";

                _hasFace = false;
            }

            tsslAddedToLibrary.Text = string.Format("已经添加到人脸库数量:{0}   |   ", _faceCount);
            tsslCurrentNumber.Text  = string.Format("当前处理图片序号:{0}   ", i + 1);

            // 来自文件的时候,文件名默认为人脸名
            if (_single)
            {
                txtPersonName.Text = string.Empty;
            }
            else
            {
                // var info = new FileInfo(imageName);   // 获取文件名
                // var fileName = info.Name.Replace(info.Extension, ""); // 去掉扩展名
                txtPersonName.Text = System.IO.Path.GetFileNameWithoutExtension(imageName);  // 直接获取主文件名
            }
            txtPosition.Text     = string.Empty;
            txtSerialNumber.Text = string.Empty;
            txtDescription.Text  = string.Empty;

            txtPersonName.Enabled   = _hasFace;
            txtPosition.Enabled     = _hasFace;
            txtSerialNumber.Enabled = _hasFace;
            txtDescription.Enabled  = _hasFace;
        }
Example #2
0
        private void FrmFacePhoto_Load(object sender, EventArgs e)
        {
            tsslFaceCount.Text = string.Format("待识别人脸特征图片数量:{0}   |   ", _count);

            if (_single)
            {
                pictureBox1.Image = _singleImage;
                var locateResult = _faceDetectionService.FaceLocateResult(_singleImage);
                if (locateResult.FaceCount == 1)
                {
                    btnOK.Text         = "添加人脸";
                    _feature           = _faceDetectionService.GetFaceFeature(_singleImage, locateResult);
                    _faceThumbnail     = PictureProcess.GetThumbnail(_singleImage, _feature);
                    picThumbnail.Image = _faceThumbnail;
                    _hasFace           = true;
                }
                else
                {
                    var lbShowText = new Label();   // 使用 Label 在图片中显示文字
                    lbShowText.Text      = string.Format("图片无有效人脸\n\n请跳过");
                    lbShowText.Font      = new Font("宋体", 14, FontStyle.Bold);
                    lbShowText.ForeColor = Color.Red;
                    lbShowText.Location  = new Point(0, 00);
                    lbShowText.Width     = 150;
                    lbShowText.Height    = 150;
                    lbShowText.TextAlign = ContentAlignment.MiddleCenter;
                    lbShowText.Parent    = picThumbnail;
                    btnOK.Text           = "跳过";

                    _hasFace = false;
                }

                tsslAddedToLibrary.Text = string.Format("已经添加到人脸库数量:{0}   |   ", _faceCount);
                tsslCurrentNumber.Text  = string.Format("当前处理图片序号:{0}   ", i + 1);

                txtPersonName.Text   = string.Empty;
                txtPosition.Text     = string.Empty;
                txtSerialNumber.Text = string.Empty;
                txtDescription.Text  = string.Empty;

                txtPersonName.Enabled   = _hasFace;
                txtPosition.Enabled     = _hasFace;
                txtSerialNumber.Enabled = _hasFace;
                txtDescription.Enabled  = _hasFace;
            }
            else
            {
                ShowFaceImage(i);
            }
        }