DarkHelp - C++ wrapper library for Darknet

Overview

What is the DarkHelp C++ API?

The DarkHelp C++ API is a wrapper to make it easier to use the Darknet neural network framework within a C++ application. DarkHelp performs the following:

  • load a Darknet-style neural network (.cfg, .names, .weights)
  • run inference on images -- either filenames or OpenCV cv::Mat images and video frames -- and return a vector of results
  • optionally annotate images/frames with the inference results

Example annotated image after calling DarkHelp::NN::predict() and DarkHelp::NN::annotate():

annotated image example

What is the DarkHelp CLI?

DarkHelp also has a very simple command-line tool that uses the DarkHelp C++ API so some of the functionality can be accessed directly from the command-line. This can be useful to run tests or for shell scripting.

What is the DarkHelp Server?

DarkHelp Server is a command-line tool that loads a neural network once, and then keeps running in the background. It repeatedly applies the network to images or video frames and saves the results.

Unlike Darknet and the DarkHelp CLI which have to re-load the neural network every time they're called, DarkHelp Server only does this once. DarkHelp Server can be configured to save the results in .txt format, .json format, annotate images, and can also crop the objects and create individual image files from each of the objects detected by the neural network.

License

DarkHelp is open source and published using the MIT license. Meaning you can use it in your commercial application. See license.txt for details.

How to Build DarkHelp (Linux)

Extremely simple easy-to-follow tutorial on how to build Darknet, DarkHelp, and DarkMark.

DarkHelp build tutorial

DarkHelp requires that Darknet has already been built and installed, since DarkHelp is a wrapper for the C functionality available in libdarknet.so.

Building Darknet (Linux)

You must build Darknet with the LIBSO=1 variable set to have it build libdarknet.so. On Ubuntu:

sudo apt-get install build-essential git libopencv-dev
cd ~/src
git clone https://github.com/AlexeyAB/darknet.git
cd darknet
# edit Makefile to set LIBSO=1, and possibly other flags
make
sudo cp libdarknet.so /usr/local/lib/
sudo cp include/darknet.h /usr/local/include/
sudo ldconfig

Building DarkHelp (Linux)

Now that Darknet is built and installed, you can go ahead and build DarkHelp. On Ubuntu:

sudo apt-get install cmake build-essential libtclap-dev libmagic-dev libopencv-dev
cd ~/src
git clone https://github.com/stephanecharette/DarkHelp.git
cd DarkHelp
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make
make package
sudo dpkg -i darkhelp*.deb

Building Darknet (Windows)

The Windows build uses vcpkg to install the necessary 3rd-party libraries such as OpenCV. See the files readme_windows.txt and build_windows.cmd for details.

Start the "Developer Command Prompt for Visual Studio" (not Power Shell!) and run the following commands to build Darknet and OpenCV:

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

Building DarkHelp (Windows)

Once you finish building Darknet and OpenCV, run the following commands in the "Developer Command Prompt for VS" to build DarkHelp:

cd c:\src\vcpkg
vcpkg.exe install tclap:x64-windows
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 ..
msbuild.exe /property:Platform=x64;Configuration=Release /target:Build -maxCpuCount -verbosity:normal -detailedSummary DarkHelp.sln

Make sure you update the path to the toolchain file if you used a different directory.

If you have NSIS installed, then you can create an installation package with this command:

msbuild.exe /property:Platform=x64;Configuration=Release PACKAGE.vcxproj

Example Code

DarkHelp has many optional settings that impact the output, especially DarkHelp::NN::annotate().

To keep it simple this example code doesn't change any settings. It uses the default values as it runs inference on several images and saves the output:

// include DarkHelp.hpp and link against libdarkhelp, libdarknet, and OpenCV
//
const auto samples_images = {"dog.jpg", "cat.jpg", "horse.jpg"};
//
// Only do this once.  You don't want to keep reloading the network inside
// the loop because loading the network is actually a long process that takes
// several seconds to run to finish.
DarkHelp::NN nn("animals.cfg", "animals_best.weights", "animals.names");
//
for (const auto & filename : samples_images)
{
    // get the predictions; on a decent GPU this should take milliseconds,
    // while on a CPU this might take a full second or more
    const auto results = nn.predict(filename);
    //
    // display the results on the console
    // (meaning coordinates and confidence levels, not displaying the image)
    std::cout << results << std::endl;
    //
    // annotate the image and save the results
    cv::Mat output = nn.annotate();
    cv::imwrite("output_" + filename, output, {CV_IMWRITE_PNG_COMPRESSION, 9});
}

C++ API Doxygen Output

The official DarkHelp documentation and web site is at https://www.ccoderun.ca/darkhelp/.

Some links to specific useful pages:

tiled image example

Comments
  • Error in make project

    Error in make project

    I am trying to compile the project but has the following error occurred:

    `[ 25%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o In file included from /opt/DarkHelp/src-lib/DarkHelp.cpp:6:0: /opt/DarkHelp/src-lib/DarkHelp.hpp:559:7: error: âHersheyFontsâ in namespace âcvâ does not name a type cv::HersheyFonts annotation_font_face; ^~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp: In member function âvirtual void DarkHelp::reset()â: /opt/DarkHelp/src-lib/DarkHelp.cpp:201:2: error: âannotation_font_faceâ was not declared in this scope annotation_font_face = cv::HersheyFonts::FONT_HERSHEY_SIMPLEX; ^~~~~~~~~~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp:201:32: error: âcv::HersheyFontsâ has not been declared annotation_font_face = cv::HersheyFonts::FONT_HERSHEY_SIMPLEX; ^~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp: In member function âvirtual DarkHelp::PredictionResults DarkHelp::predict_tile(cv::Mat, float)â: /opt/DarkHelp/src-lib/DarkHelp.cpp:361:31: error: âcv::HersheyFontsâ has not been declared const auto font = cv::HersheyFonts::FONT_HERSHEY_PLAIN; ^~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp:376:54: error: âFILLEDâ is not a member of âcvâ cv::rectangle(mat, label_rect, {255, 255, 255}, cv::FILLED, cv::LINE_AA); ^~

    /opt/DarkHelp/src-lib/DarkHelp.cpp:376:66: error: âLINE_AAâ is not a member of âcvâ cv::rectangle(mat, label_rect, {255, 255, 255}, cv::FILLED, cv::LINE_AA); ^~

    /opt/DarkHelp/src-lib/DarkHelp.cpp: In member function âvirtual cv::Mat DarkHelp::annotate(float)â: /opt/DarkHelp/src-lib/DarkHelp.cpp:565:58: error: âannotation_font_faceâ was not declared in this scope const cv::Size text_size = cv::getTextSize(pred.name, annotation_font_face, annotation_font_scale, annotation_font_thickness, &baseline); ^~~~~~~~~~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp:594:51: error: âannotation_font_faceâ was not declared in this scope const cv::Size text_size = cv::getTextSize(str, annotation_font_face, annotation_font_scale, annotation_font_thickness, nullptr); ^~~~~~~~~~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp:607:57: error: âannotation_font_faceâ was not declared in this scope const cv::Size text_size = cv::getTextSize(timestamp, annotation_font_face, annotation_font_scale, annotation_font_thickness, nullptr); ^~~~~~~~~~~~~~~~~~~~

    /opt/DarkHelp/src-lib/DarkHelp.cpp: In member function âvirtual std::__cxx11::string DarkHelp::duration_string()â: /opt/DarkHelp/src-lib/DarkHelp.cpp:700:13: error: âsetwâ is not a member of âstdâ << "." << std::setw(3) << std::setfill('0') ^~~ /opt/DarkHelp/src-lib/DarkHelp.cpp:700:29: error: âsetfillâ is not a member of âstdâ << "." << std::setw(3) << std::setfill('0') ^~~

    src-lib/CMakeFiles/dh.dir/build.make:62: recipe for target 'src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o' failed make[2]: *** [src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o] Error 1 CMakeFiles/Makefile2:85: recipe for target 'src-lib/CMakeFiles/dh.dir/all' failed make[1]: *** [src-lib/CMakeFiles/dh.dir/all] Error 2 Makefile:151: recipe for target 'all' failed make: *** [all] Error 2 ` My libopencv-dev is 2.4.9.1

    opened by decesarojunior 10
  • make error in Linux

    make error in Linux

    Building ver: 1.3.11-1
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /share_data/YuhaoSun/DarkHelp-master/build
    (yolox) root@test:/share_data/YuhaoSun/DarkHelp-master/build# make
    Scanning dependencies of target dh
    [ 16%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o
    [ 33%] Linking CXX static library libdarkhelp.a
    [ 33%] Built target dh
    Scanning dependencies of target cli
    [ 50%] Building CXX object src-tool/CMakeFiles/cli.dir/DarkHelpCli.cpp.o
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:131:35: error: use of deleted function ‘std::atomic<bool>::atomic(const std::atomic<bool>&)’
     std::atomic<bool> signal_raised = false;
                                       ^
    In file included from /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:10:0:
    /usr/include/c++/5/atomic:66:5: note: declared here
         atomic(const atomic&) = delete;
         ^
    /usr/include/c++/5/atomic:70:15: note:   after user-defined conversion: constexpr std::atomic<bool>::atomic(bool)
         constexpr atomic(bool __i) noexcept : _M_base(__i) { }
                   ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In function ‘void show_help_window()’:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:20: error: expected unqualified-id before ‘[’ token
      for (const auto & [key, val] : help)
                        ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:20: error: expected ‘;’ before ‘[’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:21: error: ‘key’ was not declared in this scope
      for (const auto & [key, val] : help)
                         ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:26: error: ‘val’ was not declared in this scope
      for (const auto & [key, val] : help)
                              ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In lambda function:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:31: error: expected ‘{’ before ‘:’ token
      for (const auto & [key, val] : help)
                                   ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In function ‘void show_help_window()’:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:31: error: expected ‘;’ before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:31: error: expected primary-expression before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:31: error: expected ‘)’ before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:220:31: error: expected primary-expression before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:215:13: error: unused variable ‘font_face’ [-Werror=unused-variable]
      const auto font_face  = cv::HersheyFonts::FONT_HERSHEY_SIMPLEX;
                 ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:216:13: error: unused variable ‘font_scale’ [-Werror=unused-variable]
      const auto font_scale  = 0.5;
                 ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:217:13: error: unused variable ‘font_thickness’ [-Werror=unused-variable]
      const auto font_thickness = 1;
                 ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:219:6: error: unused variable ‘y’ [-Werror=unused-variable]
      int y = 25;
          ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In function ‘void init(Options&, int, char**)’:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:21: error: expected unqualified-id before ‘[’ token
       for (const auto & [key, val] : debug_messages)
                         ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:21: error: expected ‘;’ before ‘[’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:22: error: ‘key’ was not declared in this scope
       for (const auto & [key, val] : debug_messages)
                          ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:27: error: ‘val’ was not declared in this scope
       for (const auto & [key, val] : debug_messages)
                               ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In lambda function:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:32: error: expected ‘{’ before ‘:’ token
       for (const auto & [key, val] : debug_messages)
                                    ^
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp: In function ‘void init(Options&, int, char**)’:
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:32: error: expected ‘;’ before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:32: error: expected primary-expression before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:32: error: expected ‘)’ before ‘:’ token
    /share_data/YuhaoSun/DarkHelp-master/src-tool/DarkHelpCli.cpp:571:32: error: expected primary-expression before ‘:’ token
    cc1plus: all warnings being treated as errors
    src-tool/CMakeFiles/cli.dir/build.make:82: recipe for target 'src-tool/CMakeFiles/cli.dir/DarkHelpCli.cpp.o' failed
    make[2]: *** [src-tool/CMakeFiles/cli.dir/DarkHelpCli.cpp.o] Error 1
    CMakeFiles/Makefile2:184: recipe for target 'src-tool/CMakeFiles/cli.dir/all' failed
    make[1]: *** [src-tool/CMakeFiles/cli.dir/all] Error 2
    Makefile:171: recipe for target 'all' failed
    make: *** [all] Error 2
    
    opened by lantudou 8
  • Build error - Jetson AGX

    Build error - Jetson AGX

    Dear Stephan, Outstanding work on DarkHelp, and DarkMark! I've tried to install them on Jetson AGX and i reived the following problem. (Darknet have been installed with Libso and arch=compute_72

    I have NVIDIA JetPack installed as my Linux with all standard things coming with it.

    Thank you for your support and help!

    error on make: agx-dev-1@agxdev1-desktop:~/developer/darknet/DarkHelp/built$ make [ 16%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o /home/agx-dev-1/developer/darknet/DarkHelp/src-lib/DarkHelp.cpp: In member function ‘virtual DarkHelp& DarkHelp::init(const string&, const string&, const string&, bool, DarkHelp::EDriver)’: /home/agx-dev-1/developer/darknet/DarkHelp/src-lib/DarkHelp.cpp:169:44: error: ‘DNN_BACKEND_CUDA’ is not a member of ‘cv::dnn’ opencv_net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA); ^~~~~~~~~~~~~~~~ /home/agx-dev-1/developer/darknet/DarkHelp/src-lib/DarkHelp.cpp:170:43: error: ‘DNN_TARGET_CUDA’ is not a member of ‘cv::dnn’ opencv_net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA); ^~~~~~~~~~~~~~~ src-lib/CMakeFiles/dh.dir/build.make:62: recipe for target 'src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o' failed make[2]: *** [src-lib/CMakeFiles/dh.dir/DarkHelp.cpp.o] Error 1 CMakeFiles/Makefile2:85: recipe for target 'src-lib/CMakeFiles/dh.dir/all' failed make[1]: *** [src-lib/CMakeFiles/dh.dir/all] Error 2 Makefile:151: recipe for target 'all' failed make: *** [all] Error 2

    Before the error the cmake made this: agx-dev-1@agxdev1-desktop:~/developer/DarkHelp/build$ cmake -DCMAKE_BUILD_TYPE=Release .. -- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done Building ver: 1.3.6-1 -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE
    -- Found OpenCV: /usr (found version "4.1.1") -- Configuring done -- Generating done -- Build files have been written to: /home/agx-dev-1/developer/DarkHelp/build

    opened by mate-hegedus 6
  • error Building DarkHelp (Windows)

    error Building DarkHelp (Windows)

    Building Darknet Commands all worked fine. on the Building DarkHelp (Windows) last command

    LINK : fatal error LNK1181: cannot open input file 'opencv_aruco.lib' [D:\AI\DarkSrc\darkhelp\build\src-tool\cli .vcxproj]

    I uploaded a screenshot of the error ad of the file that's in the error

    any ideas where this file is located or why do I get this?

    err Screenshot 2021-09-10 233944

    opened by sekisek 6
  • Issue with Inference - Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

    Issue with Inference - Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

    I'm running DarkHelp in a C++ application (Through CLion). I am able to conduct detection through video capture but when I attempt to run inference as I get the following error message:

    Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

    Code:

    DarkHelp::Config cfg(config_file, weights_file, names_file ); cfg.enable_tiles = true; cfg.combine_tile_predictions = true; cfg.annotation_auto_hide_labels = false; cfg.annotation_include_duration = true; cfg.annotation_include_timestamp = false;

    DarkHelp::NN nn(cfg)

    const auto result = nn.predict(filename); cv::Mat output = nn.annotate()

    I'm using coco names and config file with pretrained YOLOv4 weights.

    Any idea what could be causing the issue?

    Thanks in advance.

    opened by Brandonio-c 5
  • std namespace errors while compiling using cmake

    std namespace errors while compiling using cmake

    I am building a cross-compilation platform using OpenCV 3.4.4, darknet (and its dependencies) and DarkHelp.

    DarkHelp dependencies such as magic, tclap etc have been cross-compiled successfully along with OpenCV and darknet. I have tested it on my RPi, the darknet libs and exe works.

    When I try to compile Darkhelp,

    cmake -DOpenCV_DIR="${RPI_SYSROOT}/usr/local/lib" -DCMAKE_PREFIX_PATH="${RPI_SYSROOT}/usr/local" ..

    
    -- The C compiler identification is GNU 7.5.0
    -- The CXX compiler identification is GNU 7.5.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    Building ver: 1.4.18-1
    -- Looking for pthread.h
    -- Looking for pthread.h - found
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
    -- Looking for pthread_create in pthreads
    -- Looking for pthread_create in pthreads - not found
    -- Looking for pthread_create in pthread
    -- Looking for pthread_create in pthread - found
    -- Found Threads: TRUE  
    -- Found OpenCV: /home/develop/RPi-sysroot/usr/local (found version "3.4.4") 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: 
    

    make -j4

    
    [ 11%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelpConfig.cpp.o
    In file included from /usr/include/c++/7/ext/string_conversions.h:41:0,
                     from /usr/include/c++/7/bits/basic_string.h:6361,
                     from /usr/include/c++/7/string:52,
                     from /usr/include/c++/7/stdexcept:39,
                     from /usr/include/c++/7/array:39,
                     from /usr/include/c++/7/tuple:39,
                     from /usr/include/c++/7/bits/stl_map.h:63,
                     from /usr/include/c++/7/map:61,
                     from /home/develop/test_darknet/DarkHelp/src-lib/DarkHelp.hpp:9,
                     from /home/develop/test_darknet/DarkHelp/src-lib/DarkHelpConfig.cpp:6:
    /usr/include/c++/7/cstdlib:144:11: error: '::calloc' has not been declared
       using ::calloc;
               ^~~~~~
    /usr/include/c++/7/cstdlib:147:11: error: '::free' has not been declared
       using ::free;
               ^~~~
    /usr/include/c++/7/cstdlib:151:11: error: '::malloc' has not been declared
       using ::malloc;
               ^~~~~~
    
    

    This is a short part of the error. All the calls to std:: are reported.

    While searching for a solution, I found this post

    It seems some include<> are done within the namespace{} as I came across multiple forum posts. Let me know if any more information is required to find a solution.

    opened by ashishmagar600 4
  • Compilation error on Raspberry Pi 4 / CM4 : cannot convert ‘const long long int*’ to ‘const time_t*’ {aka ‘const long int*’}

    Compilation error on Raspberry Pi 4 / CM4 : cannot convert ‘const long long int*’ to ‘const time_t*’ {aka ‘const long int*’}

    I stumbled on this compilation fatal error (output.txt) while trying to compile Darkhelp on Compute Module 4 (armv7l Raspbian). This error occurred in 2 files : first in DarkHelpServer.cpp and secondly in DarkHelpCli.cpp

    I bypassed this error by editing line 230 in DarkHelpServer.cpp and line 1046 in DarkHelpCli.cpp https://github.com/stephanecharette/DarkHelp/blob/318e33d4fe7b97ec02e1086bac7c3adfd73ec74d/src-tool/DarkHelpServer.cpp#L230 https://github.com/stephanecharette/DarkHelp/blob/318e33d4fe7b97ec02e1086bac7c3adfd73ec74d/src-tool/DarkHelpCli.cpp#L1046

    I wrote in both files:

    std::time_t t = seconds; const auto lt = std::localtime(&t);

    Can you check if my update is correct and update these two files if it complies with your code ?

    Thank you in advance.

    PS : Thank you for your job done on this project, it's incredible how it's easy to use darknet with your help.

    opened by QuietLullaby 4
  • Does DarkHelp Implement Image Tiling during Inference?

    Does DarkHelp Implement Image Tiling during Inference?

    @stephanecharette I'm exploring image tiling to improve small object detection. I see that DarkHelp and Darkmark has the ability implement image tiling on datasets; but it's not clear to me if Darkmark implements tiling during inference.

    Thanks in advance,

    opened by seabass1217 4
  • DarkHelp Crashes when using Single Channel Networks and OpenCV

    DarkHelp Crashes when using Single Channel Networks and OpenCV

    When using DarkHelp to load a yolov4-tiny single channel network (grayscale images), and configuring it to use OPENCV as a backend, the program crashes. This can fixed be setting the initial dummy matrix sent to the OpenCV constructor with the appropriate matrix type of CV_8UC1, as shown:

    image

    Rather than hardcoding, I think it would be best to read the darknet .cfg file to get the number of channels in the network, and use that value to set the matrix type appropriately, similar to what is done immediately above this section of code with regards to the network dimensions.

    Both DarkMark and DarkHelp are excellent!

    opened by erikstauber 3
  • Compiling on Rocky Linux

    Compiling on Rocky Linux

    I'm having trouble installing on Rocky Linux (basically CentOS 8). I've installed darknet following your instructions and it's working.

    CUDA-version: 11060 (11060), cuDNN: 8.4.0, CUDNN_HALF=1, GPU count: 1  
     CUDNN_HALF=1 
     OpenCV version: 3.4.6
    

    When I try to make DarkMark I get the following issue.

    # cmake -DCMAKE_BUILD_TYPE=Release ..
    -- The C compiler identification is GNU 8.5.0
    -- The CXX compiler identification is GNU 8.5.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    Building ver: 1.4.16-1
    -- Looking for pthread.h
    -- Looking for pthread.h - found
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
    -- Looking for pthread_create in pthreads
    -- Looking for pthread_create in pthreads - not found
    -- Looking for pthread_create in pthread
    -- Looking for pthread_create in pthread - found
    -- Found Threads: TRUE  
    CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
      Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (found
      suitable exact version "11.6")
    Call Stack (most recent call first):
      /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
      /usr/share/cmake/Modules/FindCUDA.cmake:1264 (find_package_handle_standard_args)
      /usr/local/lib64/cmake/opencv4/OpenCVConfig.cmake:86 (find_package)
      /usr/local/lib64/cmake/opencv4/OpenCVConfig.cmake:108 (find_host_package)
      CM_dependencies.cmake:7 (FIND_PACKAGE)
      CMakeLists.txt:18 (INCLUDE)
    
    
    -- Configuring incomplete, errors occurred!
    

    CMakeError.log CMakeOutput.log

    Seems to have something to with with pthreads. I have libpthread installed and create seems to be available.

    # nm /lib64/libpthread.so.0 | grep "pthread_create"
    00000000000093d4 t .annobin___pthread_create_2_1.end
    0000000000008458 t .annobin___pthread_create_2_1.start
    0000000000006ed0 t .annobin_pthread_create.c
    00000000000093d4 t .annobin_pthread_create.c_end
    000000000000683c t .annobin_pthread_create.c_end.exit
    000000000000683c t .annobin_pthread_create.c_end.hot
    000000000000683c t .annobin_pthread_create.c_end.startup
    000000000000683c t .annobin_pthread_create.c_end.unlikely
    000000000000683c t .annobin_pthread_create.c.exit
    000000000000683c t .annobin_pthread_create.c.hot
    000000000000683c t .annobin_pthread_create.c.startup
    0000000000006820 t .annobin_pthread_create.c.unlikely
    0000000000008460 t __pthread_create_2_1
    000000000000682e t __pthread_create_2_1.cold.12
    0000000000008460 T pthread_create@@GLIBC_2.2.5
    

    Any help would be very appreciated. I'm trying to get DarkMark installed and from the video it looks amazing!

    Thanks!

    opened by agorman 3
  • CMAKE build issue Windows Server: Cant find FindCUDNN.cmake CUDNNconfig.cmake CUDNN_config.cmake

    CMAKE build issue Windows Server: Cant find FindCUDNN.cmake CUDNNconfig.cmake CUDNN_config.cmake

    Trying to install DarkHelp on Windows Server 2019 with GeForce Ge 1660. Have installed OpenCV with DNN , Installed DarkNet as per the Darknet instructions. All Path variables have been updated ,including for CUDNN and CUDNN_PATH and server restarted. OpenCV was built from source with DNN. Darknet is running correctly from the CLI

    Now trying to install DarkHelp as per the sequence in readme_windows.txt.

    When running: cmake -DCMAKE_BUILD_TYPE=Release - DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake ..

    using the command as above as well as when replicating via CMAKE GUI I get the following error:

    CMake Error at C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:829 (_find_package): By not providing "FindCUDNN.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "CUDNN", but CMake did not find one.

    Could not find a package configuration file provided by "CUDNN" with any of the following names:

    CUDNNConfig.cmake
    cudnn-config.cmake
    

    Add the installation prefix of "CUDNN" to CMAKE_PREFIX_PATH or set "CUDNN_DIR" to a directory containing one of the above files. If "CUDNN" provides a separate development package or SDK, be sure it has been installed.

    I located the FindCUDNN.cmake file is in several directories: Opencv/cmake darknet/share/, darknet/cmake/modules, vcpkg/ports/ Any idea how to update the configuration to point towards the correct file? Thanks in advance

    opened by SummerPAI 2
  • Confused about resize aspect ratio training/inferencing

    Confused about resize aspect ratio training/inferencing

    During training, using DarkMark/darknet CUDA on my linux box, I deselected 'resize images' because I didn't want the network to change the aspect ratio of images.... many are smaller than my network dimensions.

    Typical small training images: 96 x 32 Network dimensions: 192 x 96 x 1 Network: YoloV4-Tiny

    As the training progresses, DarkMark seems to properly utilize darknet to predict annotations on unmarked images. So all is good up to this point.

    When I run inferencing on my Windows box, (using darkhelp API, directly with OpenCV/Cuda), I notice that the NN performs very poorly. Digging in, I see that the function DarkHelp::NN::predict_internal_opencv() calls the function fast_resize_ignore_aspect_ratio. If I change that to resize_keeping_aspect_ratio, then the network performs properly. Shouldn't the prediction function maintain the aspect ratio?

    image

    opened by erikstauber 3
  • cannot open source file

    cannot open source file "DarkHelp.hpp"

    I did all steps from readme_windows.txt, generated a Visual Studio solution, but when I build it I see this:

    cannot open source file "DarkHelp.hpp" D:\Projects\DarkHelp\src-lib\DarkHelpConfig.cpp

    image

    How to fix it?

    opened by nithrous 4
  • DarkHelp Compile error mac os x

    DarkHelp Compile error mac os x

    Hi I have below strange error when compiling darknet.

    cmake -DCMAKE_BUILD_TYPE=Release .. -- The C compiler identification is AppleClang 11.0.0.11000033 -- The CXX compiler identification is AppleClang 11.0.0.11000033 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done Building ver: 1.4.27-1 -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Found OpenCV: /usr/local (found version "3.4.8") -- Configuring done CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: Magic linked by target "cli" in directory /Users/tulpar/Project/DarkHelp/src-tool linked by target "server" in directory /Users/tulpar/Project/DarkHelp/src-tool

    -- Generating done CMake Generate step failed. Build files cannot be regenerated correctly. ╭─[email protected] ~/Project/DarkHelp/build ‹master› ╰─➤ make -j4 1 ↵ [ 44%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelpNN.cpp.o [ 44%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelpUtils.cpp.o [ 44%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelpConfig.cpp.o [ 44%] Building CXX object src-lib/CMakeFiles/dh.dir/DarkHelpPredictionResult.cpp.o /Users/tulpar/Project/DarkHelp/src-lib/DarkHelpNN.cpp:821:23: error: unused function 'convert_darknet_image_to_opencv_mat' [-Werror,-Wunused-function] static inline cv::Mat convert_darknet_image_to_opencv_mat(const image img) ^ 1 error generated. make[2]: *** [src-lib/CMakeFiles/dh.dir/DarkHelpNN.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[1]: *** [src-lib/CMakeFiles/dh.dir/all] Error 2 make: *** [all] Error 2

    opened by MyraBaba 1
  • yolov7

    yolov7

    Hi, @stephanecharette

    I am new to darknet and impressed by your c++ DarkHelp very good coverage.

    We are using AI for detecting vehicles from intersections . currently using yolov7 and fairy good enough . We want to give a shot and possibly change to c++ . can we use yolov7 models with darknet. ? If now which model you suggest for replacing yolov7e6 ?

    We also want to detect small vehicles from 4Mp resolution . tiling looks very good solution for that. detecting and tracking (bytetrack at the moment)

    When tiling we are inferencing more than one image per image. so it make slower . However can we doing inference simultaneously (batch) for tiled version ?

    opened by MyraBaba 1
  • 'undefined reference to function' after -static compilation using make for DarkHelp project

    'undefined reference to function' after -static compilation using make for DarkHelp project

    OS: Ubuntu 18.04 LTS

    Built DarkNet succesfully and can be used with './darknet'

    Built DarkHelp using this and compiled 'example_project'.

    I am trying to build a standalone executable "exe_static" to be used on linux systems, where I might not have the privileges to install dependencies.

    Copied DarkHelp/build/src-lib/libdarkhelp.a and libdarknet.a to /usr/lib/

    exe_static.cpp

    #include <DarkHelp.hpp>
    #include <typeinfo>
    
    
    int main(int argc, char *argv[])
    {
    	DarkHelp::Config cfg("model.cfg", "model.weights", "names.list");
    	cfg.enable_tiles			= true;
    	cfg.combine_tile_predictions		= true;
    	cfg.annotation_auto_hide_labels		= false;
    	cfg.annotation_include_duration		= false;
    	cfg.annotation_include_timestamp	= false;
    
    	DarkHelp::NN nn(cfg);
    	const auto results = nn.predict(argv[1]);
    
    //        std::cout <<"Shape of result = : " << results.size() << "\n";
    
    	return 0;
    }
    
    

    CMakeLists.txt

    CMAKE_MINIMUM_REQUIRED (VERSION 3.0)
    
    PROJECT (ExampleProject C CXX)
    
    SET (CMAKE_BUILD_TYPE Release)
    SET (CMAKE_CXX_STANDARD 17)
    SET (CMAKE_CXX_STANDARD_REQUIRED ON)
    
    ADD_DEFINITIONS ("-Wall -Wextra -Werror -Wno-unused-parameter ")
    
    FIND_PACKAGE (Threads	REQUIRED)
    FIND_PACKAGE (OpenCV	REQUIRED)
    #FIND_LIBRARY (DARKHELP	libdarkhelp.a)
    #FIND_LIBRARY (DARKNET	libdarknet.a)
    
    INCLUDE_DIRECTORIES (${OpenCV_INCLUDE_DIRS})
    
    FILE (GLOB SOURCE *.cpp)
    LIST (SORT SOURCE)
    
    SET (BUILD_SHARED_LIBS=OFF)
    SET (OPENCV_GENERATE_PKGCONFIG=YES)
    
    
    ADD_EXECUTABLE (exe_static ${SOURCE})
    
    SET_TARGET_PROPERTIES(exe_static PROPERTIES 
       LINK_SEARCH_START_STATIC ON
       LINK_SEARCH_END_STATIC ON
    )
    
    set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
    
    set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
    
    #TARGET_LINK_LIBRARIES (exe_static Threads::Threads ${DARKHELP} ${DARKNET} ${OpenCV_LIBS})
    TARGET_LINK_LIBRARIES (exe_static Threads::Threads libdarknet.a libdarkhelp.a  ${OpenCV_LIBS} )
    
    

    Same file structure as DarkHelp/example_project

    $> cd build $> cmake ..

    -- The C compiler identification is GNU 7.5.0
    -- The CXX compiler identification is GNU 7.5.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Looking for pthread.h
    -- Looking for pthread.h - found
    -- Looking for pthread_create
    -- Looking for pthread_create - not found
    -- Looking for pthread_create in pthreads
    -- Looking for pthread_create in pthreads - not found
    -- Looking for pthread_create in pthread
    -- Looking for pthread_create in pthread - found
    -- Found Threads: TRUE  
    -- Found OpenCV: /usr/local (found version "3.4.4") 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /path/to/exe_static/build
    
    

    $> make

    Scanning dependencies of target exe_static
    [ 50%] Building CXX object CMakeFiles/exe_static.dir/exe_static.cpp.o
    [100%] Linking CXX executable exe_static
    /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libdarkhelp.a(DarkHelpNN.cpp.o): In function `DarkHelp::NN::reset()':
    DarkHelpNN.cpp:(.text+0x1ff8): undefined reference to `free_network'
    /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libdarkhelp.a(DarkHelpNN.cpp.o): In function `DarkHelp::NN::predict_internal_darknet()':
    DarkHelpNN.cpp:(.text+0x45ca): undefined reference to `make_image'
    DarkHelpNN.cpp:(.text+0x4715): undefined reference to `network_predict'
    DarkHelpNN.cpp:(.text+0x4761): undefined reference to `get_network_boxes'
    DarkHelpNN.cpp:(.text+0x4b7e): undefined reference to `free_detections'
    DarkHelpNN.cpp:(.text+0x4ba7): undefined reference to `free_image'
    DarkHelpNN.cpp:(.text+0x5190): undefined reference to `do_nms_sort'
    /usr/lib/gcc/x86_64-linux-gnu/7/../../../../lib/libdarkhelp.a(DarkHelpNN.cpp.o): In function `DarkHelp::NN::init()':
    DarkHelpNN.cpp:(.text+0xaa81): undefined reference to `load_network_custom'
    DarkHelpNN.cpp:(.text+0xaaa7): undefined reference to `calculate_binary_weights'
    collect2: error: ld returned 1 exit status
    CMakeFiles/exe_static.dir/build.make:139: recipe for target 'exe_static' failed
    make[2]: *** [exe_static] Error 1
    CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/exe_static.dir/all' failed
    make[1]: *** [CMakeFiles/exe_static.dir/all] Error 2
    Makefile:83: recipe for target 'all' failed
    make: *** [all] Error 2
    
    
    
    opened by ashishmagar600 3
  • DarkHelp does not support batch inference

    DarkHelp does not support batch inference

    Investigate what would be needed to support batch inference.

    See: https://github.com/AlexeyAB/darknet/issues/7541 And: https://github.com/AlexeyAB/darknet/pull/7915

    opened by stephanecharette 5
Owner
Stéphane Charette
C/C++ developer. Mostly linux-based. IoT, desktop, and embedded device. Computer vision, neural networks, Ubuntu geek.
Stéphane Charette
Support Yolov4/Yolov3/Centernet/Classify/Unet. use darknet/libtorch/pytorch to onnx to tensorrt

ONNX-TensorRT Yolov4/Yolov3/CenterNet/Classify/Unet Implementation Yolov4/Yolov3 centernet INTRODUCTION you have the trained model file from the darkn

null 172 Dec 29, 2022
License plate parsing using Darknet and YOLO

DarkPlate Note that DarkPlate by itself is not a complete software project. The intended purpose was to create a simple project showing how to use Dar

Stéphane Charette 35 Dec 9, 2022
C++11 wrapper for the LMDB embedded B+ tree database library.

lmdb++: a C++11 wrapper for LMDB This is a comprehensive C++ wrapper for the LMDB embedded database library, offering both an error-checked procedural

D.R.Y. C++ 263 Dec 27, 2022
Implement yolov5 with Tensorrt C++ api, and integrate batchedNMSPlugin. A Python wrapper is also provided.

yolov5 Original codes from tensorrtx. I modified the yololayer and integrated batchedNMSPlugin. A yolov5s.wts is provided for fast demo. How to genera

weiwei zhou 46 Dec 6, 2022
cudnn_frontend provides a c++ wrapper for the cudnn backend API and samples on how to use it

cuDNN Frontend API Introduction The cuDNN Frontend API is a C++ header-only library that demonstrates how to use the cuDNN C backend API. The cuDNN C

NVIDIA Corporation 127 Dec 28, 2022
Watertight Manifold Python Wrapper

Watertight Manifold Python Wrapper This repository is a simple PythonWrapper around the origin implementation of the paper: Huang, Jingwei, Hao Su, an

Photogrammetry & Robotics Bonn 20 Dec 27, 2022
A simple ros wrapper for apriltag-cpp

Ros wrapper for apriltags-cpp Ros wrapper of the APRIL tags library, using OpenCV (and optionally, CGAL). Requirements Currently, apriltags-cpp requir

Robot Perception & Navigation Group (RPNG) 6 Dec 30, 2021
ROS wrapper for real-time incremental event-based vision motion estimation by dispersion minimisation

event_emin_ros ROS wrapper for real-time incremental event-based vision motion estimation by dispersion minimisation (EventEMin). This code was used t

Imperial College London 2 Jan 10, 2022
Python wrapper for Environment Simulator Minimalistic (esmini)

python-esmini is a python wrapper for Environment Simulator Minimalistic (esmini). Install the package python-esmini is now only available for the Lin

Hamid Ebadi 6 Aug 4, 2022
The dgSPARSE Library (Deep Graph Sparse Library) is a high performance library for sparse kernel acceleration on GPUs based on CUDA.

dgSPARSE Library Introdution The dgSPARSE Library (Deep Graph Sparse Library) is a high performance library for sparse kernel acceleration on GPUs bas

dgSPARSE 59 Dec 5, 2022
C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library

Build Status Travis CI VM: Linux x64: Raspberry Pi 3: Jetson TX2: Backstory I set to build ccv with a minimalism inspiration. That was back in 2010, o

Liu Liu 6.9k Jan 6, 2023
Edge ML Library - High-performance Compute Library for On-device Machine Learning Inference

Edge ML Library (EMLL) offers optimized basic routines like general matrix multiplications (GEMM) and quantizations, to speed up machine learning (ML) inference on ARM-based devices. EMLL supports fp32, fp16 and int8 data types. EMLL accelerates on-device NMT, ASR and OCR engines of Youdao, Inc.

NetEase Youdao 179 Dec 20, 2022
The Robotics Library (RL) is a self-contained C++ library for rigid body kinematics and dynamics, motion planning, and control.

Robotics Library The Robotics Library (RL) is a self-contained C++ library for rigid body kinematics and dynamics, motion planning, and control. It co

Robotics Library 656 Jan 1, 2023
A GPU (CUDA) based Artificial Neural Network library

Updates - 05/10/2017: Added a new example The program "image_generator" is located in the "/src/examples" subdirectory and was submitted by Ben Bogart

Daniel Frenzel 93 Dec 10, 2022
Header-only library for using Keras models in C++.

frugally-deep Use Keras models in C++ with ease Table of contents Introduction Usage Performance Requirements and Installation FAQ Introduction Would

Tobias Hermann 926 Dec 30, 2022
simple neural network library in ANSI C

Genann Genann is a minimal, well-tested library for training and using feedforward artificial neural networks (ANN) in C. Its primary focus is on bein

Lewis Van Winkle 1.3k Dec 29, 2022
oneAPI Deep Neural Network Library (oneDNN)

oneAPI Deep Neural Network Library (oneDNN) This software was previously known as Intel(R) Math Kernel Library for Deep Neural Networks (Intel(R) MKL-

oneAPI-SRC 3k Jan 6, 2023
A lightweight C library for artificial neural networks

Getting Started # acquire source code and compile git clone https://github.com/attractivechaos/kann cd kann; make # learn unsigned addition (30000 sam

Attractive Chaos 617 Dec 19, 2022
LibDEEP BSD-3-ClauseLibDEEP - Deep learning library. BSD-3-Clause

LibDEEP LibDEEP is a deep learning library developed in C language for the development of artificial intelligence-based techniques. Please visit our W

Joao Paulo Papa 22 Dec 8, 2022