views:

523

answers:

1

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  A: 

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.

SlavaGu
Thanks for the help. I tried replacing _videSourceIndex with 1, 2,3 none of them work the program dies instantly. Maybe cause I am trying to use the graphics right away? I dunno. I did check out the DirectShow.NET their demo for dxWebCam is big time overkill ( a service?) Maybe I just don't get it though...
Codejoy
Yah I played with it some more, the idea behind my program is to be super easy to set up. The minute I introduce network connectivity its not so easy to set up anymore for the end user IMHO. I would be trading the have to select a cam for the having to set up a service and connect to it. In my little demo I finally installed the service, started it and tried to have the client connect to it in which case it kept saying connection refused (and I am no network admin). Mabye its just the sample that is overly difficult for a sample. I do appreciate the help though.
Codejoy
We use DirectShow.NET successfully and I agree it is quite complex. This is because it is simply replicating most of DirectShow interfaces. You can try other free DirectShow libraries. They aren't that powerful but may be sufficient for your task: Emgu.CV (.NET port of OpenCV, which in turn uses DirectShow for accessing cameras on Windows)) http://www.emgu.com/wiki/index.php/Camera_Capture_in_7_lines_of_codeAForge.NET, haven't tried it myself but the documentation looks nice and many samples provided: http://www.aforgenet.com/framework/docs/
SlavaGu
SlavaGu you are the man. I realized I was using AForge for the motion stuff, didn't realize it had video too. Good video it seems, will have to test. But it gets Moniker Strings of all the camera adapters you have. I can have on install or first start have user pick which one they want to use, and save that value out somewhere (hell even a text file) to use that moniker from then on out, and if it ever fails show all the strings again and have them select another).Thats awesome THANKS SO MUCH!
Codejoy