Giter VIP home page Giter VIP logo

darkhelp's Introduction

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 first. See the Darknet repo for details.

Building DarkHelp (Linux)

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

sudo apt-get install 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)

You must build Darknet first. See the Darknet repo for details.

Building DarkHelp (Windows)

Once you finish building Darknet, 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

darkhelp's People

Contributors

stephanecharette avatar erikreed avatar olokos avatar s95huang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.