#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=face_detected_1.ico #AutoIt3Wrapper_Compile_Both=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include #include #include #include #include #include #include Global $nPic = 1 Global $nWin = "" Global $aFacesDB[100][142] $nWin = win_select($nWin) $hWnd = WinGetHandle($nWin) WinActivate($hWnd) WinSetState($hWnd, "", @SW_SHOWNA) Global $aPos = WinGetPos($hWnd) Global $hHBmp = _ScreenCapture_CaptureWnd("", $hWnd, $aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3]) Global $g_hGUI = GUICreate("YOLO - CAPTURE SCREEN LIVE", $aPos[2], $aPos[3], -1, -1) GUISetState(@SW_SHOWNA, $g_hGUI) ;@SW_SHOWNA _GDIPlus_Startup() Global $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) Global $dir = @ScriptDir & "\ImageCrop_" & @MDAY & "_" & @MON & "_" & @YEAR If Not FileExists($dir) Then MsgBox(0, "Folder creation ","ImageCrop folder does not exist, creating ...", 3) ; El mensaje está 3 segundos. DirCreate($dir) EndIf Global $dir_train = @ScriptDir & "\Train_dataset_" & @MDAY & "_" & @MON & "_" & @YEAR If Not FileExists($dir_train) Then MsgBox(0, "Folder creation ","The train_dataset folder does not exist, creating ...", 3) ; El mensaje está 3 segundos. DirCreate($dir_train) EndIf general_ refresh() _GDIPlus_Shutdown() Func general_ refresh() Local $tDelta = TimerInit() Do If TimerDiff($tDelta) >= 67 Then ; => 67=30 FPS; 32=60 FPS $tDelta = TimerInit() RefreshImage() ConsoleWrite(TimerDiff($tDelta) & @CRLF) ;~ OnAutoItExitRegister("CleanupResources") EndIf Until GUIGetMsg() == $GUI_EVENT_CLOSE EndFunc Func RefreshImage() $hWnd = WinGetHandle($nWin) WinSetState($hWnd, "", @SW_SHOWNA) Local $aPos = WinGetPos($hWnd) Local $sFilePath Local $sDestination = @ScriptDir & "\face_detected_1.bmp" Local $aClientSize = WinGetClientSize($hWnd) Local $iPicW=$aClientSize[0] Local $iPicH=$aClientSize[1] Local $hHBmp = _ScreenCapture_CaptureWnd("", $hWnd, $aPos[0], $aPos[1], $aPos[0] + $aPos[2], $aPos[1] + $aPos[3]) Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) Local $rG = _GDIPlus_GraphicsDrawImage($g_hGraphics, $hBitmap, 0, 0) ;~ ========================================================================================================================== ;~ Resize square image for intro in objetcs detector Local $iWidth = _GDIPlus_ImageGetWidth($hBitmap) Local $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $sFactor = 1 If $iWidth > $iPicW Then $sFactor = $iPicW / $iWidth EndIf If $iHeight > $iPicH And ($iHeight * $sFactor) > $iPicH Then $sFactor = $iPicH / $iHeight EndIf $iHeight = $iHeight * $sFactor $iWidth = $iWidth * $sFactor $hResizedImage = _GDIPlus_ImageResize($hBitmap, $iWidth, $iHeight) ;~ _GDIPlus_BitmapDispose($hBitmap) Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hResizedImage, 0x00000000) ;~ ====================objetcs detector====================================================================================================== Global $aRes = _AutoYolo3_GetObjInHBitmap($hHBITMAP) ;~ _ArrayDisplay($aRes) If $aRes[0][0] <> 0 Then If @error Then Local $iErr = @error Local $asDllErrors[6] = ["No error", "unable to use the DLL file", "unknown ""return type""", """function"" not found in the DLL file", "bad number of parameters", "bad parameter"] If $iErr < 6 Then MsgBox(32, @ScriptName, "DLL Error, " & $asDllErrors[$iErr]) Else MsgBox(32, @ScriptName, "DLL Error, " & _AutoYolo3_GetLastError()) EndIf ElseIf _AutoYolo3_GetLastError() <> "" Then MsgBox(32, @ScriptName, _AutoYolo3_GetLastError()) Else ;nice thick green boxes Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, 2, 2) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Calibri") Local $hFont = _GDIPlus_FontCreate($hFamily, 12, 0) Local $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20) ;~ Local $hBrushBack = _GDIPlus_BrushCreateSolid(0x7FFFFFFF) ;color format AARRGGBB (hex) ;~ $hGraphics = _GDIPlus_ImageGetGraphicsContext($hHBmp) ;~ _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing) For $i = 1 To $aRes[0][0] $sTempImg = $dir & "\face_" & @HOUR & "_" & @MIN & "_" & @SEC & "-" & $aRes[$i][0] & ".jpg" $hClone = _GDIPlus_BitmapCloneArea($hBitmap, $aRes[$i][2], $aRes[$i][3] , $aRes[$i][4], $aRes[$i][5], $GDIP_PXF24RGB) _GDIPlus_ImageSaveToFile($hClone, $sTempImg) _GDIPlus_ImageDispose($hClone) _WinAPI_DeleteObject($hBitmap) ; Draw a frame around the object _GDIPlus_GraphicsDrawRect($g_hGraphics, $aRes[$i][2], $aRes[$i][3] , ($aRes[$i][4] - $aRes[$i][2]), ($aRes[$i][5] - $aRes[$i][3]) , $hPen) ; Label it $sLabel = $aRes[$i][0] & " " & StringLeft($aRes[$i][1], 6) $tLayout = _GDIPlus_RectFCreate($aRes[$i][2] , $aRes[$i][3] , 200, 20) ;~ $iBackLen = 0 ;~ If (StringLen($sLabel) * 8) > $iBackLen Then ;~ $iBackLen = StringLen($sLabel) * 8 ;~ EndIf ;~ _GDIPlus_GraphicsFillRect($hGraphics, $aRes[$i][2] , $aRes[$i][3], $iBackLen, 20, $hBrushBack) ;~ _ GDIPlus_GraphicsDrawStringEx($g_hGraphics, $sLabel, $hFont, $tLayout, $hFormat, $hBrush) Next EndIf ;~ $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hHBmp, 0x00000000) ;~ GUICtrlSendMsg($g_hGUI , $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP) _GDIPlus_PenDispose($hPen) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) ;~ _GDIPlus_ImageDispose($hClone) ;~ _GDIPlus_BrushDispose($hBrush) ;~ _GDIPlus_BrushDispose($hBrushBack) _GDIPlus_GraphicsDispose($g_hGraphics) EndIf ;~ ================================================================================================================================ EndFunc ;==>RefreshImage Func win_select($nWin) Local $stPoint = DllStructCreate($tagPOINT), $aPos, $hControl, $hWin, $aLastPos[2] = [-1, -1], $sLastStr = '', $sStr TrayTip ("YOLO - CAPTURE SCREEN LIVE", "Select the window to detect", 5) While Not _IsPressed('01') ;Right mouse button $aPos = MouseGetPos() If $aPos[0] <> $aLastPos[0] Or $aPos[1] <> $aLastPos[1] Then DllStructSetData($stPoint, 1, $aPos[0]) DllStructSetData($stPoint, 2, $aPos[1]) $hControl = _WinAPI_WindowFromPoint($stPoint) $hWin = _WinAPI_GetAncestor($hControl, 2) $sStr = 'Window at ' & $aPos[0] & ',' & $aPos[1] & ': "' & WinGetTitle($hWin) & '"' If $sLastStr <> $sStr Then ToolTip($sStr, $aPos[0] + 10, $aPos[1] + 20) $sLastStr = $sStr EndIf $aLastPos = $aPos EndIf Sleep(15) WEnd ToolTip("") #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Cancel, Try Again, Continue, Icon=Info If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(70,"YOLO - CAPTURE SCREEN LIVE","La ventana seleccionada es " & WinGetTitle($hWin)) Select Case $iMsgBoxAnswer = 2 ;Cancel Case $iMsgBoxAnswer = 10 ;Try Again win_select($nWin) Case $iMsgBoxAnswer = 11 ;Continue #EndRegion --- CodeWizard generated code End --- EndSelect Return WinGetTitle($hWin) EndFunc ;==>win_select Func _LoadImage($Input1, $Pic1, $hImage, $iPicW, $iPicH) If $hImage <> 0 Then _GDIPlus_ImageDispose($hImage) EndIf Local $sImagePath = GUICtrlRead($Input1) $hImage = _GDIPlus_ImageLoadFromFile($sImagePath) Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) Local $sFactor = 1 If $iWidth > $iPicW Then $sFactor = $iPicW / $iWidth EndIf If $iHeight > $iPicH And ($iHeight * $sFactor) > $iPicH Then $sFactor = $iPicH / $iHeight EndIf $iHeight = $iHeight * $sFactor $iWidth = $iWidth * $sFactor $hResizedImage = _GDIPlus_ImageResize($hImage, $iWidth, $iHeight) _GDIPlus_BitmapDispose($hImage) Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hResizedImage, 0x00000000) GUICtrlSendMsg($Pic1, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP) Return $hResizedImage EndFunc ;==>_LoadImage