Include this file to get access to the Darknet/YOLO C API. More...
Classes | |
struct | DarknetBox |
Bounding box used with normalized coordinates (between 0.0 and 1.0). More... | |
struct | DarknetDetection |
Everything Darknet knows about a specific detection. More... | |
struct | DarknetImage |
The structure DarknetImage is used to store a normalized RGB Darknet image. More... | |
Typedefs | |
typedef struct DarknetBox | box |
Bounding box used with normalized coordinates (between 0.0 and 1.0). | |
typedef struct DarknetBox | DarknetBox |
Bounding box used with normalized coordinates (between 0.0 and 1.0). | |
typedef struct DarknetDetection | DarknetDetection |
Everything Darknet knows about a specific detection. | |
typedef struct DarknetImage | DarknetImage |
The structure DarknetImage is used to store a normalized RGB Darknet image. | |
typedef void * | DarknetNetworkPtr |
An opaque pointer to a Darknet::Network object, without needing to expose the internals of the network structure. | |
typedef struct DarknetDetection | detection |
Everything Darknet knows about a specific detection. | |
typedef struct DarknetImage | image |
Darknet-style image (vector of floats). | |
Enumerations | |
enum | NMS_KIND { DEFAULT_NMS , GREEDY_NMS , DIOU_NMS , CORNERS_NMS } |
Functions | |
void | calculate_binary_weights (DarknetNetworkPtr ptr) |
This is part of the original C API. | |
void | copy_image_from_bytes (DarknetImage im, char *pdata) |
This is part of the original C API. Convert from data pointer to a Darknet image. Used by the Python API. | |
void | cuda_set_device (int n) |
This is part of the original C API. This function does nothing when Darknet was built to run on the CPU. | |
void | darknet_add_skipped_class (DarknetNetworkPtr ptr, const int class_to_skip) |
This is the C equivalent to Darknet::add_skipped_class(). | |
void | darknet_clear_skipped_classes (DarknetNetworkPtr ptr) |
This is the C equivalent to Darknet::clear_skipped_classes(). | |
void | darknet_del_skipped_class (DarknetNetworkPtr ptr, const int class_to_include) |
This is the C equivalent to Darknet::del_skipped_classes(). | |
void | darknet_fix_out_of_bound_values (DarknetNetworkPtr ptr, const bool toggle) |
This is the C equivalent to Darknet::fix_out_of_bound_values(). | |
void | darknet_free_neural_network (DarknetNetworkPtr *ptr) |
This is the C equivalent to Darknet::free_neural_network(). | |
DarknetNetworkPtr | darknet_load_neural_network (const char *const cfg_filename, const char *const names_filename, const char *const weights_filename) |
This is the C equivalent to Darknet::load_neural_network(). | |
void | darknet_network_dimensions (DarknetNetworkPtr ptr, int *w, int *h, int *c) |
This is the C equivalent to Darknet::network_dimensions(). | |
void | darknet_set_detection_threshold (DarknetNetworkPtr ptr, float threshold) |
This is the C equivalent to Darknet::set_detection_threshold(). | |
void | darknet_set_gpu_index (int idx) |
This is the C equivalent to Darknet::set_gpu_index(). | |
void | darknet_set_non_maximal_suppression_threshold (DarknetNetworkPtr ptr, float threshold) |
This is the C equivalent to Darknet::set_non_maximal_suppression_threshold(). | |
void | darknet_set_trace (const bool flag) |
This is the C equivalent to Darknet::set_trace(). | |
void | darknet_set_verbose (const bool flag) |
This is the C equivalent to Darknet::set_verbose(). | |
void | darknet_show_version_info () |
This is the C equivalent to Darknet::show_version_info(). | |
const char * | darknet_version_short () |
Return the short version string, such as "3.0.163" . | |
const char * | darknet_version_string () |
Return the full version string, such as "v3.0-163-g56145bf" . | |
void | diounms_sort (detection *dets, int total, int classes, float thresh, NMS_KIND nms_kind, float beta1) |
This is part of the original C API. Non Maxima Suppression. | |
void | do_nms_obj (detection *dets, int total, int classes, float thresh) |
This is part of the original C API. Non Maxima Suppression. | |
void | do_nms_sort (detection *dets, int total, int classes, float thresh) |
This is part of the original C API. Non Maxima Suppression. | |
void | free_detections (detection *dets, int n) |
This is part of the original C API. Do not use in new code. | |
void | free_image (image im) |
This is part of the original C API. | |
void | free_network_ptr (DarknetNetworkPtr ptr) |
This is part of the original C API. | |
void | free_ptrs (void **ptrs, int n) |
This is part of the original C API. | |
detection * | get_network_boxes (DarknetNetworkPtr ptr, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter) |
This is part of the original C API. | |
DarknetImage | load_image_v2 (const char *filename, int desired_width, int desired_height, int channels) |
This is part of the original C API. This function exists for the Python API. | |
DarknetImage | make_empty_image (int w, int h, int c) |
This is part of the original C API. | |
DarknetImage | make_image (int w, int h, int c) |
This is part of the original C API. | |
detection * | make_network_boxes (DarknetNetworkPtr ptr, float thresh, int *num) |
This is part of the original C API. | |
float * | network_predict_image (DarknetNetworkPtr ptr, const DarknetImage im) |
This is part of the original C API. | |
float * | network_predict_image_letterbox (DarknetNetworkPtr ptr, DarknetImage im) |
This is part of the original C API. | |
float * | network_predict_ptr (DarknetNetworkPtr ptr, float *input) |
This is part of the original C API. | |
void | reset_rnn (DarknetNetworkPtr ptr) |
This is part of the original C API. | |
DarknetNetworkPtr | load_network (const char *cfg, const char *weights, int clear) |
DarknetNetworkPtr | load_network_custom (const char *cfg, const char *weights, int clear, int batch) |
Include this file to get access to the Darknet/YOLO C API.
C
API is at the top of the file. C++
API is in darknet.hpp.https://darknetcv.ai/api/api.html
The old C V2 API did not have "darknet"
in the function names nor the structures returned. It defined things like network
and image
in the global namespace, which can cause problems since those are common words. By default this old API is no longer exposed. If you're using some old software that expects the original C
API in the darknet library, then make sure you "#define DARKNET_INCLUDE_ORIGINAL_API"
before you include this header file.
Internally, Darknet still uses the old C
V2 API.
typedef struct DarknetBox box |
Bounding box used with normalized coordinates (between 0.0 and 1.0).
typedef struct DarknetBox DarknetBox |
Bounding box used with normalized coordinates (between 0.0 and 1.0).
typedef struct DarknetDetection DarknetDetection |
Everything Darknet knows about a specific detection.
This structure is used by the old API. If using the new API, use Darknet::Prediction instead.
typedef struct DarknetImage DarknetImage |
The structure DarknetImage is used to store a normalized RGB Darknet image.
The format is intended to be used for internal use by Darknet, but there are some situations where it may also be used or referenced externally via the Darknet API.
Moving forward starting with Darknet V3 (August 2024), where possible the emphasis will be to use OpenCV cv::Mat
objects in the external-facing API instead of DarknetImage. Internally, Darknet will continue to use Image
.
C
API, which is why it exists this way and not as a C++ class with methods.Within data
, the image is stored as 3 non-interlaced channels in RGB order. Each channel is stored as rows, from top to bottom. So a 5x3 RGB image would look like this:
A 5x3 pure red image, with a blueish/green square in the bottom-right corner would look like this:
For additional information or to help debug the internals of DarknetImage
, see Darknet::image_as_debug_string().
typedef void* DarknetNetworkPtr |
An opaque pointer to a Darknet::Network object, without needing to expose the internals of the network structure.
typedef struct DarknetDetection detection |
Everything Darknet knows about a specific detection.
typedef struct DarknetImage image |
Darknet-style image (vector of floats).
enum NMS_KIND |
Enumerator | |
---|---|
DEFAULT_NMS | |
GREEDY_NMS | |
DIOU_NMS | |
CORNERS_NMS |
void calculate_binary_weights | ( | DarknetNetworkPtr | ptr | ) |
This is part of the original C
API.
Do not use in new code.
If you were previously using calculate_binary_weights()
from within C
code, it used to pass the network by value. Starting with Darknet V3 in 2024-08-16, the network is now passed in as a pointer.
void copy_image_from_bytes | ( | DarknetImage | im, |
char * | pdata | ||
) |
This is part of the original C
API. Convert from data pointer to a Darknet image. Used by the Python API.
void cuda_set_device | ( | int | n | ) |
This is part of the original C
API. This function does nothing when Darknet was built to run on the CPU.
void darknet_add_skipped_class | ( | DarknetNetworkPtr | ptr, |
const int | class_to_skip | ||
) |
void darknet_clear_skipped_classes | ( | DarknetNetworkPtr | ptr | ) |
This is the C
equivalent to Darknet::clear_skipped_classes().
void darknet_del_skipped_class | ( | DarknetNetworkPtr | ptr, |
const int | class_to_include | ||
) |
This is the C
equivalent to Darknet::del_skipped_classes().
void darknet_fix_out_of_bound_values | ( | DarknetNetworkPtr | ptr, |
const bool | toggle | ||
) |
This is the C
equivalent to Darknet::fix_out_of_bound_values().
void darknet_free_neural_network | ( | DarknetNetworkPtr * | ptr | ) |
This is the C
equivalent to Darknet::free_neural_network().
DarknetNetworkPtr darknet_load_neural_network | ( | const char *const | cfg_filename, |
const char *const | names_filename, | ||
const char *const | weights_filename | ||
) |
This is the C
equivalent to Darknet::load_neural_network().
void darknet_network_dimensions | ( | DarknetNetworkPtr | ptr, |
int * | w, | ||
int * | h, | ||
int * | c | ||
) |
This is the C
equivalent to Darknet::network_dimensions().
void darknet_set_detection_threshold | ( | DarknetNetworkPtr | ptr, |
float | threshold | ||
) |
This is the C
equivalent to Darknet::set_detection_threshold().
void darknet_set_gpu_index | ( | int | idx | ) |
void darknet_set_non_maximal_suppression_threshold | ( | DarknetNetworkPtr | ptr, |
float | threshold | ||
) |
This is the C
equivalent to Darknet::set_non_maximal_suppression_threshold().
void darknet_set_trace | ( | const bool | flag | ) |
void darknet_set_verbose | ( | const bool | flag | ) |
void darknet_show_version_info | ( | ) |
const char * darknet_version_short | ( | ) |
Return the short version string, such as "3.0.163"
.
const char * darknet_version_string | ( | ) |
Return the full version string, such as "v3.0-163-g56145bf"
.
void diounms_sort | ( | detection * | dets, |
int | total, | ||
int | classes, | ||
float | thresh, | ||
NMS_KIND | nms_kind, | ||
float | beta1 | ||
) |
This is part of the original C
API. Non Maxima Suppression.
void do_nms_obj | ( | detection * | dets, |
int | total, | ||
int | classes, | ||
float | thresh | ||
) |
This is part of the original C
API. Non Maxima Suppression.
void do_nms_sort | ( | detection * | dets, |
int | total, | ||
int | classes, | ||
float | thresh | ||
) |
This is part of the original C
API. Non Maxima Suppression.
void free_detections | ( | detection * | dets, |
int | n | ||
) |
This is part of the original C
API. Do not use in new code.
void free_image | ( | image | im | ) |
This is part of the original C
API.
Free the data pointer that stores the image . All image objects must eventually call either this function or Darknet::free_image() to prevent memory leaks.
void free_network_ptr | ( | DarknetNetworkPtr | ptr | ) |
This is part of the original C
API.
Do not use in new code.
If you were previously using free_network() from within C
code, please use free_network_ptr()
instead by passing in the address of the network structure (pointer to the network).
void free_ptrs | ( | void ** | ptrs, |
int | n | ||
) |
This is part of the original C
API.
detection * get_network_boxes | ( | DarknetNetworkPtr | ptr, |
int | w, | ||
int | h, | ||
float | thresh, | ||
float | hier, | ||
int * | map, | ||
int | relative, | ||
int * | num, | ||
int | letter | ||
) |
This is part of the original C
API.
Do not use in new code.
You must call free_detections() to free up memory once done with the detections.
DarknetImage load_image_v2 | ( | const char * | filename, |
int | desired_width, | ||
int | desired_height, | ||
int | channels | ||
) |
This is part of the original C
API. This function exists for the Python API.
DarknetNetworkPtr load_network | ( | const char * | cfg, |
const char * | weights, | ||
int | clear | ||
) |
This is part of the original C
API. Do not use in new code.
DarknetNetworkPtr load_network_custom | ( | const char * | cfg, |
const char * | weights, | ||
int | clear, | ||
int | batch | ||
) |
DarknetImage make_empty_image | ( | int | w, |
int | h, | ||
int | c | ||
) |
This is part of the original C
API.
Make an empty image with the given dimensions. The data pointer will be nullptr
.
DarknetImage make_image | ( | int | w, |
int | h, | ||
int | c | ||
) |
This is part of the original C
API.
Similar to make_empty_image() but the data pointer is fully allocated.
detection * make_network_boxes | ( | DarknetNetworkPtr | ptr, |
float | thresh, | ||
int * | num | ||
) |
This is part of the original C
API.
float * network_predict_image | ( | DarknetNetworkPtr | ptr, |
const DarknetImage | im | ||
) |
This is part of the original C
API.
Do not use in new code.
float * network_predict_image_letterbox | ( | DarknetNetworkPtr | ptr, |
DarknetImage | im | ||
) |
This is part of the original C
API.
float * network_predict_ptr | ( | DarknetNetworkPtr | ptr, |
float * | input | ||
) |
This is part of the original C
API.
Do not use in new code.
If you were previously using network_predict() from within C
code, please use network_predict_ptr()
instead by passing in the address of the network structure (pointer to the network).
void reset_rnn | ( | DarknetNetworkPtr | ptr | ) |
This is part of the original C
API.