Darknet/YOLO v3.0-177-gfa2353b
Object Detection Framework
 
Loading...
Searching...
No Matches
Darknet/YOLO API

Since Darknet started in 2013, there have been several APIs available to access Darknet/YOLO from other applications.

The V2 C API is the original Darknet/YOLO API. It is recommended that new applications skip the original API, and use the new V3 C API or V3 C++ API instead.

For Python users, see V3 Python API.

V2 C API

Earlier versions of the Darknet tool exported all functions and structures publicly. The API was not documented.

Note
Where possible, it is recommended that new or refactored code use the V3 C API or V3 C++ API instead.

The original V2 API consisted of C functions such as:

The V2 API also exposed many C structures including:

In July 2024, the old V2 C API had to be modified due to changes in the Darknet/YOLO codebase for V3 released in August 2024. If your application uses the old Darknet V2 API, you will have to make some minor changes to continue to use the original Darknet V2 API.

  • Before including the darknet.h header file, you must define DARKNET_INCLUDE_ORIGINAL_API:
#define DARKNET_INCLUDE_ORIGINAL_API
#include <darknet.h>
Include this file to get access to the Darknet/YOLO C API.
Note
If you previously used other Darknet functions which are no longer exposed, please come chat with us on the Darknet/YOLO discord so we can determine exactly what is needed by users of the Darknet/YOLO API.

V3 C++ API

The Darknet V3 API is defined in files such as darknet.hpp and darknet_image.hpp. It is meant to be simpler to use than the V2 API, and should be better documented. This includes functions such as:

Header files that define the public Darknet/YOLO C++ API include

Also see the documentation for the Darknet namespace.

The simplest way to understand the V3 API is to look at the source examples, such as src-examples/darknet_02_display_annotated_images.cpp.

V3 C API

The Darknet V3 C API should be very similar to the C++ API. The functions and structures are named almost the same way. For example:

V3 C API V3 C++ API
darknet_set_detection_threshold() Darknet::set_detection_threshold()
darknet_set_non_maximal_suppression_threshold() Darknet::set_non_maximal_suppression_threshold()
darknet_network_dimensions() Darknet::network_dimensions()
darknet_load_neural_network() Darknet::load_neural_network()
darknet_free_neural_network() Darknet::free_neural_network()

The full list of function calls is in darknet.h.

Note
The neural network structure passed around as a void* pointer can be used interchangibly between the C and C++ API. There is no difference between DarknetNetworkPtr, Darknet::NetworkPtr, and void*. Behind the scenes there is only 1 neural network structure known as Darknet::Network. Note that starting with Darknet V3, this structure is no longer exposed publicly.

V3 Python API

The Python API is very similar to the C API. See src-python/darknet.py for details, or src-python/example.py for sample code.

For documentation, see V3 C API.