如何在C#中从网络摄像头获取恒定的位图图像流 [英] How to grab constant stream of bitmap images from webcam in c#

查看:85
本文介绍了如何在C#中从网络摄像头获取恒定的位图图像流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个c#应用程序,可以对视频流进行处理。这是一个低级应用程序,它以位图格式接收每个帧,因此基本上我们每秒需要25张图像。该应用程序已经可以用于某些媒体资源,但是现在我们需要添加一个网络摄像头作为输入设备。

We have a c# application that performs processing on video streams. This is a low-level application that receives each frame in Bitmap format, so basically we need 25 images each second. This application is already working for some of our media sources, but we now need to add a webcam as an input device.

因此,我们基本上需要从网络摄像头,以便我们可以将所有这些帧作为流传递给我们的应用程序。

So we basically need to capture bitmap images from a webcam continuously so that we can pass all these frames as a "stream" to our application.

什么是访问网络摄像头并读取实际帧的最好和最简单的方法直接从网络摄像头作为单个图像?我仍然处在起步阶段。

What is the best and simplest way to access the webcam and read the actual frames directly from the webcam as individual images? I am still in the starting blocks.

那里有许多库,使人们可以访问网络摄像头,在Windows面板上预览网络摄像头的内容并然后使用屏幕捕获再次捕获该图像。不幸的是,每秒捕获25帧时,这不会给我们带来必要的性能。提到了IVMRWindowlessControl9 :: GetCurrentImage作为另一种选择,但这似乎又是针对不频繁的快照而不是恒定的图像流。许多人提到 Directshow.Net ,但尚不清楚如何简单地获取图像从网络摄像头。同样,许多消息来源都表示担心Microsoft不再支持Directshow。另外,我看到的实现需要ImageGrabber,它显然也是不再受支持。 MS的较新替代品似乎是Media Foundation,但我的研究尚未找到如何实现此方法的任何可行示例(而且我不确定该方法是否可以在较旧版本的Windows(例如XP)上运行)。 DirectX.Capture 是一个很棒的库(看到一个不错的实现),但似乎缺少直接获取视频图像的过滤器和方法。我也已经开始研究过滤器和过滤器图,但这似乎非常复杂,确实有点像重新发明轮子。

There are a multitude of libraries out there that allows one to access the webcam, preview the content of the webcam on a windows panel and then use screen capturing to capture this image again. This, unfortunately, will not give us the necessary performance when capturing 25 frames per second. IVMRWindowlessControl9::GetCurrentImage has been mentioned as another alternative, but this again seems to be aimed at an infrequent snapshot rather than a constant stream of images. Directshow.Net is mentioned by many as a good candidate, but it is unclear how to simply grab the images from the webcam. Also, many sources state a concern about Microsoft no longer supporting Directshow. Also, implementations I've seen of this requires ImageGrabber which is apparently also no longer supported. The newer alternative from MS seems to be Media Foundation, but my research hasn't turned up any working examples of how this can be implemented (and I'm not sure if this will run on older versions of windows such as XP). DirectX.Capture is an awesome library (see a nice implementation) but seems to lack the filters and methods to get the video images directly. I have also started looking at Filters and Filter Graphs but this seems awfully complex and does feel a bit like "reinventing the wheel".

总的来说,上面简要提到的所有解决方案似乎都已经过时了。有人可以帮我指出逐步指南的方向,以使网络摄像头可以在C#中工作并每秒从中捕获几张图像吗? (我们还必须在某些时候做音频,因此不排除视频的解决方案将是最有帮助的。)

Overall, all the solutions briefly mentioned above seem to rather old. Can someone please point me in the direction of a step-by-step guide for getting a webcam working in C# and grabbing several images per second from it? (We will also have to do audio at some point, so a solution that does not exclude video would be most helpful).

推荐答案

我使用AForge.Video(在此处找到:code.google.com/p/aforge/),因为它是非常快速的c#实现。我对性能非常满意,它可以在一台8岁的PC上轻松地以30fps的速度从两个高清网络摄像头捕获视频。数据作为本机IntPtr提供,因此非常适合使用本机代码或opencv进行进一步处理。

I use AForge.Video (find it here: code.google.com/p/aforge/) because it's a very fast c# implementation. i am very pleased with the performance and it effortlessly captures from two HD webcams at 30fps on an 8 year old PC. the data is supplied as a native IntPtr so it's ideal for further processing using native code or opencv.

opencv包装器emgu和opencvsharp都实现了基本的视频捕获功能,可能足以满足您的目的。显然,如果您要执行图像处理/计算机视觉,则可能仍要使用这些图像。

opencv wrappers emgu and opencvsharp both implement a rudimentary video capture functionality which might be sufficient for your purposes. clearly if you are going perform image processing / computer vision you might want to use those anyway.

这篇关于如何在C#中从网络摄像头获取恒定的位图图像流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆