Jump to content

Webcam UDF


LIMITER
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

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
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 year later...

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?

Link to comment
Share on other sites

  • 2 weeks later...

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
[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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....

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • 4 months later...

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?!

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

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
Automatic Update UDF - IP Address UDF - WinPcap AutoIt _FindDevice()[font="Verdana"][size="2"]AutoIt Spanish/Brasil/World community!!![/size][/font]Use you wanna a dot.tk domain please use my link:
Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
Share on other sites

  • 1 month later...

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().

Link to comment
Share on other sites

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...