Author Topic: WebCam Video  (Read 10303 times)

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #15 on: November 30, 2015, 01:58:11 AM »
Ha! Marinus was faster, it seems. But just for comparison, I attach mine - pure VfW :biggrin:

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #16 on: November 30, 2015, 06:05:42 AM »
Hi Jochen,

Mine is much smaller ( that sounds a little weird...  :biggrin: ) and also vfw.  :t

BTW I got a black screen with your example.

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #17 on: November 30, 2015, 07:16:03 AM »
Hi Jochen,

Mine is much smaller ( that sounds a little weird...  :biggrin: ) and also vfw.  :t

BTW I got a black screen with your example.

Now that's lovely: for me it's the other way round... a black screen with your example. I am on Win7-64, and you?
Version 2 attached, with source (asc=rtf).

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #18 on: November 30, 2015, 07:34:01 AM »
I'm on win 8.1 64bit
That's weird, now I got a pink screen with your second example.

Can you select a camera ( combobox ) in my example?

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #19 on: November 30, 2015, 07:40:38 AM »
Yes, there is one. Check my source, there is a strange loop that you should try to add. It's a known problem that user needs several attempts to connect.

Btw my code just chooses device 0. Should work in principle...

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #20 on: November 30, 2015, 07:48:11 AM »
Here is the source code of the vfw example.
Mine also selects device 0 at startup.

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #21 on: November 30, 2015, 08:13:00 AM »
Think I had the preview rate wrong.

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #22 on: November 30, 2015, 08:35:34 AM »
No, that's not the problem. Your prog presents me with the infamous video source dialog. When clicking OK or Cancel repeatedly (2...5 times), eventually it will work. That is why I inserted that loop into my code.

Now one interesting question is why my prog won't work on your puter...

P.S.: It won't work on Win 8.1, either. Or rather: once after reboot.
Attached a version that started working on 8.1 after a minor modification.

Just in case anybody else is following this thread: FEEDBACK WELCOME!!! XP somebody? Win 10?
« Last Edit: November 30, 2015, 10:28:14 AM by jj2007 »

PriNet

  • Regular Member
  • *
  • Posts: 11
  • Using: MASM32
Re: WebCam Video
« Reply #23 on: November 30, 2015, 09:49:11 AM »
Hey again Marinus !
I'm glad your following me, I'm STILL working on figuring out the DirectShow approach, I think it could "broaden my horizons" ! Sounds like you can do alot with "COM". To answer your most recent questions:

Yes, when I (first) start my program, the source dialog pops up. That's what started this big adventure. I wanted to be able to (using the description) decide "which" source I want to attach to programmaticly, not through the source dialog.

Yes, I have more than 1(one) source on several of my computers here... TV cards, Video Capture (8-cam security system, which I want to be able to incorporate eventually also), sometimes a couple cameras, etc. This is why I was looking for a way to "set" the source programmaticly so I can just use an identifier (eventually) on the command line "which" source to use (but that's after I get things "working" *heh*).

And, yup, I'm trying to find a way to "choose" which camera/source to use without the dialog popping up.

Now, after all that... *lol*... let me look at what you sent and see what it looks like. oh, yea, thanks so much for your help and guidance, and hutch? thanx for the board here, I've learned a lot more in a week or so here than I have "surfing" the internet on my own for "several" weeks.
There has GOT to be a harder way...

jj2007

  • Member
  • *****
  • Posts: 7765
  • Assembler is fun ;-)
    • MasmBasic
Re: WebCam Video
« Reply #24 on: November 30, 2015, 10:34:15 AM »
P.S.: It won't work on Win 8.1, either. Or rather: once after reboot.

@Marinus: Does your prog work repeatedly? A common problem seems to be that WM_CAP_DRIVER_CONNECT works only once after a reboot - and no real solution on the World Wide Web. Actually, I spent quite a bit of time rebooting :(

PriNet

  • Regular Member
  • *
  • Posts: 11
  • Using: MASM32
Re: WebCam Video
« Reply #25 on: November 30, 2015, 04:58:08 PM »
ok, what you just sent is actually the one i studied so hard to get the "remote" program i originally posted above. I already used dictionary.com to translate alot of what i couldn't decipher on my own *lol*. It's a VERY good guide (if you can read ?dutch?) but alas, it does the same thing i'm having trouble with, it pops up the source dialog the same as mine when you first start the program. Did you say you knew a way to "assign" a source device programmaticly and stop that from popping up? THAT'S where i'm having the trouble. (i'm not abandoning the com research though, sounds intriguing)
There has GOT to be a harder way...

GoneFishing

  • Member
  • ****
  • Posts: 967
  • Gone fishing
Re: WebCam Video
« Reply #26 on: November 30, 2015, 07:29:33 PM »
...
Just in case anybody else is following this thread: FEEDBACK WELCOME!!! XP somebody? Win 10?
Unfortunately I don't have web cam . The subject of the thread looks interesting though

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #27 on: November 30, 2015, 08:29:40 PM »
P.S.: It won't work on Win 8.1, either. Or rather: once after reboot.

@Marinus: Does your prog work repeatedly? A common problem seems to be that WM_CAP_DRIVER_CONNECT works only once after a reboot - and no real solution on the World Wide Web. Actually, I spent quite a bit of time rebooting :(

Yes it works here repeatedly, the source dialog never pops up. Not on my 8.1 or my XP computers nor on my wifes W7 laptop.
Now, this is really strange and a behaviour I have never heard of.

How are we gonna fix this?

Did you say you knew a way to "assign" a source device programmaticly and stop that from popping up? THAT'S where i'm having the trouble.

I intended to just skip the camera selection and fill in the device number of the camera you want to use, but that will not solve the "source pop up" bug.

Is the DirectShow example working on all your computers?

Maybe we should focus our attention on DirectShow and leave VFW for what it is?
DirectShow is more flexible but requires more programming......

GoneFishing

  • Member
  • ****
  • Posts: 967
  • Gone fishing
Re: WebCam Video
« Reply #28 on: November 30, 2015, 09:19:20 PM »
Hi guys,
I've found something for you
Selecting a particular webcam
The good sign is that the thread is from Visual Basic forum  ;)
Pay attention to this:

Randy Hemingway
Quote
You can send a windows message to the video device handler that will activate a Video Source dialog that typically allows you to select which of the multiple cameras being serviced by the handler to use.  The message ID is: WM_CAP_DLG_VIDEOSOURCE.  The problem with this approach is that it requires user interaction, for example, you can't program the application to always select the second webcam.  If you don't mind a user dialog solution, the WM_CAP_DLG_VIDEOSOURCE approach should work fine.



Ricky Luk
Quote
The code provided above has references to functions like Getstring that wasnt included, but after I simplied the code it is a matter of

    RegOpenKey HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", lngKey
    RegSetValueEx lngKey, "DevicePath", 0, 1, ByVal Strdata, Len(Strdata)
    RegCloseKey lngKey
    capCreateCaptureWindow("CaptureWindow", WS_CHILD Or WS_VISIBLE, 0, 0, 0, 0, Picture4.hwnd, 0)

Then repeat 1-4 but this time write the second devicepath to registry and then kick the second camera.

PS. Remember not to put "SendMessage hCapWin2, WM_CAP_DLG_VIDEOSOURCE, 0, 0" so the video source window wont pop up.

And finally what seems to be the most valueable post  :

Christopher MCSE
Quote
Hi guys,

i recently bought 7 cheap web cams ambitiously thinking i could easily write an application to monitor all 7 symultaneously. oh i love learning things the hard way.

 

Anyway, The application ive written so far cant monitor all 7 at once, but it can switch cameras automatically without user interaction. it uses the avicap32.dll. I dont know if it will be any use to anyone but heres how i did it.

 

I discovered that when the user chose the camera source from the dialog that appears, it would write the path to the device in the registry, in the key HKLM\System\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM to a string called DevicePath.

 

So when the user launches the program for the first time, the program asks the user if they want to add a camera and goes into a loop until the answer is no.

 

in the loop:

the string DevicePath is deleted from the above mentioned key

the program then tells the driver to "connect", since avicap doesnt know which device to connect to it throws a dialog to the user asking which device to connect to.

when the user choses the device, the driver connects and displays a preview

the program then looks at the DevicePath string in the above mentioned key and saves the value to the program settings

my.settings.cameras.add(

My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\MediaResources\msvideo\MSVideo.VFWWDM", "DevicePath", Nothing))

 

when the user clicks No, they dont want to add any more cameras the program should now have an array of device paths for each camera attached.

 

now when the user clicks the button to start to capture, the program iterates through the array, chosing the next device in the array, it sets the value of DevicePath to the value of the selected element in the array, it tells the driver to connect and send the output to a picturebox for preview, then tells the driver to take a snapshop, saves the snapshot to disk, tells the driver to disconnect, and then deletes the value of DevicePath and the loop starts again.

 

this works, but isnt ideal. Ive found that each cycle for each camera takes about 2.5 to 3 seconds for the driver to connect, take snapshot, then disconnect. this means that if ive got 7 cameras attached it takes the program about 20 seconds to take snapshots from all 7 cameras.

 

anyway, it works for now. im actually trying to achieve a capture rate of at least 4 shots per second per camera, symultaneously.

 

ive got no idea if its possible using avicap32.dll but heres my theory (in case you were interested).

when then program tells the driver to connect, it reads the device path from the above mentioned registry key. the driver should only need to do this when it connects.

 

so I figure i can iterate through the device array, set the devicepath value in the registry, tell the driver to connect and send output to a new instance of the picturebox, then iterate to the next device, set the device path value in the registry, and tell the driver to connect and send output to a new instance of picturebox.

 

that way we get all cameras connected at the start of the program and dont have to worry about disconnecting the camera, switching the camera, reconnecting, etc..


no idea if this will work, im going to give it a try.

HTH

P.S.: You may try SysInternals Process Monitor to see if VFW reads / writes certain registry keys
P.P.S.: Tmax97's source code looks promising  :t

Siekmanski

  • Member
  • *****
  • Posts: 1145
Re: WebCam Video
« Reply #29 on: November 30, 2015, 09:59:24 PM »
Hi gonefishing,

Quote
the program then tells the driver to "connect", since avicap doesnt know which device to connect to it throws a dialog to the user asking which device to connect to.

We give the device number so avicap knows which device to connect:
   invoke   SendMessage,hCaptureWnd,WM_CAP_DRIVER_CONNECT,camera_devicenumber,0
This is where the source dialog pops up. ( or is it at: capCreateCaptureWindow ? )


He takes snapshots, we want full-rate movies.

Even at the Windows Development Center they can't give us a solution...

https://social.msdn.microsoft.com/Forums/windows/en-US/858192dd-fbc9-4ea1-91fc-9f2d8286b4f7/webcam-access-in-c-using-system-calls-only-works-once-per-restart?forum=winformsdatacontrols