Jump to content
Sign in to follow this  

Face in picture

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")


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

    MsgBox(0, "", @error)

$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]
            $aFaces[$i][0] = $i
            $aFaces[$i][1] = $iX
            $aFaces[$i][2] = $iY
            $aFaces[$i][3] = $iSize

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))

    Return $vStruct_Byte
EndFunc   ;==>_GDIPlus_BitmapToStructByte

Share this post

Link to post
Share on other sites

This script has to find faces in one embellish with images and to spot them but it does not work: (I have to try to modify it but without any success...

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...