Sign in to follow this  
Followers 0

Webcam UDF

44 posts in this topic

#1 ·  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



#2 ·  Posted

lol I made a webcam udf as well :)


Udf's:[topic="71394"]MiscConstants[/topic] - [topic="72249"]LangConstants[/topic] - [topic="70857"]Webcam Udf[/topic][topic="67425"]Set Walpaper[/topic] - [topic="71458"]Movie Udf[/topic] - [topic="74583"]Cmd Udf[/topic][topic="81662"]Find Lyrics Udf[/topic] - [topic="81935"]CustomBox Udf[/topic] - [topic="119885"]_Communicate UDF[/topic]Progs:[topic="71722"]HandyScript[/topic] - [topic="71148"]Basic Calc[/topic] - [topic="68178"]Cool win effect![/topic][topic="72535"]Easy Editor[/topic] - [topic="73070"]Billing[/topic] - [topic="73210"]Calculate energy cost[/topic][topic="74249"]Watch out![/topic] - [topic="74783"]WinHider[/topic] - [topic="75236"]SBA Task Manager[/topic][topic="119185"]Ultimate Talker[/topic] - [topic="119483"]Password Safer[/topic] - [topic="120223]FreeRider GameConsole[/topic][topic="125852"]Face regognizer[/topic]White Eagle Media Player: [topic="75854"]topic[/topic] downloadAll My Scripts[URL=http://swagbucks.com/?cmd=sb-register&rb=2427158][IMG]http://prodegebanners.sitegrip.com/images/swagbucks-468x60Alt4.jpg[/IMG][/URL](You'll get swagbucks and you can trade 'em in for prizes directly!)

Share this post


Link to post
Share on other sites

#5 ·  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

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]

Share this post


Link to post
Share on other sites

#6 ·  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

#7 ·  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

#8 ·  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

#9 ·  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

#10 ·  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

#11 ·  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

[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]

Share this post


Link to post
Share on other sites

#12 ·  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

My work in AutoIt (Not many yet):

Parse Large Text Files To 2D Array Quickly [With Chunk Size]

 

My artificial intelligence project coded entirely in AutoIt. Meet Alice Assistant: http://facebook.com/ProjectAliceAI

 

Share this post


Link to post
Share on other sites

#13 ·  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....


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

Share this post


Link to post
Share on other sites

#14 ·  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

#16 ·  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

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:

Share this post


Link to post
Share on other sites

#17 ·  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

#18 ·  Posted

Nice, very nice


Gnatwork Networks

Share this post


Link to post
Share on other sites

#19 ·  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

#20 ·  Posted

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