private void timer1_Tick(object sender, EventArgs e)
 {
     if (State == (int)PlayState.PlayState_Play)
     {
         objVideoCapture_Before.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, FrameCount);
         showFrame();
     }
     else
     {
         timer1.Stop();
     }
 }
Beispiel #2
0
        private bool InitObjects()
        {
            bool bRes = false;

            capture = new VideoCapture(0, VideoCapture.API.DShow);

            if (capture.CaptureSource == VideoCapture.CaptureModuleType.Camera && capture.IsOpened)
            {
                capture.SetCaptureProperty(CapProp.FrameWidth, 640);
                capture.SetCaptureProperty(CapProp.FrameHeight, 480);
                capture.SetCaptureProperty(CapProp.Fps, SettingsHolder.Instance.FPS);
                capture.ImageGrabbed += Capture_ImageGrabbed;
                bRes = true;
            }
            else
            {
                bRes = false;
            }

            return(bRes);
        }
Beispiel #3
0
        // Update is called once per frame
        void Update()
        {
            if (capture == null || cc == null)
            {
                return;
            }


            if (!useCamera)
            {//seek to correct video frame
                var vframe = (Time.time * videoCaptureFps) % videoFrameCount;
                capture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, vframe);
            }

            using (Image <Bgr, byte> img = capture.QueryFrame().ToImage <Bgr, byte>())
            {
                imageSize = img.Size;

                var faces = cc.DetectMultiScale(img, 1.1, 10);
                foreach (Rectangle face in faces)
                {
                    faceRectCenter = GetRectCenter(face);
                    DrawFaceMarkers(img, face);
                }

                if (texture is null)
                {
                    texture = new Texture2D(img.Width, img.Height);
                }
                texture.LoadImage(img.ToJpegData());

                if (imageBox != null && imageBox.isActiveAndEnabled)
                {
                    imageBox.texture = texture;
                }
            }

            playerData.EyePosition = FacePos;
        }
        private void btm_Start_Click(object sender, EventArgs e)
        {
            SF.Filter = "All files (*.*)|*.*";
            if (SF.ShowDialog() == DialogResult.OK)
            {
                int Index = SF.FileName.IndexOf(".");
                SaveFileName = (Index == -1 ? String.Concat(SF.FileName, ext) : String.Concat(SF.FileName.Substring(0, SF.FileName.IndexOf(".")), ext));
                SF.Dispose();
                if (ext == ".jpg")
                {
                    btm_Play.Enabled  = false;
                    btm_Pause.Enabled = false;
                    TSFaceDetection.TSFaceDetection tSFaceDetection = new TSFaceDetection.TSFaceDetection();
                    tSFaceDetection.FaceReduction(Text_FilePath.Text, "D:\\test.txt", SaveFileName);
                    showFrame();
                }
                else
                {
                    btm_Play.Enabled  = false;
                    btm_Pause.Enabled = false;
                    objVideoCapture   = null;
                    objVideoCapture   = new Emgu.CV.VideoCapture(Text_FilePath.Text);
                    TSFaceDetection.TSFaceDetection tSFaceDetection = new TSFaceDetection.TSFaceDetection();
                    tSFaceDetection.FaceReduction(Text_FilePath.Text, "D:\\test.txt", SaveFileName);

                    objVideoCapture_Before = new Emgu.CV.VideoCapture(Text_FilePath.Text);
                    objVideoCapture_After  = new Emgu.CV.VideoCapture(SaveFileName);
                    FrameCount             = 0;
                    objVideoCapture_Before.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, FrameCount);
                    objVideoCapture_After.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames, FrameCount);
                    showFrame();

                    btm_Play.Enabled  = true;
                    btm_Pause.Enabled = true;
                }
            }
        }