Sign in to follow this  
Followers 0

Webcam UDF

44 posts in this topic

Posted (edited)

Thx rysiora for his awesome script :D (hope you don't get mad at me :D )

Original post (rysiora's version): http://www.autoitscript.com/forum/index.php?showtopic=27925

Just modified the script a little and made it an UDF ...

Example code :

#include <GUIConstants.au3>
#include <Webcam.au3>

$gui = GUICreate("Webcam UDF Test",640,480)
_WebcamInit()
_Webcam($gui,640,480,0,0)
GUISetState(@SW_SHOW)
Sleep(2000)
ConsoleWrite("Taking snapshot ..." & @CRLF)
_WebcamSnapShot()
ConsoleWrite("Snapshot taken !" & @CRLF)

While 1
 $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
  _WebcamStop()
  Exit
 EndIf
 Sleep(1)
WEnd

Webcam UDF

Webcam.au3

Edited by LIMITER

Share this post


Link to post
Share on other sites



Posted

lol I made a webcam udf as well :)

Share this post


Link to post
Share on other sites

Posted

Link to the original topic. :( but otherwise good job converting it... I guess. :)

Share this post


Link to post
Share on other sites

Posted

Why is it taking only 1 snapshot if I write the code like this? IT should Take 3 right?

For $sdf = 1 to 3
    Sleep(2000)
    ConsoleWrite("Taking snapshot ..." & @CRLF)
    _WebcamSnapShot()
Next

Share this post


Link to post
Share on other sites

Posted

It should take 3 ....

I'll check the code later, cause now i don't have a webcam at this pc :)

Share this post


Link to post
Share on other sites

Posted

any ideas on how you change the resolution of the output bmp file?

i can only ever get a 320x240 file, even though my web cam can do up to 1600x1200.

Any help would be much appreciated!

Share this post


Link to post
Share on other sites

Posted (edited)

Maybe....

#include <GUIConstants.au3>
#include <Webcam.au3>

$gui = GUICreate("Webcam UDF Test",1600,1200)
_WebcamInit()
_Webcam($gui,1600,120,0,0)
GUISetState(@SW_SHOW)
Sleep(2000)
ConsoleWrite("Taking snapshot ..." & @CRLF)
_WebcamSnapShot()
ConsoleWrite("Snapshot taken !" & @CRLF)

While 1
 $msg = GUIGetMsg()
	If $msg = $GUI_EVENT_CLOSE Then
  _WebcamStop()
  Exit
 EndIf
 Sleep(1)
WEnd
Edited by Bert

Share this post


Link to post
Share on other sites

Posted (edited)

thanks for your help Bert,

i should of mentioned, i had tried that - the visible image becomes pixulated, as if it is stretching the 320x240, and the output file is still 320x240 muttley

I am planning to use a webcam to do timelapse photos of a building being built, and then turn it into a video - but i need higher than 320x240...

EDIT:

Ok, worked it out

adding the line:

DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DLG_VIDEOFORMAT, "int", 1, "int", 0)

triggers a dialog box which allows you to set resolution. once set, it will be remembered (i suspect thru the registry somewhere)

Cheers

Edited by boomingranny

Share this post


Link to post
Share on other sites

Posted

May I know is it possible to adjust the quality settings of webcam (eg. brightness, contrast, gamma, etc) and is there any way of reading back the different settings from the current webcam before I set it?

Share this post


Link to post
Share on other sites

Posted (edited)

Some thoughts on your UDF

First, is there a way to capture some output without having to open a GUI control. Because if I don't call _Webcam() the array $cap is never declared.

And as far as i understand, the _WebcamSnapShot() does read the output from the previously created controll.

And why open this DLL if it is never used?

$avi = DllOpen("avicap32.dll")

Edit: Saw that it was used...

Edited by colafrysen

Share this post


Link to post
Share on other sites

Posted

Why is it taking only 1 snapshot if I write the code like this? IT should Take 3 right?

For $sdf = 1 to 3
    Sleep(2000)
    ConsoleWrite("Taking snapshot ..." & @CRLF)
    _WebcamSnapShot()
Next

The _WebcamSnapShot() function overwrites the default snapshot.bmp file. If you want three different shots then you must use a variable. Here's how you can achieve this. >_<

#include <GUIConstants.au3>
#include <Webcam.au3>
#include <WindowsConstants.au3>

$gui = GUICreate("Webcam UDF Test",640,480)
_WebcamInit()
_Webcam($gui,640,480,0,0)
GUISetState(@SW_SHOW)
Sleep(2000)
For $sdf = 1 to 3
    Sleep(2000)
    ConsoleWrite("Taking snapshot ..." &$sdf& @CRLF)
    _WebcamSnapShot(@DesktopDir & "\snapshot"&$sdf&".bmp")
Next
While 1
 $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
  _WebcamStop()
  Exit
 EndIf
 Sleep(1)
WEnd

Share this post


Link to post
Share on other sites

Posted

I dont really understand how this works, but could anyone show a small example of how this could be streamed over a network and displayed on a remote PC instead of on the local one? I think that would be reall cool.  I would try it but I am nto good in the area of DLL calls and such, as well as i dont understand how this works at all....

Share this post


Link to post
Share on other sites

Posted

I've got a problem with te function _WebcamStop():

Every time i call it -> Autoit3.exe must close ..... error

I think the problem is on the $avi dll (avicap32.dll) because when I comment the line "DllClose($avi)" there is no problem!

but I want to close the webcam without exiting the script!

Anyone could help?!

Share this post


Link to post
Share on other sites

Posted

get error variable not declared

Share this post


Link to post
Share on other sites

Posted (edited)

With all webcam UDFs I get these errors:

C:\Documents and Settings\Gisele\Desktop\Nova pasta\webcam.au3(122,91) : WARNING: $WS_CHILD: possibly used before declaration.

$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Gisele\Desktop\Nova pasta\webcam.au3(122,103) : WARNING: $WS_VISIBLE: possibly used before declaration.

$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Gisele\Desktop\Nova pasta\webcam.au3(122,91) : ERROR: $WS_CHILD: undeclared global variable.

$cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Gisele\Desktop\Nova pasta\webcam.au3 - 1 error(s), 2 warning(s)

Why? I have tryed stable and beta.

Thanks in advance.

Edited by Splash

Share this post


Link to post
Share on other sites

Posted

Hi!

I tested on four computers.

For the first, it's OK, whenever.

For other (three), if works only once. When I re-run the script, the webcam does not open, until I restart the computer.

I tried also to close/re-open a session, but the problem remains.

The first CPU is on W7

Other : W7 , W7 , XP

Any idea?

Share this post


Link to post
Share on other sites

Posted

Nice, very nice

Share this post


Link to post
Share on other sites

Posted

I've got a problem with te function _WebcamStop():

Every time i call it -> Autoit3.exe must close ..... error

I think the problem is on the $avi dll (avicap32.dll) because when I comment the line "DllClose($avi)" there is no problem!

but I want to close the webcam without exiting the script!

Anyone could help?!

You need to destroy the gui used for webcam.

Call GUIDelete() before WebcamStop().

Share this post


Link to post
Share on other sites

Posted

You need to destroy the gui used for webcam.

Call GUIDelete() before WebcamStop().

Its April now. Useless first post.

Share this post


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
Sign in to follow this  
Followers 0