Windows 11 Real-Time Object Detection Dependencies
--
Darknet is an open source neural network framework written in C, and CUDA. It is used with YOLO, You Only Look Once, which is a Real-Time Object Detection system.
Operating System: Windows 11 22H2
Shell: PowerShell Version 7.3.6
Run the following Windows Package Manager commands in PowerShell to install the essential development tools and 7-zip from Ninite.
iwr -Uri "https://ninite.com/7zip/ninite.exe" -OutFile "C:\Ninite7ZipInstaller.exe"
saps -Path "C:\Ninite7ZipInstaller.exe"
del "C:\Ninite7ZipInstaller.exe"
winget install Git.Git
winget install Kitware.CMake
winget install nsis.nsis
winget install Microsoft.VisualStudio.2022.Community
7-zip, Git Version Control, CMake Build System, Nullsoft Scriptable Install System (To Create Windows Installers), and Microsoft Visual Studio 2022 Community Edition should now be installed.
Open Visual Studio Installer and Choose Modify
Select Desktop development with C++
and .NET desktop development
Some information for what is to come:
Microsoft VCPKG will handle open-source C++ libraries.
OpenCV is a C, and C++ library that is used for real-time computer-vision applications. It is used for object recognition, image and video processing, augmented reality, and more.
Back to PowerShell. We need to run some commands to install Microsoft VCPKG. This is used to build OpenCV. See below:
cd c:\
mkdir c:\src
cd c:\src
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe integrate installtree
.\vcpkg.exe integrate powershell
.\vcpkg.exe install opencv[contrib,dnn,freetype,jpeg,openmp,png,webp,world]:x64-windows pthreads:x64-windows
At this point, the commands created a directory src
that will hold Microsoft’s C++ Library Manager (VCPKG). This is cloned from the GitHub repo and vcpkg
batch file is called to compile the vcpkg
executable (.exe) file. Specific modules and dependencies are installed with the pthreads library. This enables a robust environment to develop computer vision applications.
Now let us clone Darknet [insert ominous sound]
To clone Darknet, build it, and tell CMake where the vcpkg
is located, so it can find other dependencies, we will run the following:
cd c:\src
git clone https://github.com/hank-ai/darknet.git
cd darknet
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake" -DPTHREADS_LIBRARY="C:\src\vcpkg\installed\x64-windows\lib" ..
The darknet
directory is formed inside the src
folder, and so is the build
directory. The build is optimized for release and not debugging, CMake sees the vcpkg
toolchain file and it will find and use the vcpkg
managed libraries. Also, the PThreads library location is explicitly stated. This creates an environment for Darknet to utilize the libraries and toolchains managed by vcpkg
.
Now we need to set the following directories to PATH for the MSBuild executable. See the PowerShell script below.
setx PATH "%PATH%;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\"
setx PATH "%PATH%;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\"
setx PATH "%PATH%;C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
setx PATH "%PATH%;C:\Windows\WinSxS\amd64_msbuild_b03f5f7f11d50a3a_4.0.15912.0_none_de1bfcc9998a681e\"
setx PATH "%PATH%;C:\Windows\Microsoft.NET\assembly\GAC_64\MSBuild\v4.0_4.0.0.0__b03f5f7f11d50a3a\"
setx PATH "%PATH%;C:\Windows\Microsoft.NET\assembly\GAC_32\MSBuild\v4.0_4.0.0.0__b03f5f7f11d50a3a\"
setx PATH "%PATH%;C:\Windows\Microsoft.NET\Framework\v4.0.30319\"
setx PATH "%PATH%;C:\Windows\WinSxS\wow64_msbuild_b03f5f7f11d50a3a_4.0.15912.0_none_07ea43e35ad4fd3b\"
setx PATH "%PATH%;C:\src\vcpkg\installed\x64-windows\lib"
setx PATH "%PATH%;C:\src\vcpkg\installed\x64-windows\bin"
setx PATH "%PATH%;C:\src\vcpkg\installed\x64-windows\include"
This can also be done by accessing the Environment Variables Dialog box from the System Properties > Advanced Tab. System Properties can be accessed by running sysdm.cpl
.
The Doxygen dependency needs to be installed at this point. Doxygen is a documentation generator for C, C++, and other languages. Run the following in PowerShell to clone the Doxygen repository from GitHub into the corresponding directory.
cd c:\src
mkdir flex
git clone https://github.com/doxygen/doxygen.git
cd doxygen
mkdir build
cd build
Download [flex.exe] from https://sourceforge.net/projects/winflexbison/ (according to doxygen.nl)
Extract the .zip to C:\src\flex and rename [win_flex.exe] and [win_bison.exe] to [flex.exe] and [bison.exe], respectively. After you unzip the archive, you can run the following to rename the files.
rni -Path "C:\src\flex\win_flex.exe" -NewName "flex.exe"
rni -Path "C:\src\flex\win_bison.exe" -NewName "bison.exe"
Add C:\src\flex to PATH
setx PATH "%PATH%;C:\src\flex"
Create the directory C:\tools. Download the Doxygen tarball from https://www.doxygen.nl/files/doxygen-1.9.8.src.tar.gz and unzip the tarball. Do this manually or use the commands below.
Mkdir C:\tools
iwr -Uri "https://www.doxygen.nl/files/doxygen-1.9.8.src.tar.gz" -OutFile "C:\tools\doxygen-1.9.8.src.tar.gz"
& "C:\Program Files\7-Zip\7z.exe" e -y "C:\tools\doxygen-1.9.8.src.tar.gz" "-oC:\tools\"
mkdir C:\tools\doxygen-1.9.8.src
& "C:\Program Files\7-Zip\7z.exe" x -y "C:\tools\doxygen-1.9.8.src.tar" "-oC:\tools\doxygen-1.9.8.src\"
Create a build
directory and run CMake with Visual Studio 2022. The build system is prepared for compiling. The MSBuild application is launched to compile the solution darknet.sln
file.
cd C:\src\doxygen\build
cmake -G "Visual Studio 17 2022" -A x64 ..
cd C:\src\darknet\build
msbuild.exe "/property:Platform=x64;Configuration=Release" /target:Build -maxCpuCount -verbosity:normal -detailedSummary darknet.sln
Now there is a file you can run in C:\src\Darknet\build\src\Release\Darknet.exe
Run this to test it and show what version you have installed.
C:\src\Darknet\build\src\Release\Darknet.exe version
And now you should run the following to package Darknet, its libraries, include files, DLLs, and create the NSIS installation package:
cd C:\src\darknet\build
msbuild.exe "/property:Platform=x64;Configuration=Release" /target:Build -maxCpuCount -verbosity:normal -detailedSummary PACKAGE.vcxproj
Finally, you should have a darknet-VERSION.exe
in the C:\src\darknet\build
directory. It will not actually say “VERSION”. It will have some numbers such as 2.6.2, etc. Open the installer file, go through the motions, and add darknet
to PATH.
From here, use Hank AI’s README document available on GitHub as a resource for what to do next: https://github.com/hank-ai/darknet/blob/master/README.md#cli
From here you can learn how to pre-train your own custom models with your own videos/images or find a pre-trained model. Roboflow is a good source for that, https://roboflow.com/. Have fun detecting objects!
References:
C Language: https://www.w3schools.com/c/c_intro.php
CUDA: https://developer.nvidia.com/cuda-zone
GitHub Hank AI Darknet: https://github.com/hank-ai/darknet/blob/master/README.md#windows-cmake-method
The PThreads Library: https://docs.oracle.com/cd/E19120-01/open.solaris/816-5137/tlib-1/index.html
YOLO: https://pjreddie.com/darknet/yolo/
Computer Vision Models: https://roboflow.com/