C# 如何在 .NET 中连接到 USB 网络摄像头?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/113426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I connect to a USB webcam in .NET?
提问by
I want to connect to a USB Webcam in .NET, specifically using C#. Being new to .NET I don't know what kind of support there is in the standard libraries for doing so. I found one example on the web that copies bitmaps through the clipboard, but that seems very hacky (and probably slow). Is there a better way?
我想连接到 .NET 中的 USB 网络摄像头,特别是使用 C#。作为 .NET 的新手,我不知道标准库中对此有什么样的支持。我在网上找到了一个通过剪贴板复制位图的例子,但这看起来很笨拙(而且可能很慢)。有没有更好的办法?
回答by Eric Schoonover
You will need to use Windows Image Acquisition (WIA)to integrate a webcam with your application. There are plenty examples of this readily available. Here is a C# Webcam User Controlwith source.
您将需要使用Windows Image Acquisition (WIA)将网络摄像头与您的应用程序集成。有很多这方面的例子。这是一个带有源代码的C# 网络摄像头用户控件。
Here are some more articles and blog posts from people looking to solve the same problem you are:
以下是一些希望解决与您相同的问题的人的更多文章和博客文章:
回答by Crank
Here is nice example of doing this. It's using DirectShow.Net (http://directshownet.sourceforge.net/), which is propably better than using "clipboard" :D.
这是一个很好的例子。它使用 DirectShow.Net ( http://directshownet.sourceforge.net/),这可能比使用“剪贴板”更好:D。
https://www.codeproject.com/Articles/18511/Webcam-using-DirectShow-NET
https://www.codeproject.com/Articles/18511/Webcam-using-DirectShow-NET
回答by timvw
On my computer, WIA was painstakingly sloooow... so i decided to give the Windows Multimedia Video Capturea try.
在我的电脑上,WIA 非常慢......所以我决定尝试一下Windows 多媒体视频捕获。
You can find a demo here.
您可以在此处找到演示。
回答by Sneaky
It really depends on what you want to do. WIA is primarily for capturing stills from imaging devices, and DirectShow (used either through directshow.netor managed DirectX) is for access to fuller video features.
这真的取决于你想做什么。WIA 主要用于从成像设备捕获静止图像,而 DirectShow(通过directshow.net或托管 DirectX 使用)用于访问更完整的视频功能。
The other option is to create a WPF application. It has a huge amount of built in support for video (to the extent that having a looping video clip as a button is pretty trivial), and should be quick and easy to develop.
另一种选择是创建 WPF 应用程序。它有大量内置的视频支持(在某种程度上,将循环视频剪辑作为按钮非常简单),并且应该快速且易于开发。
回答by JoelHess
Interesting side note, WIA isn't supported by Vista for doing Captures from Webcams anymore. They mainly targeted it towards Scanners and pulling stills from cameras.
有趣的旁注,Vista 不再支持 WIA 从网络摄像头进行捕获。他们主要针对扫描仪并从相机中提取静止图像。
Also, larger manufacturers like logitech have abandoned WIA is favor of DirectShow.
还有,像罗技这样的大厂商已经放弃了 WIA 是 DirectShow 的青睐。
回答by Kurru
Theres a package with functions with a lot of things to do with computer vision systems called AForge. And they have an easy way to get webcam images from a USB camera if you're still looking.
有一个包含许多功能的包与称为 AForge 的计算机视觉系统有关。如果您还在寻找,他们有一种简单的方法可以从 USB 摄像头获取网络摄像头图像。
Just check out the sample code for computer vision motion sensor example code. I'm sure you can pull out the function calls you need from it as I did.
只需查看计算机视觉运动传感器示例代码的示例代码即可。我相信你可以像我一样从中提取出你需要的函数调用。
[sorry to necro, but this could be of use to someone in the future]
[抱歉死灵,但这可能对将来的某人有用]