Камера RSTP для записи видео использует так много памяти и процессора - PullRequest
0 голосов
/ 04 мая 2019

Мне удалось транслировать и записывать видео в EMGU cv, последняя версия 4.0.1.3373 моя проблема в том, что когда я записываю видео в реальном времени с камеры, используя видеомагнитофон, она использует так много памяти и процессора как улучшить это, чтобы не использовать столько памяти и процессора ?? и как я могу добавить распознавание лиц и распознавание во время записи?

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;
    }
...