0

我在 C# 中有以下代码,使用 emgu 进行相机捕获:

    //video capture
    private Capture videoCapture = null;  //takes images from camera as image frames
    private Image<Bgr, Byte> videoCaptureImageFrame;
    private Image<Bgr, Byte> videoCaptureResizedFrame;
    //video capture

    private void ProcessFrame(object sender, EventArgs arg)
    {
        try
        {
            videoCaptureImageFrame = videoCapture.QueryFrame().ToImage<Bgr, Byte>();   

            if (videoCaptureImageFrame != null)
            {
                videoCaptureResizedFrame = videoCaptureImageFrame.Resize(960, 540, Emgu.CV.CvEnum.Inter.Cubic);                                        
                VideoCapturePictureBox.Image = videoCaptureResizedFrame.ToBitmap();                      
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show("Video capture error #1: " + ex.Message.ToString());
        }
    }

    public void VideoCaptureReleaseData()
    {
        if (videoCapture != null)
            videoCapture.Dispose();
    }

    //video capture  
    private void MainForm_Load(object sender, EventArgs e)
    {
        //Dispose of Capture if it was created before
        if (videoCapture != null) videoCapture.Dispose();

        //video capture
        if (videoCapture == null)
        {                
            try
            {
                videoCapture = new Capture(0);
                videoCapture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameWidth, 1920);
                videoCapture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameHeight, 1080);
                videoCapture.SetCaptureProperty(Emgu.CV.CvEnum.CapProp.FrameCount, 25);

                Application.Idle += ProcessFrame;
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show("Video capture error #2: " + excpt.Message);
            }
        }
        //video capture
    }

此代码运行良好,但我可以看到 Visual Studio 2015 不时显示 2GB 数据的进程内存消耗。有时我收到以下错误:
“视频捕获错误#1:opencv:u!= 0”
并且应用程序停止显示任何相机输出。

我假设我在上面的代码中有某种内存泄漏。
这很奇怪,因为我根据教程编写了这段代码。
你能帮我看看这段代码有什么问题吗?

4

0 回答 0