Jump to content

Face in picture


 Share

Recommended Posts

I found this code on the German site, Can use me to put on (it)

Thank you in advance

#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <Array.au3>

$hOpen = DllOpen("fdlib.dll")

_GDIPlus_Startup()

$hbBMP = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\geeks.jpg")
$iWidth = _GDIPlus_ImageGetWidth($hbBMP)
$iHeight = _GDIPlus_ImageGetHeight($hbBMP)
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hbBMP)
$iThreshold = Number(InputBox("Threshold", "Threshold"))
If $iThreshold < 1 Then $iThreshold = 1
$vBMP = _GDIPlus_BitmapToStructByte($hBMP, $iWidth, $iHeight)

DllCall($hOpen, "int:cdecl", "fdlib_detectfaces", "ptr", DllStructGetPtr($vBMP), "int", $iWidth, "int", $iHeight, "int", $iThreshold)

$nFace = DllCall($hOpen, "int:cdecl", "fdlib_getndetections")
If Not @error Then
    MsgBox(0, "", $nFace[0])
    $nFace = $nFace[0]

Else
    MsgBox(0, "", @error)
    Exit
EndIf

$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

$hGraph = _GDIPlus_ImageGetGraphicsContext($hImage)
$hPen = _GDIPlus_PenCreate(0xFFFF0000)
Dim $aFaces,$iX,$iY,$iSize
If $nFace > 0 Then
    Dim $aFaces[$nFace][4]
    For $i = 0 To $nFace - 1
        $nextFace = DllCall($hOpen, "int:cdecl", "fdlib_getdetection", "int", $i, "int*", $iX + $i, "int*", $iY + $i, "int*", $iSize + $i)
        If Not @error Then
            $iX = $nextFace[2]
            $iY = $nextFace[3]
            $iSize = $nextFace[4]
            _GDIPlus_GraphicsDrawRect($hGraph,$iX,$iY,$iSize,$iSize,$hPen)
            $aFaces[$i][0] = $i
            $aFaces[$i][1] = $iX
            $aFaces[$i][2] = $iY
            $aFaces[$i][3] = $iSize
        EndIf
    Next
EndIf
_GDIPlus_ImageSaveToFile($hImage,@ScriptDir&"\geeks2.jpg")
_ArrayDisplay($aFaces)


DllClose($hOpen)
Func _GDIPlus_BitmapToStructByte($hBMP, $iW, $iH)
    Local $x, $y, $z, $sErrorHandlerString, $hDC, $hDC_tmp, $hBitmap, $vStruct_Byte, $vStruct_BMPInfo

    Local $hBitmap = DllCall("User32.dll", "hwnd", "CopyImage", "hwnd", $hBMP, "int", 0, "int", 0, "int", 0, "int", 1);LR_MONOCHROME
    If @error Then Return SetError(1, 0, _WinAPI_GetLastErrorMessage())
    $hBitmap = $hBitmap[0]

    $vStruct_Byte = DllStructCreate("byte graydata[" & $iW * $iH & "]")

    Local $vStruct_BMPInfo = DllStructCreate("dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword;dword RGBQuad[256];")
    $hDC_tmp = _WinAPI_GetDC(_WinAPI_GetDesktopWindow())
    $hDC = _WinAPI_CreateCompatibleDC($hDC_tmp)
    _WinAPI_ReleaseDC(0, $hDC_tmp)
    Local $hBitmapOld = _WinAPI_SelectObject($hDC, $hBitmap)

    DllStructSetData($vStruct_BMPInfo, 1, DllStructGetSize(DllStructCreate("dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword;", 1)))
    DllStructSetData($vStruct_BMPInfo, 2, $iW)
    DllStructSetData($vStruct_BMPInfo, 3, $iH * - 1)
    DllStructSetData($vStruct_BMPInfo, 4, 1)
    DllStructSetData($vStruct_BMPInfo, 5, 1)

    _WinAPI_GetDIBits($hDC, $hBitmap, 0, $iH, DllStructGetPtr($vStruct_Byte), DllStructGetPtr($vStruct_BMPInfo), 0)

    _WinAPI_DeleteObject(_WinAPI_SelectObject($hDC, $hBitmapOld))
    _WinAPI_DeleteDC($hDC)

    Return $vStruct_Byte
EndFunc   ;==>_GDIPlus_BitmapToStructByte
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...