How do I connect to a USB webcam in .NET? [closed]

2020-01-26 04:08发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 5 years ago.

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?

回答1:

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 Control with source.

Here are some more articles and blog posts from people looking to solve the same problem you are:

  • MSDN Coding4Fun: Look at me! Windows Image Acquisition
  • CodeProject: WIA Scripting and .NET
  • CodeProject: WebCam Fast Image Capture Service using WIA
  • clausn.dk: Webcam control from C# and WIA


回答2:

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.

Also, larger manufacturers like logitech have abandoned WIA is favor of DirectShow.



回答3:

Here is nice example of doing this. It's using DirectShow.Net (http://directshownet.sourceforge.net/), which is propably better than using "clipboard" :D.

https://www.codeproject.com/Articles/18511/Webcam-using-DirectShow-NET



回答4:

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.

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]



回答5:

On my computer, WIA was painstakingly sloooow... so i decided to give the Windows Multimedia Video Capture a try.

You can find a demo here.



回答6:

It really depends on what you want to do. WIA is primarily for capturing stills from imaging devices, and DirectShow (used either through directshow.net or managed DirectX) is for access to fuller video features.

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.