我的代码适用于内置摄像头,但我想从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();
}