Jump to content

Webcam Udf


ludocus
 Share

Recommended Posts

This UDF doesn't work on any OS above XP (meaning Vista/7/and probably 8).

I don't think so - I did this under Windows 7 SP1 X64 and it works fine without any additional dlls. I'm using some kind of Creative Live! Cam (VFD230)

#include 
#include 

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)
Opt('GUICloseOnESC',0)


Global $mainWindow
Global $webCamHandler
Global $StatusBar


mainWindow()

_webcamClose($webCamHandler)
Exit


Func mainWindow()

local $filemenu,$actionmenu
local $exititem,$webCamSnapItem,$webCamRecStartItem,$webCamRecStopItem

$mainWindow=GUICreate("Webcam" , 820, 660)
GUISetBkColor(0xFFFFFF)

$filemenu = GUICtrlCreateMenu("&File")
$exititem = GUICtrlCreateMenuItem("Exit", $filemenu)

$actionmenu = GUICtrlCreateMenu("&Action")
$webCamSnapItem = GUICtrlCreateMenuItem("Take Snapshot", $actionmenu)
$webCamRecStartItem = GUICtrlCreateMenuItem("Start Recording", $actionmenu)
$webCamRecStopItem = GUICtrlCreateMenuItem("Stop Recording", $actionmenu)

$StatusBar = _GUICtrlStatusBar_Create($mainWindow)

GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSEClicked",$mainWindow)
GUICtrlSetOnEvent($exititem, "_CLOSEClicked")

GUICtrlSetOnEvent($webCamSnapItem, "_webCamSnapshot")
GUICtrlSetOnEvent($webCamRecStartItem, "_webCamRecStart")
GUICtrlSetOnEvent($webCamRecStopItem, "_webCamRecStop")

$webCamHandler=_WebcamOpen($mainWindow, 10,10, 800, 600,1)
ConsoleWrite("$webCamHandler="&$webCamHandler&@CRLF)

while 1

WEnd

EndFunc ;==> mainWindow()



; =============================================================================
; _webCamSnapshot
; =============================================================================
func _webCamSnapshot()
ConsoleWrite("_webCamSnap started...")
local $ergebnis=_WebcamSnap($webCamHandler, "$snapshot.BMP")
if $ergebnis=1 then
ConsoleWrite("...Success!"&@CRLF)
Else
ConsoleWrite("...Error:-("&@CRLF)
EndIf


EndFunc; ==> _webCamSnapshot

; =============================================================================
; _webCamRecStart
; =============================================================================
func _webCamRecStart()
ConsoleWrite("_webCamRecStart started..."&@CRLF)
local $ergebnis= _WebcamRecordStart("$video.avi", $webCamHandler)
if $ergebnis=1 then
ConsoleWrite("...Success!"&@CRLF)
_GUICtrlStatusBar_SetText($StatusBar, "Recording: ON")
Else
ConsoleWrite("...Error:-("&@CRLF)
EndIf



EndFunc; ==> _webCamRecStart

; =============================================================================
; _webCamRecStop
; =============================================================================
func _webCamRecStop()
ConsoleWrite("_webCamRecStop started..."&@CRLF)
local $ergebnis=_WebcamRecordStop($webCamHandler)
if $ergebnis=1 then
ConsoleWrite("...Success!"&@CRLF)
_GUICtrlStatusBar_SetText($StatusBar, "Recording: OFF")
Else
ConsoleWrite("...Error:-("&@CRLF)
EndIf

EndFunc; ==> _webCamRecStop


; =============================================================================
; _CLOSEClicked
; =============================================================================
func _CLOSEClicked()
Exit
EndFunc;==> _CLOSEClicked

But I also have some weird behavior regarding recording .... it works, but the .avi is huge!

Link to comment
Share on other sites

  • 1 month later...

I use this to test a webcam works but i have noticed odd behaviour with it

I run it like this

$gui = GUICreate("Test", 322, 242)
$camera = _WebcamOpen($gui, 1, 1, 320, 240)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
_WebcamClose($camera)
Exit
EndIf
Sleep(100)
WEnd

Which opens the webcam fine but you can only do it once, a reboot is needed to view it again?

Anyone able to make a guess why?

EDIT:

It crossed my mind whether the Dll's needed closing so ive added that and ill test tomorrow at work

Edited by Chimaera
Link to comment
Share on other sites

  • 4 months later...

Sorry for bumping an old thread but i'm facing a few problems in regards to this code..

My aim is to include a webcam inside of my GUI under a 'Webcam' tab in a tab menu. The tab menu is already full of different technician aiding codes like mic test, driver install menus, benchmark tests etc.

My problems when using the Webcam au3 are as follows:

1. For either my like of knowledge or simple blindsided-ness i can't seem to get the webcam to 'embed' within the gui. At best i can have it included in the main gui but it doesn't switch through tabbed windows, it remains 'ontop' of the entire GUI.

2. When i give up and just accept it's ontop for now it only shows a picture one time. Next load up it shows a black screen and requires selection of a video device. Was this due to the none-DLL closes Chimera was talking about?

Any help would be appreciated =] or a simple point in the right direction!

Regards

Nufan.

Link to comment
Share on other sites

  • 3 months later...

Problem.

For some reasons i no longer able to use this script.

I constantly get this window asking to select Video Source

post-70165-0-35040600-1384243213_thumb.j

After hours of goggling and trying different settings, i found this.

I opened Skype, previewed my face from there and closed it.

Then script was finally able to use my webcam

I suspect that somewhere something did not turn it off properly.

Do you guys know the fix ?

Edited by tonycst
Link to comment
Share on other sites

  • 11 months later...

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 comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...