C# web cam WM_CAP_CONNECT: Want to force a capture

2019-07-18 06:08发布

问题:

I am using WebCam_Capture code I found online to access through C# a web cam. On a computer with one video source it works like a charm! (Program starts up at start up, finds the webcam and it works).

Though on a computer with many video sources (Say a web cam and then manycam running on top of that), the program starts and queries the user which source to use. I would love my program to start up autonomously at the restart of a machine so this waiting for user input throws a wrench in that, anyway I can force it to just select say the first found source and go with that?

So i have some webcam code I yes indeed found online here:

http://channel9.msdn.com/forums/TechOff/93476-Programatically-Using-A-Webcam-In-C/?CommentID=94149

and now in preparing this post I did do more research and found out that my issue lies in this line from the above code:

SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);

That is what connects the webcam up, the only issue is that the above brings up this annoying video source dialog if I have more than one source. I want it to just use the first source so that dialog doesn't come up. I tried passing in different values where the 0's are, sure enough the dialog doesn't come up but it doesn't work either. Anyone know if there is a value I can pass to the SendMessage to suspend the dialog and yet have it select the first video source it finds?

回答1:

The only hint I found is that the first 0 is the camera index:

SendMessage(_windowHandle, WM_CAP_CONNECT, _videoSourceIndex, 0)

Try to give 0,1,2 until the desired camera is connected. Note it may take up to 5 sec until a webcam responds. Some of them are pretty slow.

But the best suggestion would be to try out DirectShow.NET library as it is much more capable than the API you're currently using.