C# emgu захват камеры и утечка памяти?

У меня есть следующий код в 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 показывает потребление памяти процессом 2 ГБ данных. Иногда я получаю следующую ошибку:
"Ошибка захвата видео #1: opencv: u!= 0"
и приложение останавливается, чтобы показать любой вывод камеры.

Я предполагаю, что у меня есть какая-то утечка памяти в приведенном выше коде.
Это странно, потому что я написал этот код в соответствии с учебниками.
Не могли бы вы помочь мне, что не так с этим кодом?

0 ответов

Другие вопросы по тегам