Exemple #1
0
        public FrmSearch(Bitmap bmpSource, Guid faceId, DateTime dt, Guid imageId)
        {
            InitializeComponent();
            BcFace         bcFace = BcFace.LoadById(faceId);
            List <BcImage> list   = BcImage.LoadByFaceId(faceId);

            foreach (BcImage bcImage in list)
            {
                if (bcImage.IsMain)
                {
                    if (bcImage.Image.Length > 0)
                    {
                        pictureBox1.Image = bmpSource;
                        pictureBox2.Image = new Bitmap(new MemoryStream(bcImage.Image));
                    }
                }
                else if (list.Count > 0 && bcImage.Image.Length > 0)
                {
                    pictureBox1.Image = bmpSource;
                    pictureBox2.Image = new Bitmap(new MemoryStream(bcImage.Image));
                }
            }
            groupBox1.Text = groupBox1.Text + (object)" (" + Messages.PassDateAndTime + ": " + (string)(object)dt + ")";
            groupBox2.Text = groupBox2.Text + " (" + bcFace.Surname + " " + bcFace.FirstName + " " + bcFace.LastName + ")";
        }
Exemple #2
0
 public void SaveFace(string str, FaceRecognition rec)
 {
     try
     {
         BcFace   bcFace   = new BcFace();
         string[] strArray = str.Replace(_currentDir + "\\", "").ToUpper().Replace(".JPEG", "").Replace(".JPG", "").Replace(".BMP", "").Replace(".GIF", "").Replace(".PNG", "").Replace(".TIFF", "").Split(new string[1]
         {
             " "
         }, StringSplitOptions.RemoveEmptyEntries);
         bcFace.Id = Guid.Empty;
         if (strArray.Length > 1)
         {
             bcFace.FirstName = strArray[1];
         }
         if (strArray.Length > 0)
         {
             bcFace.Surname = strArray[0];
         }
         if (strArray.Length > 2)
         {
             bcFace.LastName = strArray[2];
         }
         Bitmap source = (Bitmap)Image.FromFile(str);
         TS.Sdk.StaticFace.Model.Image image = source.ConvertFrom();
         BcKey    bcKey = new BcKey();
         FaceInfo face  = rec.Engine.DetectMaxFace(image, null);
         if (face != null)
         {
             bcFace.Comment    = CommonComment;
             bcFace.Sex        = CommonSex;
             bcFace.AccessId   = _selectedCategoryId;
             bcFace.EditUserId = MainForm.CurrentUser.Id;
             Rectangle faceRectangle = face.FaceRectangle;
             int       width1        = (int)faceRectangle.Width * 2;
             faceRectangle = face.FaceRectangle;
             int    height1 = (int)faceRectangle.Height * 2;
             Bitmap bitmap  = new Bitmap(width1, height1);
             using (Graphics graphics = Graphics.FromImage(bitmap))
             {
                 graphics.FillRectangle(Brushes.White, 0, 0, bitmap.Width, bitmap.Height);
                 faceRectangle = face.FaceRectangle;
                 double x1 = faceRectangle.X;
                 faceRectangle = face.FaceRectangle;
                 double num1 = faceRectangle.Width / 2.0;
                 int    x2   = (int)(x1 - num1);
                 double num2 = source.Height;
                 faceRectangle = face.FaceRectangle;
                 double y1   = faceRectangle.Y;
                 double num3 = num2 - y1;
                 faceRectangle = face.FaceRectangle;
                 double height2 = faceRectangle.Height;
                 double num4    = num3 - height2;
                 faceRectangle = face.FaceRectangle;
                 double num5    = faceRectangle.Width / 2.0;
                 int    y2      = (int)(num4 - num5);
                 int    width2  = bitmap.Width;
                 int    height3 = bitmap.Height;
                 graphics.DrawImage(source, new System.Drawing.Rectangle(0, 0, width2, height3), new System.Drawing.Rectangle(x2, y2, width2, height3), GraphicsUnit.Pixel);
             }
             MemoryStream memoryStream1 = new MemoryStream();
             MemoryStream memoryStream2 = new MemoryStream();
             bitmap.Save(memoryStream1, ImageFormat.Jpeg);
             BcImage bcImage = new BcImage();
             if (bitmap.Width >= 300)
             {
                 bitmap = new Bitmap(bitmap, new Size(bitmap.Width / 2, bitmap.Height / 2));
                 bitmap.Save(memoryStream2, ImageFormat.Jpeg);
                 bcFace.ImageIcon  = memoryStream2.GetBuffer();
                 bcImage.ImageIcon = memoryStream2.GetBuffer();
             }
             else
             {
                 bcFace.ImageIcon  = memoryStream1.GetBuffer();
                 bcImage.ImageIcon = memoryStream1.GetBuffer();
             }
             bcFace.Save();
             bcImage.FaceId = bcFace.Id;
             bcImage.Image  = memoryStream1.GetBuffer();
             bcImage.FaceId = bcFace.Id;
             bcImage.Save();
             bitmap.Dispose();
             memoryStream1.Close();
             memoryStream1.Dispose();
             memoryStream2.Close();
             memoryStream2.Dispose();
             bcKey.ImageKey = rec.Engine.ExtractTemplate(image, face);
             if (bcKey.ImageKey != null)
             {
                 bcKey.Ksid    = -1;
                 bcKey.ImageId = bcImage.Id;
                 bcKey.FaceId  = bcFace.Id;
                 bcKey.Save();
             }
             else
             {
                 Errors.Add("Error to create template");
                 ErrorFiles.Add(str);
             }
         }
         else
         {
             Errors.Add(Messages.NoFaceWasFound);
             ErrorFiles.Add(str);
         }
         source.Dispose();
     }
     catch (Exception ex)
     {
         Errors.Add(ex.Message);
         ErrorFiles.Add(str);
     }
     rec.IsWork = false;
     try
     {
         Invoke(new NewValueFileFunc(NewValueFile), (object)_progVal, (object)_mainIndex, (object)_commonFiles.Count);
     }
     catch
     {
     }
 }