After the opencv udf, Dlib seems to be a missing library for image processing.
This UDF provides a way to use dlib in AutoIt
The usage is similar to the python usage of dlib
Prerequisites
Download and extract autoit-dlib-19.24.4-opencv-4.10.0-com-v1.4.3.7z into a folder
Sources
Here
Documentation
A generated documentation for functions is available here
Examples
More examples can be found here
To run them, please follow these instructions
Face detection
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
#include "autoit-dlib-com\udf\dlib_udf_utils.au3"
_Dlib_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-dlib-com\autoit_dlib_com-19.24-470.dll")
OnAutoItExitRegister("_OnAutoItExit")
Example()
Func Example()
Local Const $dlib = _Dlib_get()
If Not IsObj($dlib) Then Return
Local $detector = $dlib.get_frontal_face_detector()
Local $win = _Dlib_ObjCreate("image_window")
Local $image_path = _Dlib_FindFile("examples\faces\2008_002470.jpg")
Local $img = $dlib.load_rgb_image($image_path)
$win.set_image($img)
; The 1 in the second argument indicates that we should upsample the image
; 1 time. This will make everything bigger and allow us to detect more
; faces.
Local $dets = $detector.call($img, 1)
ConsoleWrite("Number of faces detected: " & UBound($dets) & @CRLF)
Local $d
For $i = 0 To UBound($dets) - 1
$d = $dets[$i]
ConsoleWrite(StringFormat("Detection %d: Left: %d Top: %d Right: %d Bottom: %d", _
$i, $d.left(), $d.top(), $d.right(), $d.bottom()) & @CRLF)
Next
$win.add_overlay($dets)
hit_to_continue()
EndFunc ;==>Example
Func hit_to_continue()
ToolTip("Hit ESC to continue", 0, 0)
ConsoleWrite("Hit ESC to continue" & @CRLF)
Do
Sleep(50)
Until _IsPressed("1B")
EndFunc ;==>hit_to_continue
Func _OnAutoItExit()
_Dlib_Close()
EndFunc ;==>_OnAutoItExit
Camera face detection using opencv
First, download the opencv UDF from here
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>
#include "autoit-dlib-com\udf\dlib_udf_utils.au3"
#include "autoit-opencv-com\udf\opencv_udf_utils.au3"
_Dlib_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-dlib-com\autoit_dlib_com-19.24-470.dll")
_OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll")
OnAutoItExitRegister("_OnAutoItExit")
Example()
Func Example()
Local Const $dlib = _Dlib_get()
If Not IsObj($dlib) Then Return
Local Const $cv = _OpenCV_get()
If Not IsObj($cv) Then Return
Local $detector = $dlib.get_frontal_face_detector()
Local $cam = _OpenCV_ObjCreate("VideoCapture").create(0)
Local $color_green = _OpenCV_Tuple(0, 255, 0)
Local $line_width = 3
Local $img, $dets, $det
While True
If $cam.read() Then
$img = $cv.extended[1]
$dets = $detector.call($img)
For $i = 0 To UBound($dets) - 1
$det = $dets[$i]
$cv.rectangle($img, _OpenCV_Tuple($det.left(), $det.top()), _OpenCV_Tuple($det.right(), $det.bottom()), $color_green, $line_width)
Next
;; Flip the image horizontally to give the mirror impression
$cv.imshow("my webcam", $cv.flip($img, 1))
EndIf
If _IsPressed("1B") Then
ExitLoop ; esc to quit
EndIf
Sleep(1)
WEnd
$cv.destroyAllWindows()
EndFunc ;==>Example
Func _OnAutoItExit()
_OpenCV_Close()
_Dlib_Close()
EndFunc ;==>_OnAutoItExit