Emgu opencv捕获RTSP / HTTP媒体流太慢

时间:2016-10-12 02:42:46

标签: opencv emgucv

我的代码适用于内置摄像头,但我想从IP摄像头捕获一个流。然而,饲料运行非常慢。我怎样才能跳过帧,所以我总是看到最新的帧。对于我正在做的事情,拥有一个完美的流式视频并不是很重要,而是实时获取帧。

        while (true)
        {
            // try to open the camera device
            if (capture == null)
            {
                try
                {
                    int index;
                    bool isNumeric = int.TryParse(ConfigurationManager.AppSettings["CameraSource"], out index);
                    capture = isNumeric ? new Capture(index) : new Capture(ConfigurationManager.AppSettings["CameraSource"]);
                }
                catch
                {
                    frameObservers.ForEach(a => a.frame(cameraNotConnectedBitmap, new List<Person>(), recognizer.isActive()));
                }
                Task.Delay(1000).Wait();
                continue;
            }

            // read a frame from the camera
            Mat matFrame = capture.QueryFrame();
            Image<Bgr, byte> frame = (matFrame == null) ? null : matFrame.ToImage<Bgr, byte>();
            if (frame == null)
            {
                frameObservers.ForEach(a => a.frame(cameraNotConnectedBitmap, new List<Person>(), recognizer.isActive()));
                capture = null; // force to reconnect to camera again
                Task.Delay(1000).Wait();
                continue;
            }

            frameObservers.ForEach(a => a.frame(frame, personsInCurrentFrame, recognizer.isActive()));

            Task.Delay(10).Wait();
        }

0 个答案:

没有答案