示例#1
0
 void match_faces()
 {
     if (FaceList.Count == 0)
     {
         MessageBox.Show("Please enroll faces first", "Error");
     }
     else
     {
         try {
             String       fn = Application.StartupPath + "\\images\\verify_image.jpg";
             TFaceRecords fr = new TFaceRecords();
             fr.ImageFileName  = fn;
             fr.FacePosition   = new FSDK.TFacePosition();
             fr.FacialFeatures = new FSDK.TPoint[FSDK.FSDK_FACIAL_FEATURE_COUNT - 1];
             fr.Template       = new Byte[FSDK.TemplateSize - 1];
             fr.image          = new FSDK.CImage(fn);
             fr.FacePosition   = fr.image.DetectFace();
             if (fr.FacePosition.w == 0)
             {
                 MessageBox.Show("No faces found. Try to lower the Minimal Face Quality parameter.", "Verification error");
             }
             else
             {
                 fr.faceImage = fr.image.CopyRect((int)(fr.FacePosition.xc - System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc - System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.xc + System.Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc + System.Math.Round(fr.FacePosition.w * 0.5)));
                 bool eyesdetected = false;
                 try
                 {
                     fr.FacialFeatures = fr.image.DetectEyesInRegion(ref fr.FacePosition);
                     eyesdetected      = true;
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Error detecting eyes...", "Verification Module");
                 }
                 if (eyesdetected)
                 {
                     fr.Template = fr.image.GetFaceTemplateInRegion(ref fr.FacePosition);
                 }
                 Go(ref fr);
             }
         } catch (Exception ex)
         {
             MessageBox.Show("Can't open image(s) with error: " + ex.Message.ToString(), "Error");
         }
     }
 }
示例#2
0
        void Go(ref TFaceRecords SearchFace)
        {
            System.Drawing.Image img = SearchFace.faceImage.ToCLRImage();
            float Threshold          = 0.0f;

            FSDK.GetMatchingThresholdAtFAR(70 / 100, ref Threshold);
            int MatchedCount = 0;
            int FaceCount    = FaceList.Count();

            Double[] Similarities = new Double[FaceCount];
            int[]    Numbers      = new int[FaceCount];
            MessageBox.Show("Facelist = " + FaceList.Count);
            for (int i = 0; i <= FaceList.Count - 1; i++)
            {
                float        Similarity  = 0.0F;
                TFaceRecords CurrentFace = FaceList[i];
                FSDK.MatchFaces(ref SearchFace.Template, ref CurrentFace.Template, ref Similarity);
                MessageBox.Show("Similarity = " + Similarity + "Threshold = " + Threshold);
                if (Similarity >= Threshold)
                {
                    Similarities[MatchedCount] = Similarity;
                    Numbers[MatchedCount]      = i;
                    MatchedCount += 1;
                }
            }
            if (MatchedCount == 0)
            {
                MessageBox.Show("No matches found.\nTry Again !!!" + MatchedCount, "No matches");
            }
            else
            {
                MessageBox.Show("Staff Record found in database...");
            }

            /*
             */
            t.Abort();
            // button1.Enabled = true;
        }
示例#3
0
        void loaddb()
        {
            MySqlConnection sqlConnect = null;

            try
            {
                sqlConnect = new MySqlConnection("server=127.0.0.1;user id=root;password=;database=verification_system");
                sqlConnect.Open();
                MySqlCommand    sqlCmd = new MySqlCommand("SELECT ImageFileName, FacePositionXc, FacePositionYc, FacePositionW, FacePositionAngle, Eye1X, Eye1Y, Eye2X, Eye2Y, imageTemplate, image, faceimage FROM records", sqlConnect);
                MySqlDataReader reader = sqlCmd.ExecuteReader();
                while (reader.Read())
                {
                    TFaceRecords fr = new TFaceRecords();
                    fr.ImageFileName = reader.GetString(0);

                    fr.FacePosition        = new FSDK.TFacePosition();
                    fr.FacePosition.xc     = reader.GetInt32(1);
                    fr.FacePosition.yc     = reader.GetInt32(2);
                    fr.FacePosition.w      = reader.GetInt32(3);
                    fr.FacePosition.angle  = reader.GetFloat(4);
                    fr.FacialFeatures      = new FSDK.TPoint[2];
                    fr.FacialFeatures[0]   = new FSDK.TPoint();
                    fr.FacialFeatures[0].x = reader.GetInt32(5);
                    fr.FacialFeatures[0].y = reader.GetInt32(6);
                    fr.FacialFeatures[1]   = new FSDK.TPoint();
                    fr.FacialFeatures[1].x = reader.GetInt32(7);
                    fr.FacialFeatures[1].y = reader.GetInt32(8);
                    fr.Template            = new Byte[FSDK.TemplateSize];
                    reader.GetBytes(9, 0, fr.Template, 0, FSDK.TemplateSize);
                    // MessageBox.Show(reader.GetFieldType(10).ToString());

                    Byte[] b  = (Byte[])reader.GetValue(10); //new Byte[reader.GetByte(10)];
                    Byte[] bb = (Byte[])reader.GetValue(11); //new Byte[reader.GetByte(11)];
                    // MessageBox.Show("reached");
                    System.Drawing.Image img      = System.Drawing.Image.FromStream(new System.IO.MemoryStream(b));
                    System.Drawing.Image img_face = System.Drawing.Image.FromStream(new System.IO.MemoryStream(bb));
                    // MessageBox.Show("reached");
                    fr.image     = new FSDK.CImage(img);
                    fr.faceImage = new FSDK.CImage(img_face);
                    bool eyesdetected = false;
                    try
                    {
                        fr.FacialFeatures = fr.image.DetectEyesInRegion(ref fr.FacePosition);
                        eyesdetected      = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error detecting eyes", "Verification Module");
                    }
                    if (eyesdetected)
                    {
                        fr.Template = fr.image.GetFaceTemplateInRegion(ref fr.FacePosition);
                    }
                    FaceList.Add(fr);
                    img.Dispose();
                    img_face.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception on loading database");
            }
            finally
            {
                if (sqlConnect != null)
                {
                    sqlConnect.Close();
                }
            }
        }