Jump to content

Playing with webcam, brightness and gama


jvds
 Share

Recommended Posts

 was playing with my webcam using mylise's script from https://www.autoitscript.com/forum/topic/150536-simple-webcam-access-using-escapi/ .

I'm trying to set the contrast and brightness with the new escapi.dll, found here http://sol.gfxile.net/zip/escapi3.zip but fail to understand how to implement it, i tried to call the dll with VideoProcAmp_Gamma and CAPTURE_GAMMA but it seems I'm doing it wrong, dllcall keeps returning the default brightness value as if i didn't call the Gama parameters, of which i don't even know if im doing it the correct way.

i got the VideoProcAmp_Gamma and CAPTURE_GAMMA  from  https://github.com/jarikomppa/escapi/blob/master/escapi_dll/capture.cpp . but dont know for sure with which int i can call the dll with

;--------------------------------------------------------------------------
; ESCAPI is a very simple DLL interface to use video capture devices
; (most commonly webcams, but also video in devices and other similar things)
; Get dll from --> [url="http://sol.gfxile.net/escapi/index.html"]http://sol.gfxile.net/escapi/index.html[/url]
;
#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
;--------------------------------------------------------------------------
; Local variables
Local $Width = 320 ;Escapi seems to use 640x480 (or lower) as webcam resolution and will
Local $Height = 240 ; adjust the image size to $Width by $Height
;--------------------------------------------------------------------------
; variables required for dshow escapi
Local $tagSimpleCapParams = _
        "ptr mTargetBuf;" & _
        "int mWidth;" & _
        "int mHeight;"
Local $tSimpleCapParams = DllStructCreate($tagSimpleCapParams)
Local $tTargetBuf = DllStructCreate("BYTE[" & $Width * $Height * 4 & "]")
Global $pTargetBuf = DllStructGetPtr($tTargetBuf)
DllStructSetData($tSimpleCapParams, 1, $pTargetBuf)
DllStructSetData($tSimpleCapParams, 2, $Width)
DllStructSetData($tSimpleCapParams, 3, $Height)
Local $pSimpleCapParams = DllStructGetPtr($tSimpleCapParams)
Local $device = 0 ;change this number to select dshow device
;---------------------------------------------------------------------------
;Escapi init
Local $_escapi_Dll = DllOpen("escapi.dll")
$return = DllCall($_escapi_Dll, "int", "initCOM")
$return = DllCall($_escapi_Dll, "int:cdecl", "initCapture", "int", $device, "ptr", $pSimpleCapParams)
;---------------------------------------------------------------------------
; GUI and GDI init
Global $hwnd = GUICreate("EscApi WebCam", $Width, $Height)
GUISetState(@SW_SHOW, $hwnd)
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)

$C_timer = TimerInit()
While 1

    ;---------------------------------------------------------------------------
    ;Get frame
    DllCall($_escapi_Dll, "none:cdecl", "doCapture", "int", 0)
    Do
        $return = DllCall($_escapi_Dll, "int:cdecl", "isCaptureDone", "int", 0)
        Sleep(100)
    Until $return[0] = 1

    ;---------------------------------------------------------------------------
    ;Display frame
    $hBMP = _WinAPI_CreateBitmap($Width, $Height, 1, 32, $pTargetBuf)
    Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $Width, $Height)
    _GDIPlus_BitmapDispose($hImage)
    _WinAPI_DeleteObject($hBMP)


    Local $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Sleep(500)

    ;################################################# getCapturePropertyValue #################################################
    $Default = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", "int", $device, "int", '')
    ;extern "C" float __declspec(dllexport) getCapturePropertyValue(unsigned int deviceno, int prop)
    ConsoleWrite("$Default CAPTURE_BRIGHTNESS = " & $Default[0] & @LF)
    
    ;WHAT is WRONG HERE? CAPTURE_GAMMA
    $CAPTURE_GAMMA = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", "int", $device, "int", 'CAPTURE_GAMMA');,"int",20)
    ConsoleWrite("$CAPTURE_GAMMA = " & $CAPTURE_GAMMA[0] & @LF)
    
    ;WHAT is WRONG HERE? VideoProcAmp_Gamma
    $VideoProcAmp_Gamma = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", "int", $device, "int", 'VideoProcAmp_Gamma');,"int",20)
    ConsoleWrite("$VideoProcAmp_Gamma = " & $VideoProcAmp_Gamma[0] & @LF& @LF)

    If Round(TimerDiff($C_timer)) > 5000 Then
        $C_timer = TimerInit()

        ;WHAT is WRONG HERE? CAPTURE_BRIGHTNESS to 0.1
        $setCaptureProperty = DllCall($_escapi_Dll, "int:cdecl", "setCaptureProperty", "int", $device, "int", '', 'float', 0.1)
        ;~ extern "C" int __declspec(dllexport) setCaptureProperty(unsigned int deviceno, int prop, float value, int autoval)
        ConsoleWrite("$setCaptureProperty = " & $setCaptureProperty[0] & @LF)

    EndIf
WEnd

;--------------------------------------------------------------------------
;Clean up
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($hwnd)

i can change the brightness with the propgui.exe which is inside the dll examples folder, and then the script picks the changed value up with the dllcall, but was not able to set it from autoit nor pick up the Gama or other settings

Link to comment
Share on other sites

  • 3 weeks later...

Take a look to escapi.h for declare CAPTURE_GAMMA

;~ CAPTURE_PROPERTIES
Global Enum _
    $CAPTURE_BRIGHTNESS, _
    $CAPTURE_CONTRAST, _
    $CAPTURE_HUE, _
    $CAPTURE_SATURATION, _
    $CAPTURE_SHARPNESS, _
    $CAPTURE_GAMMA, _
    $CAPTURE_COLORENABLE, _
    $CAPTURE_WHITEBALANCE, _
    $CAPTURE_BACKLIGHTCOMPENSATION, _
    $CAPTURE_GAIN, _
    $CAPTURE_PAN, _
    $CAPTURE_TILT, _
    $CAPTURE_ROLL, _
    $CAPTURE_ZOOM, _
    $CAPTURE_EXPOSURE, _
    $CAPTURE_IRIS, _
    $CAPTURE_FOCUS, _
    $CAPTURE_PROP_MAX

 

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • 2 weeks later...

Hello JVDS

Have tested your script and it worked nice now.

see your script running as wanted now:

;--------------------------------------------------------------------------
; ESCAPI is a very simple DLL interface to use video capture devices
; (most commonly webcams, but also video in devices and other similar things)
; Get dll from --> [url="http://sol.gfxile.net/escapi/index.html"]http://sol.gfxile.net/escapi/index.html[/url]
;

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=projector.ico
#AutoIt3Wrapper_Res_Fileversion=1.1.0.0
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
;--------------------------------------------------------------------------
; Local variables
Local $Width = 320 ;Escapi seems to use 640x480 (or lower) as webcam resolution and will
Local $Height = 240 ; adjust the image size to $Width by $Height
;--------------------------------------------------------------------------
; variables required for dshow escapi
Local $tagSimpleCapParams = _
        "ptr mTargetBuf;" & _
        "int mWidth;" & _
        "int mHeight;"
Local $tSimpleCapParams = DllStructCreate($tagSimpleCapParams)
Local $tTargetBuf = DllStructCreate("BYTE[" & $Width * $Height * 4 & "]")
Global $pTargetBuf = DllStructGetPtr($tTargetBuf)
DllStructSetData($tSimpleCapParams, 1, $pTargetBuf)
DllStructSetData($tSimpleCapParams, 2, $Width)
DllStructSetData($tSimpleCapParams, 3, $Height)
Local $pSimpleCapParams = DllStructGetPtr($tSimpleCapParams)
Local $device = 0 ;change this number to select dshow device
;---------------------------------------------------------------------------
;Escapi init
Local $_escapi_Dll = DllOpen("escapi.dll")
$return = DllCall($_escapi_Dll, "int", "initCOM")
$return = DllCall($_escapi_Dll, "int:cdecl", "initCapture", "int", $device, "ptr", $pSimpleCapParams)
;---------------------------------------------------------------------------
; GUI and GDI init
Global $hwnd = GUICreate("EscApi WebCam", $Width, $Height)
GUISetState(@SW_SHOW, $hwnd)
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)

$C_timer = TimerInit()
While 1

    ;---------------------------------------------------------------------------
    ;Get frame
    DllCall($_escapi_Dll, "none:cdecl", "doCapture", "int", 0)
    Do
        $return = DllCall($_escapi_Dll, "int:cdecl", "isCaptureDone", "int", 0)
        Sleep(100)
    Until $return[0] = 1

    ;---------------------------------------------------------------------------
    ;Display frame
    $hBMP = _WinAPI_CreateBitmap($Width, $Height, 1, 32, $pTargetBuf)
    Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $Width, $Height)
    _GDIPlus_BitmapDispose($hImage)
    _WinAPI_DeleteObject($hBMP)


    Local $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Sleep(500)

    ;################################################# getCapturePropertyValue #################################################
    $Default = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", "int", $device, "int", 0) ; SOLVED
    ;extern "C" float __declspec(dllexport) getCapturePropertyValue(unsigned int deviceno, int prop)
    ConsoleWrite("$Default CAPTURE_BRIGHTNESS = " & $Default[0] & @LF)

    ;SOLVED CAPTURE_GAMMA
    $CAPTURE_GAMMA = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", _
    "int", $device, "int", 5)
    ConsoleWrite("$CAPTURE_GAMMA = " & $CAPTURE_GAMMA[0] & @LF)

    ;SOLVED VideoProcAmp_Gamma
    $VideoProcAmp_Gamma = DllCall($_escapi_Dll, "float:cdecl", "getCapturePropertyValue", _
    "int", $device, "int", 5)
    ConsoleWrite("$VideoProcAmp_Gamma = " & $VideoProcAmp_Gamma[0] & @LF & @LF)

    If Round(TimerDiff($C_timer)) > 5000 Then
        $C_timer = TimerInit()

        ;SOLVED CAPTURE_BRIGHTNESS to 0.1
        $setCaptureProperty = DllCall($_escapi_Dll, "int:cdecl", "setCaptureProperty", _
        "int", $device, "int", 0, 'float', 0.1, "int", 0)
;~ extern "C" int __declspec(dllexport) setCaptureProperty(unsigned int deviceno, int prop, float value, int autoval)
        ConsoleWrite("$setCaptureProperty = " & $setCaptureProperty[0] & @LF) ; Do not know what the return value means ?

    EndIf
WEnd

;--------------------------------------------------------------------------
;Clean up
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($hwnd)

I had a similiar issue.

I found the following solution by writing

the PropValues as int values like 0 1 2 3 4 instead of using constructs like 'VideoProcAmp_Gamma'

see $iProp within the for next loop.

See the following code snippet about i have addressed the props to read out.

Local $eEND_PROP = 17
Local $aPropVal ; [0] = Value; [1] = DeviceId ; [2] = PropId
Local $aPropAuto ; [0] = Value; [1] = DeviceId ; [2] = PropId
For $iProp = 0 To $eEND_PROP
    $aPropVal = DllCall($_escapi_Dll, "FLOAT:cdecl", "getCapturePropertyValue", "int", $device, "int", $iProp)
    $aPropAuto = DllCall($_escapi_Dll, "INT:cdecl", "getCapturePropertyAuto", "int", $device, "int", $iProp)
    ConsoleWrite(" Prop: " & $aPropVal[2] & _
            " Auto: " & $aPropAuto[0] & _
            " DEVICE: " & $aPropVal[1] & _
            " VALUE: " & $aPropVal[0] & _
            @CRLF)
Next

 

Also i'am able to "setCaptureProperty"

I used the following by example simple statement.
;                                                                                                                   CAMERA       Prop         Value       Auto
$aSetProp = DllCall($_escapi_Dll, "int:cdecl", "setCaptureProperty", "int", $device, "int", 0, "float", 0.3, "int", 0)

Add the brightnes prop id:  "int",0
and add the auto prop at the end "int",0

That should help.

see result from ConsoleWindow:
Prop: 0 Auto: 0 DEVICE: 0 VALUE: 0.296875

Value of 0.3 means dark and 0.9 light.

Have tested it with 2 webcams at the same time on my laptop running WIN10 64

Tested under Autoscript 64 as well 32 with the related ESCAPI.DLL

 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000407  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0407)

 SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\juergen\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper

>Running:(3.3.12.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "X:\Project\WebCamShutter\ESCAPI.au3"

>Running:(3.3.12.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "X:\Project\WebCamShutter\ESCAPI.au3"

Hope that helps

PS: I'am on the way to include sliders into my  script to adjust properties.

--Juergen

Edited by JuergenAlfing
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

×
×
  • Create New...