Jump to content



Photo

Webcam Udf


  • Please log in to reply
21 replies to this topic

#1 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 09 May 2008 - 05:26 PM

Made a udf to rysiora's webcam example,


Webcam.au3 (the udf)
AutoIt         
#include <WindowsConstants.au3> #include-once $WM_CAP_START = 0x400 $WM_CAP_UNICODE_START = $WM_CAP_START +100 $WM_CAP_PAL_SAVEA = $WM_CAP_START + 81 $WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81 $WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW $WM_CAP_ABORT = $WM_CAP_START + 69 $WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46 $WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43 $WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41 $WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42 $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10 $WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11 $WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14 $WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12 $WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12 $WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13 $WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13 $WM_CAP_EDIT_COPY = $WM_CAP_START + 30 $WM_CAP_END = $WM_CAP_UNICODE_END $WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22 $WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21 $WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21 $WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23 $WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23 $WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25 $WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25 $WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20 $WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20 $WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24 $WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36 $WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1 $WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67 $WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67 $WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65 $WM_CAP_GET_STATUS = $WM_CAP_START + 54 $WM_CAP_GET_USER_DATA = $WM_CAP_START + 8 $WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44 $WM_CAP_GRAB_FRAME = $WM_CAP_START + 60 $WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61 $WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83 $WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84 $WM_CAP_PAL_OPENA = $WM_CAP_START + 80 $WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80 $WM_CAP_PAL_PASTE = $WM_CAP_START + 82 $WM_CAP_SEQUENCE = $WM_CAP_START + 62 $WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63 $WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35 $WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85 $WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2 $WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2 $WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5 $WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3 $WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3 $WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6 $WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7 $WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4 $WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66 $WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66 $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51 $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50 $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52 $WM_CAP_SET_SCALE = $WM_CAP_START + 53 $WM_CAP_SET_SCROLL = $WM_CAP_START + 55 $WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64 $WM_CAP_SET_USER_DATA = $WM_CAP_START + 9 $WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45 $WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72 $WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71 $WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70 $WM_CAP_STOP = $WM_CAP_START + 68 #include <GUIConstants.au3> $avi = DllOpen("avicap32.dll") $user = DllOpen("user32.dll") ;=============================================================================== ; ; Description:      Open's a webcam preview screen in your gui ; Syntax:           _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight, $sPort=0) ; Parameter(s):     $sHwnd     - The handle of the gui ;                   $sLeft     - Left coord. of the preview screen ;                   $sTop      - Top coord. of the preview screen ;                   $sWidth    - Width of the preview screen ;                   $sHeight   - Height of the preview screen ;                   $sPort     - Specify wich webcam port you want to use (for multiple webcams) ; Requirement(s):   A webcam ; Return Value(s):  On Success - Returns id needed for other controls ;                   On Failure - Returns -1 ; Author(s):        Ludocus ; Note(s):          If a black/blank screen shows up, try using different $sPort's (0 to 3) ; ;=============================================================================== Func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight, $sPort=0)     $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1)     DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", $sPort, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0)     if @error then return -1     return $cap[0] EndFunc ;=============================================================================== ; ; Description:      Creates a Snapshot from a webcam ; Syntax:           _WebcamSnap($sId, $sFile) ; Parameter(s):     $sId       - Id (returned from _WebcamOpen) ;                   $sFile     - File to save the snapshot to (*.bmp) ; Requirement(s):   A webcam ; Return Value(s):  On Success - Returns 1 ;                   On Failure - Returns 0 ; Author(s):        Ludocus ; Note(s):          None ; ;=============================================================================== Func _WebcamSnap($sId, $sFile)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SET_CALLBACK_FRAME, "int", 0, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile)     if @error Then         return 0     Else         return 1     EndIf EndFunc ;=============================================================================== ; ; Description:      Closes the preview screen created with _WebcamOpen ; Syntax:           _WebcamClose($sId) ; Parameter(s):     $sId       - Id (returned from _WebcamOpen) ; Requirement(s):   A webcam ; Return Value(s):  On Success - Returns 1 ;                   On Failure - Returns 0 ; Author(s):        Ludocus ; Note(s):          None ; ;=============================================================================== Func _WebcamClose($sId)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0)     DllClose($user)     if @error Then         return 0     Else         return 1     EndIf EndFunc ;=============================================================================== ; ; Description:      Starts recording the webcam to a file ; Syntax:           _WebcamRecordStart($sFile, $sId) ; Parameter(s):     $sId       - Id (returned from _WebcamOpen) ;                   $sFile     - File to save the movie to (*.avi) ; Requirement(s):   A webcam ; Return Value(s):  On Success - Returns 1 ;                   On Failure - Returns 0 ; Author(s):        Ludocus ; Note(s):          Stop recording by: _WebcamRecordStop($Id) ; ;=============================================================================== Func _WebcamRecordStart($sFile, $sId)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0)     if @error Then         return 0     Else         return 1     EndIf EndFunc ;=============================================================================== ; ; Description:      Stops recording. ; Syntax:           _WebcamRecordStop($sId) ; Parameter(s):     $sId       - Id (returned from _WebcamOpen) ; Requirement(s):   A webcam ; Return Value(s):  On Success - Returns 1 ;                   On Failure - Returns 0 ; Author(s):        Ludocus ; Note(s):          None ; ;=============================================================================== Func _WebcamRecordStop($sId)     DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0)     if @error Then         return 0     Else         return 1     EndIf EndFunc


thnx to rysiora with his great example!

Edited by ludocus, 25 February 2011 - 12:13 PM.






#2 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 09 May 2008 - 05:47 PM

Please Comment :)

#3 Kip

Kip

    When done learning: die

  • Active Members
  • PipPipPipPipPipPip
  • 1,685 posts

Posted 15 May 2008 - 03:00 PM

This is already done. And better.
http://www.autoitscript.com/forum/index.ph...;hl=Webcam++UDf
There's a big chance this post has been edited.Posted Image

#4 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 23 May 2008 - 12:08 PM

why do you say: 'and better'?
Mine has a better discription + _WebcamRecordStart + _WebcamRecordStop + His udf has an error, Mine works with an Id Returned, His doesn't wich explains the error
?? I don't get the clue, what is worse about mine?

Edited by ludocus, 23 May 2008 - 12:14 PM.


#5 EvAsion

EvAsion

    Adventurer

  • Active Members
  • PipPip
  • 126 posts

Posted 23 May 2008 - 12:49 PM

Everything

#6 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 23 May 2008 - 12:50 PM

could you be a little more clear?
If there are some things wrong, then I would like to try to make them better. :) thnx

Edited by ludocus, 23 May 2008 - 01:04 PM.


#7 Thatsgreat2345

Thatsgreat2345

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,640 posts

Posted 23 May 2008 - 02:36 PM

Looks good, I may actually use it to make a log of everyone that uses my computer :).

#8 Manadar

Manadar

    Taking a REST.

  • MVPs
  • 10,714 posts

Posted 23 May 2008 - 10:15 PM

Look in the original topic of how to use the webcam, and check for my post. It shows how to call the webcam, only without using the GUI that comes with it.

Also, try to thank the original author inside the code as well. Someone may find your code in a location other then this, and he would think you made it completely, because that is what you state.

#9 StAbb

StAbb

    Seeker

  • Active Members
  • 49 posts

Posted 26 June 2008 - 05:44 PM

Nice job man thanks!

#10 dmoniac

dmoniac

    Seeker

  • Active Members
  • 21 posts

Posted 04 July 2008 - 09:40 AM

Hi.

I've a compil error on $WS_CHILD.

I need to add : '#include <WindowsConstants.au3>' to fix it.

Now, it run perfectly. :muttley:

#11 spudw2k

spudw2k

    i dunno what i'm doing

  • Active Members
  • PipPipPipPipPipPip
  • 1,147 posts

Posted 03 September 2008 - 01:11 AM

Any idea why I get unpredictable recording lengths. What's the best practice to record for a speficied length of time?

Edited by spudw2k, 03 September 2008 - 01:11 AM.


#12 joseLB

joseLB

    Polymath

  • Active Members
  • PipPipPipPip
  • 210 posts

Posted 16 December 2008 - 06:27 PM

Hi,
It didn't work with my webcam. I don't know what brand is it. The screen does not show up. Compilation was OK.

Could you please provide a program example?
Regards
Jose

#13 ynbIpb

ynbIpb

    Seeker

  • Active Members
  • 45 posts

Posted 31 March 2009 - 02:00 PM

Example:
#include <GUIConstants.au3>
#include <Webcam.au3>
$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

ludocus, you can refine the UDF, to be able to specify what parameters to run the camera? (I like the program, which goes along with the driver is given resolution, and frame rate.) And in the UDF is run with default settings?

Edited by ynbIpb, 31 March 2009 - 02:00 PM.


#14 VAG

VAG

    Wayfarer

  • Active Members
  • Pip
  • 57 posts

Posted 23 July 2009 - 06:33 AM

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?

#15 elawady

elawady

    Seeker

  • Active Members
  • 44 posts

Posted 01 November 2009 - 01:27 PM

thank you it's a verygood UDF .
but when i have 3 webcam how can i change between them?

Edited by elawady, 01 November 2009 - 04:42 PM.


#16 elawady

elawady

    Seeker

  • Active Members
  • 44 posts

Posted 01 November 2009 - 04:56 PM

up

#17 ludocus

ludocus

    Possibly inventive crap going on right here

  • Active Members
  • PipPipPipPipPipPip
  • 664 posts

Posted 29 August 2010 - 03:05 PM

I'm sorry for not replying.
I haven't been online on these forums for about a year.
But, no.. I'm wondering how to do that myself.
I've got no clue on how to choose between more than 1 webcam.

#18 kokoilie

kokoilie

    Seeker

  • Active Members
  • 10 posts

Posted 10 October 2012 - 09:59 PM

can you please tell me how to choose 1 (out of 1) camera because to me it's showing only black?

#19 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,834 posts

Posted 11 October 2012 - 02:11 AM

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

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#20 JScript

JScript

    Goodbye everybody, I got tired of this system adopted here!

  • Active Members
  • PipPipPipPipPipPip
  • 1,062 posts

Posted 11 October 2012 - 11:09 AM

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

This is true, but if you use the dll avicap32.dll from XP, as I use, works normally!

Shows us that the dll of Windows 7 has some problem.

JS
http://notebook.forumais.com (Forum Maintenance Notebooks and Desktop)http://autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

Posted Image Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere!       





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users