Ejemplo n.º 1
0
        public void ImageDetect()
        {
            if (frmCameraDetect.FaceList.Count == 0)
                MessageBox.Show("Please enroll faces first", "Error");
            else
            {
               // string strapppath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\imagesearch\\imagecompare.jpg";
                string strapppath = LiveFaceScan.CameraSetting.Drive + ":\\Kiosk_Image_Search\\imagecompare.jpg";
                strapppath = strapppath.Replace("\\", "/");
                string fn = strapppath;//dlg.FileNames[0];
                TFaceRecord fr = new TFaceRecord();
                fr.ImageFileName = fn;
                fr.FacePosition = new FSDK.TFacePosition();
                fr.FacialFeatures = new FSDK.TPoint[FSDK.FSDK_FACIAL_FEATURE_COUNT];
                fr.Template = new byte[FSDK.TemplateSize];

                try
                {
                    fr.image = new FSDK.CImage(fn);

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error loading file");
                }

                fr.FacePosition = fr.image.DetectFace();
                if (0 != fr.FacePosition.w)
                //    1 = 1;
                //// MessageBox.Show("No faces found. Try to lower the Minimal Face Quality parameter in the Options dialog box.", "Enrollment error");
                //else
                {
                    fr.faceImage = fr.image.CopyRect((int)(fr.FacePosition.xc - Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc - Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.xc + Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc + 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(ex.Message, "Error detecting eyes.");
                    }

                    if (eyesDetected)
                    {
                        fr.Template = fr.image.GetFaceTemplateInRegion(ref fr.FacePosition); // get template with higher precision
                    }
                }
                else
                {
                    //MessageBox.Show("No faces found. Try to lower the Minimal Face Quality parameter in the Options dialog box.", "Enrollment error");
                }

                float Threshold = 0.0f;
                FSDK.GetMatchingThresholdAtFAR(frmCameraDetect.FARValue / 100, ref Threshold);
                int MatchedCount = 0;
                int FaceCount = frmCameraDetect.FaceList.Count; //frmCameraDetect.FaceList.Count;
                float[] Similarities = new float[FaceCount];
                int[] Numbers = new int[FaceCount];
                for (int i = 0; i < frmCameraDetect.FaceList.Count; i++)
                {
                    float Similarity = 0.0f;
                    TFaceRecord CurrentFace = frmCameraDetect.FaceList[i];
                    FSDK.MatchFaces(ref fr.Template, ref CurrentFace.Template, ref Similarity);
                    if (Similarity >= Threshold)
                    {
                        Similarities[MatchedCount] = Similarity;
                        Numbers[MatchedCount] = i;
                        ++MatchedCount;
                    }

                    if (Similarities[i] * 100 >= 90)
                    {

                        FSDKCam.CloseVideoCamera(0);
                        needClose = true;
                        // this.Close();

                        this.Visible = false;
                        this.Close();
                        frmCameraResult Detect = new frmCameraResult();
                        Detect.StartPosition = FormStartPosition.CenterScreen;
                        Detect.ShowImage(CurrentFace);
                        Detect.ShowDialog();
                        return;

                    }
                }

            }
        }
Ejemplo n.º 2
0
        void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (status == true)
            {
                return;
            }

               try
            {

            //System.Threading.Thread.Sleep(10000);
            if (frCompare.ImageFileName != null)
            {
                //do the code when bgv completes its work
                // this.Close();
                this.Visible = false;
                this.Close();
                frmCameraResult Detect = new frmCameraResult();
                Detect.StartPosition = FormStartPosition.CenterScreen;
                Detect.ShowImage(frCompare);
                Detect.ShowDialog();
                // MessageBox.Show(Similarities * 100 + "");
            }
            else {
                lblPercent.Text = "ไม่พบข้อมูล";

                pictureClose2.Visible = true;
                this.Visible = false;
                this.Close();
                frmSearchMobile f = new frmSearchMobile();
                f.ShowDialog();

                //needClose = false;
                //PopulateData();
            }

               //lblPercent.Text = "ไม่พบข้อมูล";
            }
               catch (Exception exRunWorkerCompleted)
               {

               }
        }