Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/01/2024 in all areas

  1. Hi guys, here is a small dll wrapper I made geared at making YOLOv3 (Joseph Redmon, Ali Farhadi) more accessible to AutoIt users. Homepage of YOLO: https://pjreddie.com/darknet/yolo/ Technical overview: You only look once (YOLO) is a state-of-the-art, real-time object detection system. On a Pascal Titan X it processes images at 30 FPS and has a mAP of 57.9% on COCO test-dev. (from https://pjreddie.com/darknet/yolo/) Screenshots: Features: This UDF currently supports recognizing objects in images passed in as a HBITMAP Below is a complete list of the functions currently available in this library: ; #CURRENT# ===================================================================================================================== ;_AutoYolo3_GetLastError ;_AutoYolo3_GetObjInHBitmap ;_AutoYolo3_GetVersion ;_AutoYolo3_SetConfig ;_AutoYolo3_YoloTest ; =============================================================================================================================== The _AutoYolo3_GetObjInHBitmap function returns a 2D Array of detected objects as illustrated below: Examples: Example1: basic_example.au3 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <AutoYOLO3.au3> #include <GDIPlus.au3> ConsoleWrite("Using autoyolo version:" & _AutoYolo3_GetVersion() & @CRLF) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\people-2557408_1920.jpg") Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000) Local $aRes = _AutoYolo3_GetObjInHBitmap($hHBITMAP) _ArrayDisplay($aRes) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Example 2: gui_example.au3 #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoYOLO3.au3> #include <GDIPlus.au3> ConsoleWrite("Using autoyolo version:" & _AutoYolo3_GetVersion() & @CRLF) _GUIExample1() Func _GUIExample1()     _GDIPlus_Startup()     Local $iPicW=609     Local $iPicH=385     #Region ### START Koda GUI section ### Form=     GUICreate(@ScriptName&" - Object Detection with AutoIt!", 625, 506)     GUISetFont(14, 400, 0, "Calibri")     Local $Button1 = GUICtrlCreateButton("browse", 472, 8, 145, 33)     Local $Input1 = GUICtrlCreateInput(@ScriptDir & "\scooter-5180947_1920.jpg", 8, 8, 457, 31)     Local $Button2 = GUICtrlCreateButton("detect objects!", 228, 448, 169, 49)     Local $Pic1 = GUICtrlCreatePic("", 8, 48, $iPicW, $iPicH, $SS_BITMAP)     GUISetState(@SW_SHOW)     #EndRegion ### END Koda GUI section ###     Local $hImage = _LoadImage($Input1, $Pic1, 0, $iPicW,$iPicH)     While 1         $nMsg = GUIGetMsg()         Switch $nMsg             Case $GUI_EVENT_CLOSE                 Exit             Case $Button1                 GUICtrlSetData($Input1, FileOpenDialog("Please select image", @ScriptDir, "All (*.*)"))                 $hImage = _LoadImage($Input1, $Pic1, $hImage, $iPicW,$iPicH)             Case $Button2                 GUICtrlSetState($Button2, $GUI_DISABLE)                 GUICtrlSetData($Button2, "working..")                 Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000)                 Local $aRes = _AutoYolo3_GetObjInHBitmap($hHBITMAP)                 ;_ArrayDisplay($aRes)                 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($hImage)                     _GDIPlus_GraphicsSetSmoothingMode($hGraphics, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)                     For $i = 1 To $aRes[0][0]                         ; Draw a frame around the object                         _GDIPlus_GraphicsDrawRect($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($hGraphics, $sLabel, $hFont, $tLayout, $hFormat, $hBrush)                     Next                     $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage, 0x00000000)                     GUICtrlSendMsg($Pic1, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBITMAP)                     _GDIPlus_PenDispose($hPen)                     _GDIPlus_FontDispose($hFont)                     _GDIPlus_FontFamilyDispose($hFamily)                     _GDIPlus_StringFormatDispose($hFormat)                     _GDIPlus_BrushDispose($hBrush)                     _GDIPlus_BrushDispose($hBrushBack)                     _GDIPlus_GraphicsDispose($hGraphics)                 EndIf                 GUICtrlSetData($Button2, "detect objects!")                 GUICtrlSetState($Button2, $GUI_ENABLE)         EndSwitch     WEnd     If $hImage <> 0 Then         _GDIPlus_ImageDispose($hImage)     EndIf     _GDIPlus_Shutdown() EndFunc   ;==>_GUIExample1 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 Requirements: Windows x64, AutoIt x64 Microsoft Visual C++ 2015-2019 Redistributable (x64) - https://aka.ms/vs/16/release/vc_redist.x64.exe OpenCV binaries - https://sourceforge.net/projects/opencvlibrary/files/4.3.0/opencv-4.3.0-vc14_vc15.exe/download Quickstart: Ensure you are running Windows x64, AutoIt x64 Install Microsoft Visual C++ 2015-2019 Redistributable (x64) if not already installed - https://aka.ms/vs/16/release/vc_redist.x64.exe Create your project directory anywhere, for this example we use C:\projectdir\ Download OpenCV - https://sourceforge.net/projects/opencvlibrary/files/4.3.0/opencv-4.3.0-vc14_vc15.exe/download Unpack OpenCV anywhere and copy opencv_videoio_ffmpeg430_64.dll, opencv_world430.dll to C:\projectdir\ Download trained weights, classes, config files Weights file: Save as C:\projectdir\yolo\yolov3.weights - https://pjreddie.com/media/files/yolov3.weights Classes file: Save as C:\projectdir\yolo\yolov3.txt - https://github.com/pjreddie/darknet/blob/master/data/coco.names https://raw.githubusercontent.com/zishor/yolo-python-rtsp/master/cfg/yolov3.txt NEW Config file: Save as C:\projectdir\yolo\yolov3.cfg - https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg https://raw.githubusercontent.com/zishor/yolo-python-rtsp/master/cfg/yolov3.cfg NEW Unpack autoyolo1.1.zip from downloads below to your project dir So your project directory should look like: C:\projectdir\ │   autoyolo.dll │   AutoYOLO3.au3 │   basic_example.au3 │   gui_example.au3 │   opencv_videoio_ffmpeg430_64.dll │   opencv_world430.dll │   people-2557408_1920.jpg │   scooter-5180947_1920.jpg │ └───yolo         yolov3.cfg         yolov3.txt         yolov3.weights You are done! Try running one of the examples! Download: LAST UPDATED: 06-JUN-2020 autoyolo1.1.zip 785 KB Credits: YOLOv3: An Incremental Improvement - Joseph Redmon, Ali Farhad https://pjreddie.com/yolo/ https://www.learnopencv.com/deep-learning-based-object-detection-using-yolov3-with-opencv-python-c/ zishor for alternative config and classes (https://github.com/zishor/yolo-python-rtsp) MIT License FAQ: I get error "Cannot use dll" Ensure that you are running script as x64, that you have Microsoft Visual C++ 2015-2019 Redistributable (x64) installed, and that the following files are in the @ScriptDir: autoyolo.dll, opencv_videoio_ffmpeg430_64.dll, opencv_world430.dll I get a crash when clicking detect Try using the NEW config and classes links above All feedback is welcome -smartee
    1 point
  2. @argumentum Thank you for the quick response! After further research, it seems that a machine learning process is required to either add or create new content for the objects in the .weights file.
    1 point
  3. with the help of AI (I also put my hand in) Anyway, it's a start ; https://www.autoitscript.com/forum/topic/212232-voidtools-everything-ipc #AutoIt3Wrapper_Res_Fileversion=0.0.0.3 #include <Date.au3> #include <Array.au3> Local $Result = _Everything(@ScriptDir) ; * <<-- _ArrayDisplay($Result) ; #FUNCTION# -------------------------------------------------------------------------------------------------------------------- ; Name...........: _Everything ; Description....: Searches for files using the Everything SDK. ; Syntax.........: _Everything($sSearch) ; Parameters.....: $sSearch - The search query to use. ; Return values..: An array containing the results of the search, with each element being a 3-element array containing the following information: ; | 0 - The full path name of the file. ; | 1 - The date modified of the file in ISO format (yyyy-mm-dd hh:mm:ss). ; | 2 - The size of the file in bytes. ; Notes .........: This function uses the Everything SDK to search for files on the local machine. It is based on the Python example provided by Void Tools. ; https://www.voidtools.com/support/everything/sdk/python/ ; Link ..........: https://www.voidtools.com/support/everything/sdk/ipc/ ; Dependencies...: The Everything SDK must be installed and available in the same directory as this script. ;-------------------------------------------------------------------------------------------------------------------------------- Func _Everything($sSearch) ; Load the Everything DLL Local $EverythingDLL = DllOpen(@ScriptDir & "\Everything-SDK\dll\Everything32.dll") If $EverythingDLL = -1 Then MsgBox(16, "Error", "Failed to load Everything32.dll. Check the path and try again.") Exit EndIf ; Constants for the Everything Request Flags Local Const $EVERYTHING_REQUEST_FILE_NAME = 0x00000001 Local Const $EVERYTHING_REQUEST_PATH = 0x00000002 Local Const $EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004 Local Const $EVERYTHING_REQUEST_EXTENSION = 0x00000008 Local Const $EVERYTHING_REQUEST_SIZE = 0x00000010 Local Const $EVERYTHING_REQUEST_DATE_CREATED = 0x00000020 Local Const $EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040 Local $iFlags = BitOR($EVERYTHING_REQUEST_FILE_NAME, $EVERYTHING_REQUEST_PATH, $EVERYTHING_REQUEST_SIZE, $EVERYTHING_REQUEST_DATE_MODIFIED) ConsoleWrite("$iFlags=" & $iFlags & @CRLF) ; Set up search DllCall($EverythingDLL, "none", "Everything_SetSearchW", "wstr", $sSearch) ; Set request flags DllCall($EverythingDLL, "none", "Everything_SetRequestFlags", "dword", $iFlags) ; Execute the query DllCall($EverythingDLL, "int", "Everything_QueryW", "int", 1) ; Get the number of results Local $aResCnt = DllCall($EverythingDLL, "int", "Everything_GetNumResults") Local $iNumResults = $aResCnt[0] ;ConsoleWrite("Result Count: " & $iNumResults & @CRLF) Local $aResult[$iNumResults + 1][3] $aResult[0][0] = $iNumResults $aResult[0][1] = "Date Modified" $aResult[0][2] = "bytes" ; Create buffers Local $tFilename = DllStructCreate("wchar[260]") Local $tDateModified = DllStructCreate("uint LowPart; uint HighPart") Local $tFileSize = DllStructCreate("uint64") ; Show results For $i = 0 To $iNumResults - 1 ; Get result full path name DllCall($EverythingDLL, "none", "Everything_GetResultFullPathNameW", "int", $i, "ptr", DllStructGetPtr($tFilename), "int", 260) ; Get result date modified DllCall($EverythingDLL, "int", "Everything_GetResultDateModified", "int", $i, "ptr", DllStructGetPtr($tDateModified)) ; Get result size DllCall($EverythingDLL, "int", "Everything_GetResultSize", "int", $i, "ptr", DllStructGetPtr($tFileSize)) ; constructs the result $aResult[$i + 1][0] = DllStructGetData($tFilename, 1) $aResult[$i + 1][1] = _Date_Time_FileTimeToStr($tDateModified, 1) $aResult[$i + 1][2] = DllStructGetData($tFileSize, 1) Next ; Close the DLL DllClose($EverythingDLL) Return $aResult EndFunc ;==>_Everything ;-------------------------------------------------------------------------------------------------------------------------------- Func _HumanBytes($iBytes) Local $units_array[5] = ["bytes", "KB", "MB", "GB", "TB"] For $i = 0 To UBound($units_array) - 1 Step 1 If $iBytes < 1024 Then ExitLoop $iBytes /= 1024 Next Return $i = 0 ? StringFormat("%i %s", $iBytes, $units_array[$i]) : StringFormat("%.2f %s", $iBytes, $units_array[$i]) EndFunc ;==>_HumanBytes
    1 point
×
×
  • Create New...