Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0;
            FSDK.CreateTracker(ref tracker);

            int err = 0; // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "RecognizeFaces=false; HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long [] IDs;
                long faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                Image frameImage = image.ToCLRImage();
                Graphics gr = Graphics.FromImage(frameImage);

                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top = facePosition.yc - (int)(facePosition.w * 0.5);
                    gr.DrawRectangle(Pens.LightGreen, left, top, (int)(facePosition.w * 1.2), (int)(facePosition.w * 1.2));
                }

                // display current frame
                pictureBox1.Image = frameImage;

                GC.Collect(); // collect the garbage

                // make UI controls accessible
                Application.DoEvents();
            }
            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }
            public FSDK.TFacePosition[] DetectMultipleFaces()
            {
                FSDK.TFacePosition [] FaceArray;
                int detected = 0;
                int res      = FSDK.DetectMultipleFaces(hImage, ref detected, out FaceArray, FSDK.sizeofTFacePosition * 1024);

                if (FSDKE_FACE_NOT_FOUND == res)
                {
                    FaceArray = new FSDK.TFacePosition[0];
                }
                else
                {
                    CheckForError(res);
                }
                return(FaceArray);
            }
            public TFacePosition DetectFace()
            {
                TFacePosition fp  = new FSDK.TFacePosition();
                int           res = FSDK.DetectFace(hImage, ref fp);

                if (FSDKE_FACE_NOT_FOUND == res)
                {
                    fp       = new FSDK.TFacePosition();
                    fp.xc    = 0;
                    fp.yc    = 0;
                    fp.angle = 0;
                    fp.w     = 0;
                }
                else
                {
                    CheckForError(res);
                }
                return(fp);
            }
        public void ShowDetect()
        {
            {
                int cameraHandle = 0;

                int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
                if (r != FSDK.FSDKE_OK)
                {
                    MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }

                int tracker = 0; 	// creating a Tracker
                if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
                    FSDK.CreateTracker(ref tracker); // if could not be loaded, create a new tracker

                int err = 0; // set realtime face detection parameters
                FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

                while (!needClose)
                {

                    Int32 imageHandle = 0;
                    if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                    {
                        Application.DoEvents();
                        continue;
                    }
                    FSDK.CImage image = new FSDK.CImage(imageHandle);

                    long[] IDs;
                    long faceCount = 0;
                    FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                    Array.Resize(ref IDs, (int)faceCount);

                    // make UI controls accessible (to find if the user clicked on a face)
                    Application.DoEvents();

                    Image frameImage = image.ToCLRImage();
                    Graphics gr = Graphics.FromImage(frameImage);

                    IsDetect= "False";
                    //txtDetect.Text = "ไม่เจอ";
                    for (int i = 0; i < IDs.Length; ++i)
                    {
                        //txtDetect.Text = "เจอ";
                        IsDetect = "True";

                        FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                        FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                        int left = facePosition.xc - (int)(facePosition.w * 0.6);
                        int top = facePosition.yc - (int)(facePosition.w * 0.5);
                        int w = (int)(facePosition.w * 1.2);

                        String name;
                        int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                        if (FSDK.FSDKE_OK == res && name.Length > 0)
                        { // draw name
                            StringFormat format = new StringFormat();
                            format.Alignment = StringAlignment.Center;

                            gr.DrawString(name, new System.Drawing.Font("Arial", 16),
                                new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                                facePosition.xc, top + w + 5, format);
                        }

                        Pen pen = Pens.LightGreen;
                        if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                        {
                            pen = Pens.Blue;
                            if (ProgramState.psRemember == programState)
                            {
                                if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                                {
                                    // get the user name
                                    //frmInputBox inputName = new frmInputBox();
                                    //if (DialogResult.OK == inputName.ShowDialog())
                                    //{
                                    //    userName = inputName.userName;
                                    //    FSDK.SetName(tracker, IDs[i], userName);
                                    //    FSDK.UnlockID(tracker, IDs[i]);
                                    //}
                                }
                            }
                        }
                        gr.DrawRectangle(pen, left, top, w, w);
                    }
                    programState = ProgramState.psRecognize;

                    // display current frame
                    pictureBox1.Image = frameImage;

                    GC.Collect(); // collect the garbage after the deletion
                    if (IsDetect == "True") {
                    string strapppath = LiveFaceScan.CameraSetting.Drive + ":\\Kiosk_Image_Search\\imagecompare.jpg";// System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\imagesearch\\imagecompare.jpg";
                    if (System.IO.File.Exists(strapppath.Replace("\\", "/")))
                    {
                        System.IO.File.Delete(strapppath.Replace("\\", "/"));
                    }
                          pictureBox1.Image.Save(strapppath.Replace("\\", "/"),ImageFormat.Jpeg);

                        //ImageDetect();
                    }

                }
                FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
                FSDK.FreeTracker(tracker);

                FSDKCam.CloseVideoCamera(cameraHandle);
                FSDKCam.FinalizeCapturing();
                //if (needClose == true) {

                //    if (frmCameraDetect.FaceList.Count == 0)
                //    {
                //     MessageBox.Show("Please enroll faces first", "Error");
                //    }
                //    else {

                //    }

                //}
            }
        }
        public void PopulateData()
        {
            //if (FSDK.FSDKE_OK != FSDK.ActivateLibrary("eLDwg+IxLV+w/pfOUzvf7OhNDgnO4M0ZSQZzy7Os2hUn0z3b1driMrhlq+r/eFjkQkjIL4Men2VLH29plmHC/ojpfhyrk6v0tzfc96TD72U4yqYeq4l0VR7phnG1EeFTIPzuXPRKAwtefblB7DmM6uYUrcgGZ5r8R04EdMsJl/k="))
            //{
            //    MessageBox.Show("Please run the License Key Wizard (Start - Luxand - FaceSDK - License Key Wizard)", "Error activating FaceSDK", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    Application.Exit();
            //}

            //FSDK.InitializeLibrary();
            //FSDKCam.InitializeCapturing();

            //int count;
            //cameraName = LiveFaceScan.CameraSetting.CameraName;
            //FSDKCam.VideoFormatInfo[] formatList;
            //FSDKCam.GetVideoFormatList(ref cameraName, out formatList, out count);

            //formatList[0].Height = 600;
            //formatList[0].Width = 800;
               // FSDKCam.SetVideoFormat(ref cameraName, formatList[0]);

            //int VideoFormat = LiveFaceScan.CameraSetting.VideoFormat;//0; // choose a video format
            //pictureBox1.Height = formatList[VideoFormat].Height;
            //pictureBox1.Width = formatList[VideoFormat].Width;
            //this.Height = formatList[VideoFormat].Height + 48;
            //this.Width = formatList[VideoFormat].Width + 96;

              //  777, 592
            //int screenWidth;
            //int screenHeight;

            //// grabs the resolution of the monitor
            //Screen screen = Screen.PrimaryScreen;
            //screenWidth = 777;//screen.Bounds.Width;
            //screenHeight = 570;//screen.Bounds.Height;
            //// MessageBox.Show("height = " + screenHeight + "\n" + "Width = " + screenWidth);
            //// grabs the resolution of the monitor

            //// sets the size of the window of Pictureviewer
            //this.ClientSize = new Size(screenWidth, screenHeight);
            //// sets the size of the window of Pictureviewer

            //pictureBox1.Size = new Size(screenWidth, screenHeight);

            //pictureBox1.Location = new Point((ClientSize.Width / 2) - (pictureBox1.Width / 2), (ClientSize.Height / 2) - (pictureBox1.Height / 2));

                 try
            {

            if (FSDK.FSDKE_OK != FSDK.ActivateLibrary("J98H0OOSi4gGwMxLZ0daeM5sCGAFl4wyClviJFdPlYpa48vaFm46LvwLq9T9L0W3vMjimMsBOFFSuTmn8S7nsWoLdS0GLiwGXHuXDJxlgYMo4ufYFVraAPrJfiDeKWaLLoxlR4ZbMIMnujLnM+t/NjixxITVxO522C0Sh8BcbAU="))
            {
                MessageBox.Show("Please run the License Key Wizard (Start - Luxand - FaceSDK - License Key Wizard)", "Error activating FaceSDK", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            FSDK.InitializeLibrary();
            FSDKCam.InitializeCapturing();

            string[] cameraList;
            int count;
            FSDKCam.GetCameraList(out cameraList, out count);

            if (0 == count)
            {
                MessageBox.Show("Please attach a camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            cameraName = LiveFaceScan.CameraSetting.CameraName;

            FSDKCam.VideoFormatInfo[] formatList;
            FSDKCam.GetVideoFormatList(ref cameraName, out formatList, out count);

            int VideoFormat = LiveFaceScan.CameraSetting.VideoFormat; // choose a video format
            //pictureBox1.Width = formatList[VideoFormat].Width;
            //pictureBox1.Height = formatList[VideoFormat].Height;
            //this.Width = formatList[VideoFormat].Width + 48;
            //this.Height = formatList[VideoFormat].Height + 96;
            pictureBox1.Location = new Point(0, 188);
               pictureBox1.Width = 800;
               pictureBox1.Height = 800;
            this.Width = 800;
            this.Height = 1224;

               pictureSearch.Location = new Point(222,800+260);

            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0; 	// creating a Tracker
            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
                FSDK.CreateTracker(ref tracker); // if could not be loaded, create a new tracker

            int err = 0; // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);
            string IsDetect;
            while (!needClose)
            {

                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long[] IDs;
                long faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image frameImage = image.ToCLRImage();
                Graphics gr = Graphics.FromImage(frameImage);
                IsDetect = "False";
                for (int i = 0; i < IDs.Length; ++i)
                {
                    IsDetect = "True";
                    //pictureBox1.Image = frameImage;
                    //string strapppath = "D:\\Kiosk_Image_Search\\imagecompare.jpg";// System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\imagesearch\\imagecompare.jpg";
                    //if (System.IO.File.Exists(strapppath.Replace("\\", "/")))
                    //{
                    //    System.IO.File.Delete(strapppath.Replace("\\", "/"));
                    //}
                    //pictureBox1.Image.Save(strapppath.Replace("\\", "/"), ImageFormat.Jpeg);

                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w = (int)(facePosition.w * 1.2);

                    String name;
                    int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                    if (FSDK.FSDKE_OK == res && name.Length > 0)
                    { // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString(name, new System.Drawing.Font("Arial", 16),
                            new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                            facePosition.xc, top + w + 5, format);
                    }

                    Pen pen = Pens.LightGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.Blue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {

                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
               pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
                if (IsDetect == "True")
                {
                    //string strapppath = "D:\\Kiosk_Image_Search\\imagecompare.jpg";// System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\imagesearch\\imagecompare.jpg";
                    ////if (System.IO.File.Exists(strapppath.Replace("\\", "/")))
                    ////{
                    ////    System.IO.File.Delete(strapppath.Replace("\\", "/"));
                    ////}

                    ////pictureBox1.Image.Save(strapppath.Replace("\\", "/"), ImageFormat.Jpeg);
                    ////pictureBox1.Dispose();
                    ////pictureBox1.Refresh();

                    //Image img;
                    //string file = @"D:\Kiosk_Image_Search\imagecompare.jpg";
                    //using (Bitmap bmp = new Bitmap(file))
                    //{
                    //    img = new Bitmap(bmp);
                    //   // pictureBox1.Image = img;
                    //}
                    //if (System.IO.File.Exists(file))
                    //{
                    //    System.IO.File.Delete(file);
                    //    pictureBox1.Image.Save(file, ImageFormat.Jpeg);
                    //}
                    //else
                    //    pictureBox1.Image.Save(file, ImageFormat.Jpeg);

                  // needClose = true;

                    //frCompare.ImageFileName = "imaggecompre";
                    //frCompare.FacePosition = new FSDK.TFacePosition();
                    //frCompare.FacialFeatures = new FSDK.TPoint[2];
                    //frCompare.Template = new byte[FSDK.TemplateSize];
                    //frCompare.image = new FSDK.CImage(pictureBox1.Image);

                    //int images;
                    //int img1;

                    //FSDK.LoadImageFromFile(ref img1, strapppath);
                    //FSDK.SaveImageToFile(img1, strapppath.Replace("\\", "/"));
                    //  ImageDetect();
                   // PopulateAllImage();
                    //if (FaceList.Count > 0)
                    //{
                    //    ImageDetect();
                    //}

                   // MessageBox.Show(FaceList.Count + "");
                    //MessageBox.Show("Face");
                    //FaceList = new List<TFaceRecord>();
                    //string strapppathTemp = "D:\\Kiosk_Image";
                    //String[] filenames = System.IO.Directory.GetFiles(strapppathTemp, "*.jpg");
                    ////MessageBox.Show(filenames.Length + "");
                    //for (int i = 0; i <= filenames.Length-1; i++)
                    //{

                    //    string strpath = filenames[i].Replace("\\", "/");

                    //    MessageBox.Show(strpath);
                    //    TFaceRecord fr = new TFaceRecord();
                    //    fr.ImageFileName = strpath;
                    //    fr.FacePosition = new FSDK.TFacePosition();
                    //    fr.FacialFeatures = new FSDK.TPoint[2];
                    //    fr.Template = new byte[FSDK.TemplateSize];
                    //    fr.image = new FSDK.CImage(strpath);

                    //    try
                    //    {
                    //        fr.FacePosition = fr.image.DetectFace();
                    //        if (0 != fr.FacePosition.w)
                    //        {
                    //            MessageBox.Show(fr.FacePosition.w + "");
                    //            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)));

                    //            try
                    //            {
                    //                fr.FacialFeatures = fr.image.DetectEyesInRegion(ref fr.FacePosition);
                    //            }
                    //            catch (Exception ex2)
                    //            {
                    //                MessageBox.Show(ex2.Message, "Error detecting eyes.");
                    //            }

                    //            try
                    //            {
                    //                fr.Template = fr.image.GetFaceTemplateInRegion(ref fr.FacePosition); // get template with higher precision
                    //            }
                    //            catch (Exception ex2)
                    //            {
                    //                MessageBox.Show(ex2.Message, "Error retrieving face template.");
                    //            }

                    //            FaceList.Add(fr);
                    //            //imageList1.Images.Add(fr2.faceImage.ToCLRImage());
                    //            //lvRegister.Items.Add((imageList1.Images.Count - 1).ToString(), strpath, imageList1.Images.Count - 1);
                    //        }
                    //    }
                    //    catch (Exception exMain)
                    //    {
                    //        MessageBox.Show(exMain.Message, "Error retrieving face template. Main");
                    //    }

                    //    }

                    //MessageBox.Show(FaceList.Count + "");

                   // needClose = true;

                }
                }
            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
            //if (needClose == true)
            //{
            //    Progresss();
            //}

            }
                 catch (Exception exPopulateData)
                 {

                 }
        }
        //캠활성화 버튼 클릭
        private void FaceDetection(object sender, EventArgs e)
        {
            int motion_check = 0;

            //cmb_cam.Items.AddRange(cameraList);
            cameraName = cmb_cam.SelectedItem.ToString();
            //this.btn_start.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0; 	// creating a Tracker

            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, dataRootDir + "\\" + TrackerMemoryFile)) // try to load saved tracker state
                FSDK.CreateTracker(ref tracker); // if could not be loaded, create a new tracker

            int err = 0; // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long[] IDs;
                long faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected 얼굴여부 체크
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image frameImage = image.ToCLRImage();
                Graphics gr = Graphics.FromImage(frameImage);

                //모션 없음
                if (faceCount == 0)
                {
                    motion_check++;
                    //모션 있음
                }
                else
                {
                    motion_check = 0;
                }
                if (motion_check > 1000)
                {
                    System.Windows.Forms.MessageBox.Show("방범모드");
                    motion_check = 0;
                }

                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w = (int)(facePosition.w * 1.2);

                    String name;
                    int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                    //데이터와 얼굴 영상이 일치하는 경우
                    if (FSDK.FSDKE_OK == res && name.Length > 0)
                    { // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString("이름:" + name, new System.Drawing.Font("Arial", 16),
                            new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                            facePosition.xc, top + w + 5, format);
                    }

                    //데이터와 얼굴 영상이 일치하지 않는 경우
                    else
                    {

                    }

                    FSDK.UnlockID(tracker, IDs[i]);
                    Pen pen = Pens.LightGreen;

                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
            }
            FSDK.FreeTracker(tracker);
            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }
 public FSDK.TFacePosition[] DetectMultipleFaces()
 {
     FSDK.TFacePosition [] FaceArray;
     int detected = 0;
     int res = FSDK.DetectMultipleFaces(hImage, ref detected, out FaceArray, FSDK.sizeofTFacePosition*1024);
     if (FSDKE_FACE_NOT_FOUND == res)
         FaceArray = new FSDK.TFacePosition[0];
     else
         CheckForError(res);
     return FaceArray;
 }
 public TFacePosition DetectFace()
 {
     TFacePosition fp = new FSDK.TFacePosition();
     int res = FSDK.DetectFace(hImage, ref fp);
     if (FSDKE_FACE_NOT_FOUND == res){
         fp = new FSDK.TFacePosition();
         fp.xc = 0;
         fp.yc = 0;
         fp.angle = 0;
         fp.w = 0;
     } else {
         CheckForError(res);
     }
     return fp;
 }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0; 	// creating a Tracker
            if (FSDK.FSDKE_OK != FSDK.LoadTrackerMemoryFromFile(ref tracker, TrackerMemoryFile)) // try to load saved tracker state
                FSDK.CreateTracker(ref tracker); // if could not be loaded, create a new tracker

            int err = 0; // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);

            while (!needClose)
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

                long[] IDs;
                long faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum of 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                // make UI controls accessible (to find if the user clicked on a face)
                Application.DoEvents();

                Image frameImage = image.ToCLRImage();
                Graphics gr = Graphics.FromImage(frameImage);

                for (int i = 0; i < IDs.Length; ++i)
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w = (int)(facePosition.w * 1.2);

                    String name;
                    int res = FSDK.GetAllNames(tracker, IDs[i], out name, 65536); // maximum of 65536 characters

                    if (FSDK.FSDKE_OK == res && name.Length > 0) { // draw name
                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString(name, new System.Drawing.Font("Arial", 16),
                            new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                            facePosition.xc, top + w + 5, format);
                    }

                    Pen pen = Pens.LightGreen;
                    if (mouseX >= left && mouseX <= left + w && mouseY >= top && mouseY <= top + w)
                    {
                        pen = Pens.Blue;
                        if (ProgramState.psRemember == programState)
                        {
                            if (FSDK.FSDKE_OK == FSDK.LockID(tracker, IDs[i]))
                            {
                                // get the user name
                                InputName inputName = new InputName();
                                if (DialogResult.OK == inputName.ShowDialog())
                                {
                                    userName = inputName.userName;
                                    if (userName == null)
                                    {
                                        String s = "";
                                        FSDK.SetName(tracker, IDs[i], "");
                                    }
                                    else
                                    {
                                        FSDK.SetName(tracker, IDs[i], userName);
                                    }
                                    FSDK.UnlockID(tracker, IDs[i]);
                                }
                            }
                        }
                    }
                    gr.DrawRectangle(pen, left, top, w, w);
                }
                programState = ProgramState.psRecognize;

                // display current frame
                pictureBox1.Image = frameImage;
                GC.Collect(); // collect the garbage after the deletion
            }
            FSDK.SaveTrackerMemoryToFile(tracker, TrackerMemoryFile);
            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();
        }
Esempio n. 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = false;
            int cameraHandle = 0;

            int r = FSDKCam.OpenVideoCamera(ref cameraName, ref cameraHandle);
            if (r != FSDK.FSDKE_OK)
            {
                MessageBox.Show("Error opening the first camera", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            int tracker = 0;
            FSDK.CreateTracker(ref tracker);

            int err = 0; // set realtime face detection parameters
            FSDK.SetTrackerMultipleParameters(tracker, "RecognizeFaces=false; DetectGender=true; HandleArbitraryRotations=false; DetermineFaceRotationAngle=false; InternalResizeWidth=100; FaceDetectionThreshold=5;", ref err);
           
            while (!needClose) 
            {
                Int32 imageHandle = 0;
                if (FSDK.FSDKE_OK != FSDKCam.GrabFrame(cameraHandle, ref imageHandle)) // grab the current frame from the camera
                {
                    Application.DoEvents();
                    continue;
                }
                FSDK.CImage image = new FSDK.CImage(imageHandle);

			    long [] IDs;
			    long faceCount = 0;
                FSDK.FeedFrame(tracker, 0, image.ImageHandle, ref faceCount, out IDs, sizeof(long) * 256); // maximum 256 faces detected
                Array.Resize(ref IDs, (int)faceCount);

                Image frameImage = image.ToCLRImage();
                Graphics gr = Graphics.FromImage(frameImage);

                for (int i = 0; i < IDs.Length; ++i) 
                {
                    FSDK.TFacePosition facePosition = new FSDK.TFacePosition();
                    FSDK.GetTrackerFacePosition(tracker, 0, IDs[i], ref facePosition);

                    int left = facePosition.xc - (int)(facePosition.w * 0.6);
                    int top = facePosition.yc - (int)(facePosition.w * 0.5);
                    int w = (int)(facePosition.w * 1.2);
                    gr.DrawRectangle(Pens.LightGreen, left, top, w, w);

				    String AttributeValues;
				    if (0 == FSDK.GetTrackerFacialAttribute(tracker, 0, IDs[i], "Gender", out AttributeValues, 1024))
                    {
                        float ConfidenceMale = 0.0f;
                        float ConfidenceFemale = 0.0f;
                        FSDK.GetValueConfidence(AttributeValues, "Male", ref ConfidenceMale);
                        FSDK.GetValueConfidence(AttributeValues, "Female", ref ConfidenceFemale);

                        String str = (ConfidenceMale > ConfidenceFemale ? "Male" : "Female") + ", " +
                            (ConfidenceMale > ConfidenceFemale ? (int)(ConfidenceMale * 100) : (int)(ConfidenceFemale * 100)).ToString() + "%";

                        StringFormat format = new StringFormat();
                        format.Alignment = StringAlignment.Center;

                        gr.DrawString(str, new System.Drawing.Font("Arial", 16),
                            new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen),
                            facePosition.xc, top + w + 5, format);

                    }
                }

                // display current frame
                pictureBox1.Image = frameImage;

                GC.Collect(); // collect the garbage

                // make UI controls accessible
                Application.DoEvents();
            }
            FSDK.FreeTracker(tracker);

            FSDKCam.CloseVideoCamera(cameraHandle);
            FSDKCam.FinalizeCapturing();            
        }
 public byte[] GetFaceTemplateInRegion(ref FSDK.TFacePosition FacePosition)
 {
     byte[] tmpl;
     CheckForError(FSDK.GetFaceTemplateInRegion(hImage, ref FacePosition, out tmpl));
     return(tmpl);
 }
 public FSDK.TPoint[] DetectFacialFeaturesInRegion(ref FSDK.TFacePosition FacePosition)
 {
     FSDK.TPoint[] feats;
     CheckForError(FSDK.DetectFacialFeaturesInRegion(hImage, ref FacePosition, out feats));
     return(feats);
 }