DarkHelp C++ Wrapper for Darknet

repository·master·Indexed 41 days ago

https://github.com/stephanecharette/darkhelp

A C++ wrapper for the Darknet neural network framework that provides a high-level API for loading models, performing inference on images or video, and annotating results. It includes a CLI tool, a high-performance DarkHelp Server for continuous inference, and the DarkHelp::NN class for integrating computer vision capabilities into C++ applications.

Tokens
4.9K
Snippets
23
Records
26
Agent score
51%

What's inside DarkHelp

  1. What is the DarkHelp C++ API?

    master

    The DarkHelp C++ API is a wrapper for the Darknet neural network framework, designed to simplify integration into C++ applications.

    Key capabilities include:

    • Loading Darknet-style neural networks using .cfg, .names, and .weights files.
    • Running inference on images (via filenames or OpenCV cv::Mat) and video frames.
    • Returning results as a vector of PredictionResult objects.
    • Optionally annotating images/frames with the inference results (bounding boxes, labels, etc.).
    // Example of the core workflow
    DarkHelp::NN nn("model.cfg", "model.weights", "model.names");
    const auto results = nn.predict("image.jpg");
    cv::Mat annotated_image = nn.annotate();
  2. What is the DarkHelp CLI?

    master
    DarkHelp includes a simple command-line tool built on top of the C++ API. It allows you to access DarkHelp's functionality directly from the terminal, which is useful for running tests or integrating into shell scripts without writing custom C++ code.
  3. What is the DarkHelp Server?

    master

    DarkHelp Server is a specialized command-line tool designed for high-performance, continuous inference.

    Unlike the standard CLI or Darknet, which reload the neural network for every execution, the DarkHelp Server loads the network into memory once and keeps it running in the background. It can be configured to:

    • Save results in .txt or .json format.
    • Annotate images.
    • Crop detected objects and save them as individual image files.
  4. Set up OpenCV and Darknet using vcpkg

    master

    DarkHelp requires OpenCV and Darknet. The recommended way to set these up on Windows is via vcpkg. This process involves bootstrapping vcpkg, integrating it with your environment, and installing the specific feature-enabled packages for OpenCV and Darknet.

    mkdir c:\src
    cd c:\src
    git clone https://github.com/microsoft/vcpkg
    cd vcpkg
    bootstrap-vcpkg.bat
    vcpkg.exe integrate install
    vcpkg.exe integrate powershell
    vcpkg.exe install opencv[contrib,core,dnn,ffmpeg,jpeg,png,quirc,tiff,webp]:x64-windows darknet[opencv-base]:x64-windows
  5. Use src-apps as a starting point for DarkHelp C++ development

    master

    The src-apps directory contains simple, single-purpose C++ applications designed to demonstrate how to use the DarkHelp C++ API. These apps are intended as templates for developers to modify rather than as production-ready software. Most examples use the Rolodex example dataset.

    Windows Dependency Note: When running these apps on Windows, ensure the application has access to the DLL files located in C:\Program Files\Darknet\bin\ and C:\Program Files\DarkHelp\bin\. These include dependencies like OpenCV, Darknet, CUDA, and cuDNN.

  6. Install Visual Studio and Prerequisites on Windows

    master

    To build DarkHelp on Windows, you must first install Visual Studio 2019 (or later) with the "Desktop development with C++" workload. You also need WinGet to install Git, CMake, and NSIS.

    Note: These instructions are considered legacy. For the most up-to-date installation steps, refer to the readme.md in the main DarkHelp repository.

    # Install dependencies via WinGet
    winget install git.git
    winget install kitware.cmake
    winget install nsis
  7. Build OpenCV and Darknet using vcpkg

    master

    To build the underlying dependencies, use vcpkg.

    Note: You must manually modify the OpenCV portfile to enable GTK support, otherwise video plugins and highgui will not work correctly.

    1. Bootstrap vcpkg in ~/src/vcpkg.
    2. Edit ~/src/vcpkg/ports/opencv4/portfile.cmake and change -DWITH_GTK=OFF to -DWITH_GTK=ON.
    3. Run the appropriate installation command based on your hardware requirements.
    # 1. Setup vcpkg
    mkdir ~/src && cd ~/src
    git clone https://github.com/microsoft/vcpkg
    cd vcpkg
    ./bootstrap-vcpkg.sh
    ./vcpkg integrate install
    ./vcpkg integrate bash
    
    # 2. Edit ~/src/vcpkg/ports/opencv4/portfile.cmake
    # Change -DWITH_GTK=OFF to -DWITH_GTK=ON
    
    # 3. Install dependencies
    # For GPU/CUDA support:
    ./vcpkg install --triplet x64-linux tclap cuda cudnn opencv-cuda darknet[cuda,cudnn,opencv-cuda]
    
    # For CPU only:
    ./vcpkg install --triplet x64-linux tclap opencv darknet[opencv-base]
  8. Build a CMake-based C++ project using DarkHelp on Linux

    master

    To build a project that integrates DarkHelp, Darknet, and OpenCV using CMake on a Linux system, follow these steps:

    1. Create a build directory.
    2. Navigate into the build directory.
    3. Run cmake .. to generate the build files.
    4. Run make to compile the project.
    mkdir build
    cd build
    cmake ..
    make
  9. Install pre-requisites on Ubuntu/Debian

    master

    Before building DarkHelp, install the necessary system dependencies using apt-get. This includes build tools, compression utilities, and development libraries for GTK and magic files.

    sudo apt-get install build-essential tar curl zip unzip git cmake libmagic-dev libgtk2.0-dev pkg-config yasm
  10. Install and Build DarkHelp on Linux

    master

    DarkHelp is a wrapper for libdarknet.so, so you must build and install Darknet first.

    Prerequisites

    On Ubuntu, install the following dependencies:

    sudo apt-get install build-essential libtclap-dev libmagic-dev libopencv-dev

    Build Steps

    1. Clone the repository:
    git clone https://github.com/stephanecharette/DarkHelp.git
    cd DarkHelp
    1. Build using CMake:
    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Release ..
    make
    make package
    1. Install the generated package:
    sudo dpkg -i darkhelp*.deb
    cmake -DCMAKE_BUILD_TYPE=Release ..
    make
    make package
    sudo dpkg -i darkhelp*.deb
  11. Build DarkHelp from source on Windows

    master

    After setting up the prerequisites, you can build DarkHelp using CMake and MSBuild. You will need to install the tclap package via vcpkg before configuring the DarkHelp project. The CMake configuration must point to the vcpkg.cmake toolchain file.

    # Install tclap dependency
    cd c:\src\vcpkg
    vcpkg.exe install tclap:x64-windows
    
    # Clone and configure DarkHelp
    cd c:\src
    git clone https://github.com/stephanecharette/DarkHelp.git
    cd darkhelp
    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake ..
    
    # Build using MSBuild
    msbuild.exe /property:Platform=x64;Configuration=Release /target:Build -maxCpuCount -verbosity:normal -detailedSummary DarkHelp.sln