Beispiel #1
0
        private void M_capture_ImageGrabbed(object sender, EventArgs e)
        {
            // Console.WriteLine("test: "  + startIndex.ToString());
            //  startIndex++;

            destin = SaveRecordingLocation_textbox.Text;

            if (fileChanged)
            {
                // destin = SaveRecordingLocation_textbox.Text;
                totalFrames = m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
                fps         = m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
                int    fourcc      = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FourCC));
                int    frameHeight = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight));
                int    frameWidth  = Convert.ToInt32(m_capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth));
                string destination = destin + i + ".avi";
                videoWriter = new Emgu.CV.VideoWriter(destination, Emgu.CV.VideoWriter.Fourcc('I', 'Y', 'U', 'V'), fps, new System.Drawing.Size(frameWidth, frameHeight), true);
                fileChanged = false;
            }


            Emgu.CV.Mat m = new Emgu.CV.Mat();
            m_capture.Retrieve(m);
            // pictureBox1.Image = m.ToImage<Bgr, byte>().Bitmap;
            videoWriter.Write(m);



            //throw new NotImplementedException();
        }
Beispiel #2
0
 private void Capture_ImageGrabbed(object sender, EventArgs e)
 {
     ActFrame = Convert.ToInt32(capture.GetCaptureProperty(CapProp.PosFrames));
     capture.Retrieve(Frame);
     //ProcessFrame(frame);
     ProcessFrameBallSearch(Frame);
 }
Beispiel #3
0
        // OnEnable is called just after the object is enabled
        void OnEnable()
        {
            if (useCamera)
            {
                capture = new Emgu.CV.VideoCapture(cameraId);
            }
            else if (videoPath != "")
            {
                capture         = new Emgu.CV.VideoCapture(videoPath);
                videoFrameCount = (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount);
                videoCaptureFps = (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps);
            }
            else
            {
                return;
            }

            cc = new CascadeClassifier(CASCADE_PATH);
        }
Beispiel #4
0
        private void OpenFile(string fileName)
        {
            Mat imgOriginal = null;

            try
            {
                imgOriginal = new Mat(fileName, ImreadModes.Color);
            }
            catch (Exception ex)
            {
                capture = new VideoCapture(fileName);
                if (capture == null)
                {
                    //lblTrackedColor.Text = "unable to open image, error: " + ex.Message;
                    return;
                }

                MaxFrames = Convert.ToInt32(capture.GetCaptureProperty(CapProp.FrameCount)) - 1;
                ActFrame  = 0;

                capture.ImageGrabbed += Capture_ImageGrabbed;
                capture.Start();
                VideoState = VideoState.Running;
            }

            if (imgOriginal == null)
            {
                if (capture == null)
                {
                    //lblTrackedColor.Text = "unable to open image";
                    return;
                }
                //imgOriginal = capture.QueryFrame();
            }
            else
            {
                ProcessFrame(imgOriginal);
            }

            UpdateUI();
        }
        public void showFrame()
        {
            if (this.InvokeRequired)
            {
                try
                {
                    ShowFrameDelegate SD = new ShowFrameDelegate(showFrame);
                    this.BeginInvoke(SD);
                }
                catch { }
            }
            else
            {
                if (ext == ".jpg")
                {
                    Emgu.CV.Mat matBefore = CvInvoke.Imread(Text_FilePath.Text);
                    Emgu.CV.Mat matAfter  = CvInvoke.Imread(SaveFileName);

                    if (matBefore != null && matAfter != null)
                    {
                        // bitmap是GDI+的物件,所以使用一般釋放記憶體的方式(dispose)對於bitmap是無效的
                        // 要能夠成功的釋放GDI+物件所佔用的記憶體,必須要使用Windows GDI元件,才能有效的釋放掉bitmap所使用的記憶體
                        // 將Bitmap物件轉換為平台指標
                        IntPtr gdibitmapBefore = matBefore.Bitmap.GetHbitmap();
                        IntPtr gdibitmapAfter  = matAfter.Bitmap.GetHbitmap();
                        // 將bitmap放入至PictureBox的Image屬性
                        File_Before.Image = Image.FromHbitmap(gdibitmapBefore);
                        File_After.Image  = Image.FromHbitmap(gdibitmapAfter);
                        // 進行Bitmap資源的釋放
                        DeleteObject(gdibitmapBefore);
                        DeleteObject(gdibitmapAfter);
                    }
                    if (matBefore != null)
                    {
                        matBefore.Dispose();
                    }
                    if (matAfter != null)
                    {
                        matAfter.Dispose();
                    }
                    GC.Collect();
                }
                else if (FrameCount == 0 || State == (int)PlayState.PlayState_Play)
                {
                    Emgu.CV.Mat matBefore = objVideoCapture_Before.QueryFrame();
                    Emgu.CV.Mat matAfter  = objVideoCapture_After.QueryFrame();

                    if (matBefore != null && matAfter != null)
                    {
                        FrameCount = objVideoCapture_Before.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.PosFrames);

                        // bitmap是GDI+的物件,所以使用一般釋放記憶體的方式(dispose)對於bitmap是無效的
                        // 要能夠成功的釋放GDI+物件所佔用的記憶體,必須要使用Windows GDI元件,才能有效的釋放掉bitmap所使用的記憶體
                        // 將Bitmap物件轉換為平台指標
                        IntPtr gdibitmapBefore = matBefore.Bitmap.GetHbitmap();
                        IntPtr gdibitmapAfter  = matAfter.Bitmap.GetHbitmap();
                        // 將bitmap放入至PictureBox的Image屬性
                        File_Before.Image = Image.FromHbitmap(gdibitmapBefore);
                        File_After.Image  = Image.FromHbitmap(gdibitmapAfter);
                        // 進行Bitmap資源的釋放
                        DeleteObject(gdibitmapBefore);
                        DeleteObject(gdibitmapAfter);
                    }
                    if (matBefore != null)
                    {
                        matBefore.Dispose();
                    }
                    if (matAfter != null)
                    {
                        matAfter.Dispose();
                    }
                    GC.Collect();
                }
            }
        }