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.
Earlier versions of the Darknet tool exported all functions and structures publicly. The API was not documented.
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.
darknet.h
header file, you must define DARKNET_INCLUDE_ORIGINAL_API:
network
and layer
structures are no longer exposed in the public V2 API.network
structure is no longer passed by value within Darknet/YOLO. Instead, you must now pass a void*
pointer, which is known as DarknetNetworkPtr in C
or Darknet::NetworkPtr in C++
. Some examples:network
object should be replaced by network_predict_ptr(), and the first parameter is no longer a full network
structure but a pointer to the neural network (DarknetNetworkPtr).network
object should be replaced by free_network_ptr(), and the first parameter is a pointer to the network (DarknetNetworkPtr).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
.
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:
The full list of function calls is in darknet.h.
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.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.