Webcams, C # and a robust wrapper

I really need a replacement for the shell used in a C # application. Basically, we need to connect a webcam to one of two mailboxes. This will be used to capture still images at the touch of a button, which may disconnect the camera’s power and attach a still image to this image, and then reconnect the camera. Earlier, we used some free code to use with the CaptureDevice.cs and Pinvoke.dll file to associate it with avicap32.dll. Unfortunately, this seems to have random, intermittent errors that cannot be reliably reproduced. It is just too flaky. At some random point, one of these image boxes may be black and will not show the feed until the image is taken, and at that moment the correct image will be attached to the image window. Then, even if there is only one webcam, it will contain hints for choosing a webcam, otherwise it will not work otherwise.

Honestly, I am surprised and alarmed that Microsoft has not included anything in .NET to cover webcam videos. I am looking for something reliable and relatively simple to replace this faulty webcam.

+4
source share
3 answers

Can i suggest

http://www.emgu.com/wiki/index.php/Main_Page

I have used OpenCV in many C ++ libraries, and it seems to work fine for webcams from other things I tried. Emgu is just a C # shell for OpenCV.

Here is an example project to try it out. It is very simple and simple, but it should work right away.

http://dl.dropbox.com/u/18919663/vs%20samples/OpenCVCSharpTest.zip (just downloaded)

Example:

using Emgu.CV; using Emgu.CV.Structure; ... public partial class Form1 : Form { public Capture cvWebCam; public Form1() { InitializeComponent(); try { cvWebCam = new Capture(); timer1.Start(); } catch { Console.WriteLine("Default camera not found or could not start"); } } private void timer1_Tick(object sender, EventArgs e) { if (cvWebCam != null) using (Emgu.CV.Image<Bgr, byte> frame = cvWebCam.QueryFrame()) { pictureBox1.BackgroundImage = frame.ToBitmap(); } } } 
+1
source

Try DirectShow.net, a free cover library for accessing .NET DirectShow features: http://directshownet.sourceforge.net

His code samples have an example application for capturing video from webcams: http://sourceforge.net/projects/directshownet/files/DirectShowSamples/

0
source

It's time to use the MediaCapture object. Use this sample for MS Windows 10 https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CameraStarterKit/

And read also this article http://www.codepool.biz/csharp-camera-api-video-frame.html

0
source

Source: https://habr.com/ru/post/1394482/


All Articles