摄像机的RSTP录像占用了太多的内存和CPU

时间:2019-05-04 04:22:50

标签: c# emgucv real-time-data

我能够实时流式传输并在EMGU cv中录制视频,最新版本为4.0.1.3373 我的问题是,当我使用视频编写器记录摄像机的实时流时,会占用大量内存和CPU 如何不使用太多内存和CPU来增强它?以及如何在录制时添加一些面部检测和识别?

public Form1()
    {
        InitializeComponent();
        _capture = new VideoCapture("rtsp camera link");        
        _capture.ImageGrabbed += ProcessFrame;
        _frame = new Mat();
        if (_capture != null)
        {
            try
            {
                _capture.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
    private void ProcessFrame(object sender, EventArgs e)
    {
        if (_capture != null && _capture.Ptr != IntPtr.Zero)
        {
            _capture.Retrieve(_frame);
            pictureBox1.Image = _frame.Bitmap;

            if (recording && VW!=null)
            {
                VW.Write(_frame);
            }
        }
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        if (_capture == null)
            return;
        recording = true;
        button1.Enabled = false;
        button2.Enabled = true;
        int frameWidth = Convert.ToInt32(_capture.GetCaptureProperty(CapProp.FrameWidth));
        int frameHeigt = Convert.ToInt32(_capture.GetCaptureProperty(CapProp.FrameHeight));
        string destination = @"C:\Users\user\Desktop\Videos\output.mp4";
        VW = new VideoWriter(destination, VideoWriter.Fourcc('H', '2', '6', '4'), 30, new Size(1920, 1080), true);
    }
    private void button2_Click_1(object sender, EventArgs e)
    {
        button1.Enabled = true;
        button2.Enabled = false;
        recording = false;
        if(VW!=null)
            VW.Dispose();
        MessageBox.Show("Saved");
    }
    private void Form1_Load_1(object sender, EventArgs e)
    {
        button1.Enabled = true;
        button2.Enabled = false;
        recording = false;
    }

0 个答案:

没有答案