DarkHelp  v1.8.6-4
C++ API for the neural network framework Darknet
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
DarkHelp_C_API.cpp File Reference

The C API is a wrapper around some of the most common C++ DarkHelp objects and methods. More...

#include "DarkHelp.hpp"
#include "json.hpp"
#include <darknet_version.h>
Include dependency graph for DarkHelp_C_API.cpp:

Functions

void Annotate (DarkHelpPtr ptr, const char *const output_image_filename)
 Calls DarkHelp::NN::annotate() on the last image and results from either PredictFN() or Predict(). More...
 
DarkHelpPtr CreateDarkHelpNN (const char *const fn1, const char *const fn2, const char *const fn3)
 Create a DarkHelp::NN object. More...
 
const char * DarkHelpVersion ()
 Get the DarkHelp version string, such as "1.6.1-2". More...
 
const char * DarknetVersion ()
 Get the "short" Darknet version string, such as "2.0-78". More...
 
void DestroyDarkHelpNN (DarkHelpPtr ptr)
 Destroy the neural network object previously created with CreateDarkHelpNN(). More...
 
bool EnableAnnotationAutoHideLabels (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::annotation_auto_hide_labels. More...
 
bool EnableAnnotationIncludeDuration (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::annotation_include_duration. More...
 
bool EnableAnnotationIncludeTimestamp (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::annotation_include_timestamp. More...
 
bool EnableAnnotationPixelate (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::annotation_pixelate_enabled. More...
 
bool EnableAnnotationSuppressAllLabels (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::annotation_suppress_all_labels. More...
 
bool EnableCombineTilePredictions (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::combine_tile_predictions. More...
 
bool EnableIncludeAllNames (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::include_all_names. More...
 
bool EnableNamesIncludePercentage (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::names_include_percentage. More...
 
bool EnableOnlyCombineSimilarPredictions (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::only_combine_similar_predictions. More...
 
bool EnableSnapping (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::snapping_enabled. More...
 
bool EnableTiles (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::enable_tiles. More...
 
bool EnableUseFastImageResize (DarkHelpPtr ptr, bool enabled)
 Enable or disable DarkHelp::Config::use_fast_image_resize. More...
 
const char * GetPredictionResults (DarkHelpPtr ptr)
 Get the last detection results from either PredictFN() or Predict(). More...
 
int Predict (DarkHelpPtr ptr, const int width, const int height, uint8_t *image, const int number_of_bytes)
 Calls DarkHelp::NN::predict() with the given image. More...
 
int PredictFN (DarkHelpPtr ptr, const char *const image_filename)
 Calls DarkHelp::NN::predict() with the given image filename. More...
 
double SetAnnotationFontScale (DarkHelpPtr ptr, double scale)
 Set the font scale to use when annotating predictions. More...
 
int SetAnnotationFontThickness (DarkHelpPtr ptr, int thickness)
 Set the font thickness to use when annotating predictions. More...
 
int SetAnnotationLineThickness (DarkHelpPtr ptr, int thickness)
 Set the line thickness to use when annotating predictions. More...
 
int SetAnnotationPixelateSize (DarkHelpPtr ptr, int size)
 Set the pixelation size to use when EnableAnnotationPixelate() has been enabled. More...
 
float SetAnnotationShadePredictions (DarkHelpPtr ptr, float shading)
 Set the amount of shading to use when annotating predictions. More...
 
int SetBinaryThresholdBlockSize (DarkHelpPtr ptr, int blocksize)
 Set the value for DarkHelp::Config::binary_threshold_block_size. More...
 
double SetBinaryThresholdConstant (DarkHelpPtr ptr, double threshold)
 Set the value for DarkHelp::Config::binary_threshold_constant. More...
 
float SetNonMaximalSuppression (DarkHelpPtr ptr, float nms)
 Set the NMS (non maximal suppression) threshold used with Darknet. More...
 
int SetSnappingHorizontalTolerance (DarkHelpPtr ptr, int tolerance)
 Set the value for DarkHelp::Config::snapping_horizontal_tolerance. More...
 
float SetSnappingLimitGrow (DarkHelpPtr ptr, float limit)
 Set the value for DarkHelp::Config::snapping_limit_grow. More...
 
float SetSnappingLimitShrink (DarkHelpPtr ptr, float limit)
 Set the value for DarkHelp::Config::snapping_limit_shrink. More...
 
int SetSnappingVerticalTolerance (DarkHelpPtr ptr, int tolerance)
 Set the value for DarkHelp::Config::snapping_vertical_tolerance. More...
 
float SetThreshold (DarkHelpPtr ptr, float threshold)
 Set the detection threshold used with Darknet and DarkHelp. More...
 
float SetTileEdgeFactor (DarkHelpPtr ptr, float factor)
 Set the value for DarkHelp::Config::tile_edge_factor. More...
 
float SetTileRectFactor (DarkHelpPtr ptr, float factor)
 Set the value for DarkHelp::Config::tile_rect_factor. More...
 
void ToggleOutputRedirection ()
 Calls DarkHelp::toggle_output_redirection() to either hide or show output on STDOUT and STDERR. More...
 

Detailed Description

The C API is a wrapper around some of the most common C++ DarkHelp objects and methods.

If you have the ability to use C++, you should instead be using the objects in DarkHelpNN.hpp and DarkHelpConfig.hpp.

Function Documentation

◆ Annotate()

void Annotate ( DarkHelpPtr  ptr,
const char *const  output_image_filename 
)

Calls DarkHelp::NN::annotate() on the last image and results from either PredictFN() or Predict().

The results will be saved to output_image_filename in either PNG or JPG format depending on the file extension.

Warning
If the output filename already exists it will be overwritten.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::annotate().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateDarkHelpNN()

DarkHelpPtr CreateDarkHelpNN ( const char *const  fn1,
const char *const  fn2,
const char *const  fn3 
)

Create a DarkHelp::NN object.

The order in which the filenames are specified is not important. The files should be the .cfg file, the .names file, and the .weights file.

When done with the neural network, remember to call DestroyDarkHelpNN().

Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

Referenced by main().

Here is the caller graph for this function:

◆ DarkHelpVersion()

const char* DarkHelpVersion ( )

Get the DarkHelp version string, such as "1.6.1-2".

See also
DarkHelp::version()
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::version().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DarknetVersion()

const char* DarknetVersion ( )

Get the "short" Darknet version string, such as "2.0-78".

See also
DarkHelpVersion()
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

Referenced by main().

Here is the caller graph for this function:

◆ DestroyDarkHelpNN()

void DestroyDarkHelpNN ( DarkHelpPtr  ptr)

Destroy the neural network object previously created with CreateDarkHelpNN().

Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

Referenced by main().

Here is the caller graph for this function:

◆ EnableAnnotationAutoHideLabels()

bool EnableAnnotationAutoHideLabels ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::annotation_auto_hide_labels.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_auto_hide_labels, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ EnableAnnotationIncludeDuration()

bool EnableAnnotationIncludeDuration ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::annotation_include_duration.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_include_duration, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ EnableAnnotationIncludeTimestamp()

bool EnableAnnotationIncludeTimestamp ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::annotation_include_timestamp.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_include_timestamp, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ EnableAnnotationPixelate()

bool EnableAnnotationPixelate ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::annotation_pixelate_enabled.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_pixelate_enabled, and DarkHelp::NN::config.

◆ EnableAnnotationSuppressAllLabels()

bool EnableAnnotationSuppressAllLabels ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::annotation_suppress_all_labels.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_suppress_all_labels, and DarkHelp::NN::config.

◆ EnableCombineTilePredictions()

bool EnableCombineTilePredictions ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::combine_tile_predictions.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::combine_tile_predictions, and DarkHelp::NN::config.

◆ EnableIncludeAllNames()

bool EnableIncludeAllNames ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::include_all_names.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::include_all_names.

◆ EnableNamesIncludePercentage()

bool EnableNamesIncludePercentage ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::names_include_percentage.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::names_include_percentage.

Referenced by main().

Here is the caller graph for this function:

◆ EnableOnlyCombineSimilarPredictions()

bool EnableOnlyCombineSimilarPredictions ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::only_combine_similar_predictions.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::only_combine_similar_predictions.

◆ EnableSnapping()

bool EnableSnapping ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::snapping_enabled.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::snapping_enabled.

Referenced by main().

Here is the caller graph for this function:

◆ EnableTiles()

bool EnableTiles ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::enable_tiles.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::enable_tiles.

Referenced by main().

Here is the caller graph for this function:

◆ EnableUseFastImageResize()

bool EnableUseFastImageResize ( DarkHelpPtr  ptr,
bool  enabled 
)

Enable or disable DarkHelp::Config::use_fast_image_resize.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::use_fast_image_resize.

◆ GetPredictionResults()

const char* GetPredictionResults ( DarkHelpPtr  ptr)

Get the last detection results from either PredictFN() or Predict().

The results will be formatted as a JSON string.

Warning
The char* buffer used to return the JSON is static, so don't attempt to use this function call simultaneously from multiple threads, otherwise you risk corrupting the returned text or causing strange undefined behaviour.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::cfg_filename, DarkHelp::NN::config, DarkHelp::Config::driver, DarkHelp::NN::duration_string(), DarkHelp::Config::enable_tiles, DarkHelp::NN::horizontal_tiles, DarkHelp::NN::names, DarkHelp::Config::names_filename, DarkHelp::Config::names_include_percentage, DarkHelp::NN::network_size(), DarkHelp::Config::non_maximal_suppression_threshold, DarkHelp::NN::original_image, DarkHelp::NN::prediction_results, DarkHelp::Config::redirect_darknet_output, DarkHelp::Config::snapping_enabled, DarkHelp::Config::threshold, DarkHelp::NN::tile_size, DarkHelp::NN::vertical_tiles, and DarkHelp::Config::weights_filename.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Predict()

int Predict ( DarkHelpPtr  ptr,
const int  width,
const int  height,
uint8_t *  image,
const int  number_of_bytes 
)

Calls DarkHelp::NN::predict() with the given image.

The image data is presumed to be similar to OpenCV's cv::Mat objects, meaning the bytes need to be in BGR format, not RGB. The number of channels will automatically be determined by dividing the number of bytes by the width and height.

Returns
the number of predictions made.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::predict(), and DarkHelp::NN::prediction_results.

Here is the call graph for this function:

◆ PredictFN()

int PredictFN ( DarkHelpPtr  ptr,
const char *const  image_filename 
)

Calls DarkHelp::NN::predict() with the given image filename.

Returns
the number of predictions made.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::predict(), and DarkHelp::NN::prediction_results.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAnnotationFontScale()

double SetAnnotationFontScale ( DarkHelpPtr  ptr,
double  scale 
)

Set the font scale to use when annotating predictions.

See also
DarkHelp::Config::annotation_font_scale
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_font_scale, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ SetAnnotationFontThickness()

int SetAnnotationFontThickness ( DarkHelpPtr  ptr,
int  thickness 
)

Set the font thickness to use when annotating predictions.

See also
DarkHelp::Config::annotation_font_thickness
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_font_thickness, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ SetAnnotationLineThickness()

int SetAnnotationLineThickness ( DarkHelpPtr  ptr,
int  thickness 
)

Set the line thickness to use when annotating predictions.

See also
DarkHelp::Config::annotation_line_thickness
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_line_thickness, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ SetAnnotationPixelateSize()

int SetAnnotationPixelateSize ( DarkHelpPtr  ptr,
int  size 
)

Set the pixelation size to use when EnableAnnotationPixelate() has been enabled.

See also
DarkHelp::Config::annotation_pixelate_size
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_pixelate_size, and DarkHelp::NN::config.

◆ SetAnnotationShadePredictions()

float SetAnnotationShadePredictions ( DarkHelpPtr  ptr,
float  shading 
)

Set the amount of shading to use when annotating predictions.

See also
DarkHelp::Config::annotation_shade_predictions
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::annotation_shade_predictions, and DarkHelp::NN::config.

Referenced by main().

Here is the caller graph for this function:

◆ SetBinaryThresholdBlockSize()

int SetBinaryThresholdBlockSize ( DarkHelpPtr  ptr,
int  blocksize 
)

Set the value for DarkHelp::Config::binary_threshold_block_size.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::binary_threshold_block_size, and DarkHelp::NN::config.

◆ SetBinaryThresholdConstant()

double SetBinaryThresholdConstant ( DarkHelpPtr  ptr,
double  threshold 
)

Set the value for DarkHelp::Config::binary_threshold_constant.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::Config::binary_threshold_constant, and DarkHelp::NN::config.

◆ SetNonMaximalSuppression()

float SetNonMaximalSuppression ( DarkHelpPtr  ptr,
float  nms 
)

Set the NMS (non maximal suppression) threshold used with Darknet.

See also
DarkHelp::Config::non_maximal_suppression_threshold
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::non_maximal_suppression_threshold.

◆ SetSnappingHorizontalTolerance()

int SetSnappingHorizontalTolerance ( DarkHelpPtr  ptr,
int  tolerance 
)

Set the value for DarkHelp::Config::snapping_horizontal_tolerance.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::snapping_horizontal_tolerance.

◆ SetSnappingLimitGrow()

float SetSnappingLimitGrow ( DarkHelpPtr  ptr,
float  limit 
)

Set the value for DarkHelp::Config::snapping_limit_grow.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::snapping_limit_grow.

◆ SetSnappingLimitShrink()

float SetSnappingLimitShrink ( DarkHelpPtr  ptr,
float  limit 
)

Set the value for DarkHelp::Config::snapping_limit_shrink.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::snapping_limit_shrink.

◆ SetSnappingVerticalTolerance()

int SetSnappingVerticalTolerance ( DarkHelpPtr  ptr,
int  tolerance 
)

Set the value for DarkHelp::Config::snapping_vertical_tolerance.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::snapping_vertical_tolerance.

◆ SetThreshold()

float SetThreshold ( DarkHelpPtr  ptr,
float  threshold 
)

Set the detection threshold used with Darknet and DarkHelp.

See also
DarkHelp::Config::threshold
Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::threshold.

Referenced by main().

Here is the caller graph for this function:

◆ SetTileEdgeFactor()

float SetTileEdgeFactor ( DarkHelpPtr  ptr,
float  factor 
)

Set the value for DarkHelp::Config::tile_edge_factor.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::tile_edge_factor.

◆ SetTileRectFactor()

float SetTileRectFactor ( DarkHelpPtr  ptr,
float  factor 
)

Set the value for DarkHelp::Config::tile_rect_factor.

Returns
the previous value.
Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::NN::config, and DarkHelp::Config::tile_rect_factor.

◆ ToggleOutputRedirection()

void ToggleOutputRedirection ( )

Calls DarkHelp::toggle_output_redirection() to either hide or show output on STDOUT and STDERR.

This can be used to hide the large amount of output generated by Darknet when it first loads a neural network.

Since
December 2023
Note
This is part of the DarkHelp C API, which is a simplified interface to the full DarkHelp C++ API.

References DarkHelp::toggle_output_redirection().

Here is the call graph for this function: