Jump to content

save the webcam image.


Belini
 Share

Recommended Posts

I'm trying to adapt the script posted here https://www.autoitscript.com/forum/topic/150536-simple-webcam-access-using-escapi/#comment-1136331 by mylise to display the webcam video and then save the picture .jpg but do not want to use the _ScreenCapture_Capture () does anyone know how to capture the specific area of the GUI and save to jpg?

Changes I've ever done:

;Font ==> https://www.autoitscript.com/forum/topic/150536-simple-webcam-access-using-escapi/#comment-1136331

#include <GDIplus.au3>
#include <GUIConstantsEx.au3>

Global $Width = 640 ;Escapi seems to use 640x480 (or lower) as webcam resolution and will
Global $Height = 480 ; 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)
;--------------------------------------------------------------------------

;---------------------------------------------------------------------------
;Escapi init
Local $_escapi_Dll = DllOpen("escapi.dll")
DllCall($_escapi_Dll, "int:cdecl", "initCapture", "int", 0, "ptr", $pSimpleCapParams)
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------
; GUI create
Global $hwnd = GUICreate("EscApi WebCam", 680, 520)
GUISetBkColor(0x000000, $hwnd)
GUISetState(@SW_SHOW, $hwnd)
;---------------------------------------------------------------------------

;---------------------------------------------------------------------------
; GDI init
_GDIPlus_Startup()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
;---------------------------------------------------------------------------

While 1
    video()
    Local $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Clean_up()
        ExitLoop
    EndIf
    Sleep(50)
WEnd

Func Clean_up()
    $return = DllCall($_escapi_Dll, "none:cdecl", "deinitCapture", "int", 0)
    DllClose($_escapi_Dll)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hwnd)
EndFunc   ;==>Clean_up

Func video()
    ;---------------------------------------------------------------------------
    ;Get frame
    DllCall($_escapi_Dll, "none:cdecl", "doCapture", "int", 0)
    Do
        $return = DllCall($_escapi_Dll, "int:cdecl", "isCaptureDone", "int", 0)
        Sleep(50)
    Until $return[0] = 1
    ;---------------------------------------------------------------------------
    ;Display frame
    $hBMP = _WinAPI_CreateBitmap($Width, $Height, 1, 32, $pTargetBuf)
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 20, 20, $Width, $Height)
    _GDIPlus_BitmapDispose($hImage)
    _WinAPI_DeleteObject($hBMP)
    ;---------------------------------------------------------------------------
EndFunc   ;==>video

 

Edited by Belini
Link to comment
Share on other sites

My first thought is to use the UDF to open in the 0,0 axis and take a full screen shot. Save the image as whatever and open it in paint and resize it and save as jpeg. Why dont you want to use screen capture? 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

You can save your bitmap instead make a screen capture.

_WinAPI_SaveHBITMAPToFile  bitmap

_GDIPlus_ImageSaveToFile ObjectBitmap

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

@Computergroove Full screen I can capture and also can resize but I want to put the webcam image as a control and I want to save the image to appear in the GUI without having to hide gui or having to put the gui in full screen!

@Danyfirex I'll experiment with these commands you posted!

Edited by Belini
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...