Jump to content

Recommended Posts

The UDF from worked for me, though trying to stop it, etc. didn't.

What I wanted is to have a way to take a picture 'at will', then show that latest picture for as long as I wanted, then switch back to the webcam when I wanted (in other words, some sort of control over what is happening as well as getting that latest pic to show - in the same spot as the webcam).

My total application is not done, so there may be more features I'll put in overall, though here's some code (tested, working on my system) that might be of use to others.  Note that it uses 'brute force' methods as I'm still new to GUI, etc. but the end result is that it works!

#include <GUIConstants.au3>
#include <WebcamUDF.au3>

; create webcam
$webcamgui = GUICreate("webcam", 250, 192, @DesktopWidth/2 - 250/2,@DesktopHeight/2 - 192/2, $WS_POPUP)
_WebcamInit()
_Webcam($webcamgui, 250, 192, 0, 0)
GUISetState(@SW_SHOW)
$picgui = GUICreate("picture", 251, 192, @DesktopWidth/2 - 250/2, @DesktopHeight/2 - 192/2, $WS_POPUP)
GUISetState(@SW_HIDE)
; create controls
$gui = GUICreate("controls", 250, 80, @DesktopWidth/2 - 250/2,  @DesktopHeight/2 - 192/2 + 192,$WS_POPUP)
$button = GUICtrlCreateButton("picture", 10, 10)
$webcam = GUICtrlCreateButton("webcam", 90, 10)
$snapit = GUICtrlCreateButton("Take Picture", 160,10)
$closeit = GUICtrlCreateButton("Close",90,50)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE,$closeit
            _WebcamStop()
            Exit
        Case $button
            ; create picture
            $picgui = GUICreate("picture", 250, 192, @DesktopWidth/2 - 250/2, @DesktopHeight/2 - 192/2, $WS_POPUP)
            $picshow = GUICtrlCreatePic("snapshot.bmp", 0, 0, 250, 192)
            GUISetState(@SW_SHOW)
        Case $webcam
            GUIDelete($picgui)
        case $snapit
            GUIDelete($picgui)
            ConsoleWrite("Taking snapshot ..." & @CRLF)
            _WebcamSnapShot()
            ConsoleWrite("Snapshot taken !" & @CRLF)
    EndSwitch
WEnd
Edited by TechCoder
Link to post
Share on other sites
  • 8 months later...
  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hello, everyone.

I believe I have found the reason for having the video source popup with Windows 7 /8... It relates to UAC and Run as Admin approach. If I run the script or compiled .exe as ADMIN, it always works AFTER I have initially selected a default device via that popup box. The good news is that the default device can be pre-configured, as it is simply a registry value in HKLM (which explains why if NOT run as admin - will never save the default selection via the popup, neither will succeed to read the registry if it is already setup)!!!

So this is what I have done to figure it out and being able to set the default capture device on other machines to successfully use the webcam UDF and never have the video source popup appear (just remember that it ONLY works when run as admin):

1. Run the script as Admin, got the popup to select a default device as expected (even with only one webcam present);

2. Clicked the OK button - script completed successfully;

3. Used regedit to open and navigate to:

    HKLMSYSTEMCurrentControlSetControlMediaResourcesmsvideoMSVideo.VFWWDM

    A new STRING (REG_SZ) Value was created, named "DevicePath" (without the quotes), and its DATA is:

    ?root#image#0000#{GUID}global

    ... where GUID is the unique ID of the webcam you have on your device. It can be verified/found in:

     HKLMSYSTEMCurrentControlSetControlMediaCategories{GUID}Name(REG_SZ)=Capture

     There are many GUID registry keys there, but the correct one has a VALUE "Name"=Capture

One good reference to point me in this direction was here:

http://stackoverflow.com/questions/10721085/webcam-video-source-dialog-comes-up

So at this point I don't think the script fails to close the dll or disconnect the driver after done...

Link to post
Share on other sites

Nice find, but what if you have two registry keys with the value "Name"=Capture, do you edit them both??

 

I believe there are always 2 entries for "Name"=Capture, regardless of the device's manufacturer/hardware. It is probably more of a windows (OS) GUID standard for the capture-capable devices, rather than a GUID of the hardware device itself. Therefore, I have noticed that the ID we need is

{65e8773d-8f56-11d0-a3b9-00a0c9223196}. Tested on 4 different laptops (2 models Lenovo, Dell, Toshiba) and it is always the same...
 
After more testing, I found more interesting results:
 
The webcam UDF never worked with any webcam that has just the default Microsoft Driver installed (Device Manager will show "Integrated Camera" under Imaging Devices", and properties will show MS driver from 2006 or so) - that is useless.
 
If a 3rd party (vendor's) drivers are installed, as it should be, then it works for probably 90% or more of the devices I have tested with.
 
But the most important is that each webcam responds differently on the same UDF, so it all comes down to test and find the way that works. I will now list what I have experienced with different devices, so hope it helps other people out there to make it work:
 
1. Lenovo laptops (X230 with Windows 7x64, and Yoga11e with Windows 8.1 x64):
    They have the so called communications utility, which is similar to the webcam application for other vendors, and therefore in the Device Manager        under Imaging devices there will be 2 entries (even though there is only one, built-in cam):
     - Camera Plus (this is the Lenovo's driver entry)
     - Integrated Camera (this is the Microsoft's default driver entry)
 
     So in these 2 devices, I had to create the registry value (as per my previous post), so the the default device is set to be the "Camera Plus", in order to avoid the "video Source" popup. Note that BOTH entries in the device manager are SAME physical device, so the UDF pointing to 0 (zero) port alone is not enough to avoid the popup! That is when the registry value fixes the issue.
Here, the UDF snapshot works everytime (compiled as 64 bit executable). No need to reboot the device, or to initiate another utility that controls the webcam. Just remember that it must be run as ADMIN...
 
2. Dell Latitude 2100 laptop with Windows 7 x32 (old laptop, but different hardware, so perfect for testing):
    Here the Device manager has only one entry under the Imaging Devices - "Integrated Webcam". I had to install a driver that was rated for Vista, cause there was non for 7. Before so, the default MS driver did not work with the UDF, and device was listed as "Integrated Camera". After the vendor's driver installed (Provider info was "Creative technology, Ltd") - it works everytime just as the above, but here the executable is 32 bit compiled and aslo I did not have to create the registry value for the default device path (as it is only one listed) - it gets auto created the first time I run the compiled UDF. Again - it must be run as ADMIN.
 
3. Toshiba Satellite A665 with Windows 7 x64 - This one is the weirdest of all, and believe it comes down simply to the hardware vendor for the webcam and the driver/application to control it...
 
     So it is only 1 device listed in the device manager - "Chicony 2.0 USB Camera". The problem is that even though there is the official Toshiba Web cam application installed and function (can start the webcam, use it, manipulate various settings) - the driver is still Microsoft's default from 2006. So doesn't work! Tried Updating the driver via MS update, then manually point it to the .INF driver file (via "browse my computer.." option) where the webcam application is installed - both cases the OS says no better match found! So the only way to install that 3rd party driver was to still select to browse locally option, but next instead of actually browsing, I selected the option PICK FROM A LIST... Then selected Microsoft as Vendor, and "USB Video Device" as the hardware to update. Then used the "Have Disk..." button and then point it to the .INF file - and it finally installed it. The device manager now displayed "PanGu" under Imaging Devices (weird!) and the driver provider was listed as TOSHIBA.
After reboot the UDF to take snapshot worked only once, then if I try again it would bring the "Video Source" popup, and regardless of what I choose (cancel, select, X-out; with the device selected already, as it is the only one available) it will only create a blank snapshot. So in this case it does come down to the fact that the function to disconnect the driver after done is not executing correctly. So it will only work after a reboot again, one time only again. So then I tested it differently (as other suggest using skype to control the cam and the UDF works during that time) - I tried another way: If I start the Toshiba's webcam application AND disconnect the webcam via the application's "fancy" settings options (meaning I have the GUI of the application opened, but stopped the webcam from feeding input, so the window is blank) - then the UDF Snapshot works everytime! But as soon as I start using the cam via the application, or close the application, the only way to take another snapshot is rebooting the laptop...
 
 
So to wrap it up - with most laptops it can be done (as my 1st and 2nd cases above), but for some devices the hardware and its available drivers/apps just suck, so additional steps must be done to make it work, even though it is not the desired way to do so...
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...