Darknet/YOLO v5.0-10-g6abf042
Object Detection Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Loading...
Searching...
No Matches
darknet.hpp File Reference

Include this file to get access to the new Darknet V3 C++ API. More...

Include dependency graph for darknet.hpp:
This graph shows which files directly or indirectly include this file:

Classes

struct  Darknet::Parm
 Structure returned by Darknet::parse_arguments(). More...
 
struct  Darknet::Prediction
 A much-simplified version of the old API structure DarknetDetection. More...
 

Namespaces

namespace  Darknet
 The namespace for the C++ Darknet API.
 

Typedefs

using Darknet::Parms = std::vector< Parm >
 Structure returned by Darknet::parse_arguments().
 
using Darknet::Predictions = std::vector< Prediction >
 Each image or video frame may contain many predictions.
 
using Darknet::Probabilities = std::map< int, float >
 The likelyhood of a specific object class having been predicted.
 
using Darknet::Box = DarknetBox
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::Detection = DarknetDetection
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::Image = DarknetImage
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::MMats = std::map< int, cv::Mat >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::MStr = std::map< std::string, std::string >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::MStrInt = std::map< std::string, int >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::NetworkPtr = DarknetNetworkPtr
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::SInt = std::set< int >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::SStr = std::set< std::string >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::VFloat = std::vector< float >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::VInt = std::vector< int >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::VScalars = std::vector< cv::Scalar >
 Convenient simple types used in the Darknet/YOLO C++ API.
 
using Darknet::VStr = std::vector< std::string >
 Convenient simple types used in the Darknet/YOLO C++ API.
 

Enumerations

enum class  Darknet::EParmType {
  Darknet::kUnknown ,
  Darknet::kCfgFilename ,
  Darknet::kNamesFilename ,
  Darknet::kWeightsFilename ,
  Darknet::kDirectory ,
  Darknet::kFilename ,
  Darknet::kOther
}
 When parsing command-line parameters, each parameter is assigned a "type". More...
 

Functions

SInt Darknet::add_skipped_class (Darknet::NetworkPtr ptr, const int class_to_skip)
 Add the given class index to the set of classes that Darknet must ignore.
 
cv::Mat Darknet::annotate (const Darknet::NetworkPtr ptr, const Predictions &predictions, cv::Mat mat)
 Annotate the given image using the predictions from Darknet::predict().
 
SInt Darknet::clear_skipped_classes (Darknet::NetworkPtr ptr)
 Clear the set of classes which Darknet must ignore.
 
MMats Darknet::create_yolo_heatmaps (Darknet::NetworkPtr ptr, const float threshold=0.1f)
 Create several CV_32FC1 (array of 32-bit floats, single channel) cv::Mat objects representing heatmaps obtained from the internals of the YOLO layers in the network.
 
SInt Darknet::del_skipped_class (Darknet::NetworkPtr ptr, const int class_to_include)
 Remove the given class index from the set of classes that Darknet must ignore.
 
bool Darknet::find_neural_network_files (Darknet::Parms &parms)
 Given some hints in the parsed parameters, this function attempts to find the neural network files and converts the necessary parameter(s) to filenames.
 
void Darknet::fix_out_of_bound_values (Darknet::NetworkPtr ptr, const bool toggle)
 Fix out-of-bound values returned by Darknet::predict() for objects near the edges of images.
 
std::string Darknet::format_duration_string (std::chrono::high_resolution_clock::duration duration, const int decimals=3)
 Format the C++ duration as an easy-to-read text string, such as "3.432 milliseconds" or "4.250 hours".
 
void Darknet::free_neural_network (Darknet::NetworkPtr &ptr)
 Free the neural network pointer allocated in Darknet::load_neural_network().
 
const Darknet::VScalarsDarknet::get_class_colours (const Darknet::NetworkPtr ptr)
 Get access to the vector of colours assigned to each class when the .names file was loaded.
 
const Darknet::VStrDarknet::get_class_names (const Darknet::NetworkPtr ptr)
 Get access to the vector of names read from the .names file when the configuration was loaded.
 
std::filesystem::path Darknet::get_config_filename (const Darknet::NetworkPtr ptr)
 Get the filename of the configuration file that was used to load this neural network.
 
std::filesystem::path Darknet::get_config_filename (const Parms &parms)
 Get the filename of the configuration file from the provided parameters.
 
std::filesystem::path Darknet::get_names_filename (const Darknet::NetworkPtr ptr)
 Get the filename of the names file that was used to load this neural network.
 
std::filesystem::path Darknet::get_names_filename (const Parms &parms)
 Get the filename of the names file from the provided parameters.
 
std::filesystem::path Darknet::get_weights_filename (const Darknet::NetworkPtr ptr)
 Get the filename of the weights file that was used to load this neural network.
 
std::filesystem::path Darknet::get_weights_filename (const Parms &parms)
 Get the filename of the weights file from the provided parameters.
 
float Darknet::iou (const cv::Rect &lhs, const cv::Rect &rhs)
 Calculate intersection-over-union given 2 OpenCV rectangles.
 
float Darknet::iou (const cv::Rect2f &lhs, const cv::Rect2f &rhs)
 Calculate intersection-over-union given 2 OpenCV rectangles.
 
Darknet::NetworkPtr Darknet::load_neural_network (const std::filesystem::path &cfg_filename, const std::filesystem::path &names_filename, const std::filesystem::path &weights_filename)
 Load a neural network (.cfg) and the corresponding weights file.
 
Darknet::NetworkPtr Darknet::load_neural_network (Darknet::Parms &parms)
 Load a neural network.
 
void Darknet::network_dimensions (Darknet::NetworkPtr &ptr, int &w, int &h, int &c)
 Get the network dimensions (width, height, channels).
 
std::ostream & Darknet::operator<< (std::ostream &os, const Darknet::EParmType &type)
 Mostly for debug purposes. Convert type to text.
 
std::ostream & Darknet::operator<< (std::ostream &os, const Darknet::Prediction &pred)
 Display some information about this specific prediction.
 
std::ostream & Darknet::operator<< (std::ostream &os, const Darknet::Predictions &preds)
 Display some information about all the predictions.
 
Darknet::Parms Darknet::parse_arguments (const Darknet::VStr &v)
 Similar to the other Darknet::parse_arguments(), but uses a vector of strings as input.
 
Darknet::Parms Darknet::parse_arguments (int argc, char *argv[])
 Parse common Darknet command-line parameters with the values from argc and argv in main().
 
Predictions Darknet::predict (const Darknet::NetworkPtr ptr, const cv::Mat &mat)
 Get Darknet to look at the given image or video frame and return all predictions.
 
Predictions Darknet::predict (const Darknet::NetworkPtr ptr, const std::filesystem::path &image_filename)
 Get Darknet to look at the given image and return all predictions.
 
Predictions Darknet::predict (const Darknet::NetworkPtr ptr, Darknet::Image &img, cv::Size original_image_size=cv::Size(0, 0))
 Get Darknet to look at the given image or video frame and return all predictions.
 
Predictions Darknet::predict_and_annotate (const Darknet::NetworkPtr ptr, cv::Mat mat)
 Combination of Darknet::predict() and Darknet::annotate().
 
cv::Mat Darknet::resize_keeping_aspect_ratio (cv::Mat &mat, cv::Size desired_size, const cv::InterpolationFlags method=cv::InterpolationFlags::INTER_NEAREST)
 Resize the image as close as we can to the given size, but keep the aspect ratio the same as the original image.
 
void Darknet::set_annotation_draw_bb (Darknet::NetworkPtr ptr, const bool toggle)
 Determines if bounding boxes are drawn when calling either Darknet::annotate() or Darknet::predict_and_annotate().
 
void Darknet::set_annotation_draw_label (Darknet::NetworkPtr ptr, const bool toggle)
 Determines if text labels are drawn above the bounding boxes when calling either Darknet::annotate() or Darknet::predict_and_annotate().
 
void Darknet::set_annotation_font (Darknet::NetworkPtr ptr, const cv::LineTypes line_type, const cv::HersheyFonts font_face, const int font_thickness, const double font_scale)
 Set the font characteristics to use when drawing the bounding boxes and labels in either Darknet::annotate() or Darknet::predict_and_annotate().
 
void Darknet::set_annotation_line_type (Darknet::NetworkPtr ptr, const cv::LineTypes line_type)
 The OpenCV line type can impact performance.
 
const Darknet::VScalarsDarknet::set_class_colours (Darknet::NetworkPtr ptr, const Darknet::VScalars &colours)
 Set the colours to use when drawing annotations.
 
Darknet::ParmsDarknet::set_default_neural_network (Darknet::Parms &parms, const std::string &hint1, const std::string &hint2="", const std::string &hint3="")
 If no neural network has been set in the parameters, this can be used to provide hints as to which files need to be loaded.
 
void Darknet::set_detection_threshold (Darknet::NetworkPtr ptr, float threshold)
 Detection threshold to use when Darknet::predict() is called.
 
void Darknet::set_gpu_index (int idx)
 Set the GPU index to use.
 
void Darknet::set_non_maximal_suppression_threshold (Darknet::NetworkPtr ptr, float threshold)
 Non-maximal suppression threshold to use when Darknet::predict() is called.
 
std::ostream * Darknet::set_output_stream (const std::filesystem::path &filename)
 Set the file where the output logging will take place.
 
void Darknet::set_rounded_corner_bounding_boxes (Darknet::NetworkPtr ptr, const bool toggle, const float roundness)
 This determines if annotations are drawn as circles or rounded rectangles in either Darknet::annotate() or Darknet::predict_and_annotate().
 
void Darknet::set_trace (const bool flag)
 Set the Darknet::CfgAndState::is_trace flag.
 
void Darknet::set_verbose (const bool flag)
 Set the Darknet::CfgAndState::is_verbose flag.
 
void Darknet::show_version_info ()
 Display a few lines of text with some version information, including CUDA and ROCm when used.
 
SInt Darknet::skipped_classes (const Darknet::NetworkPtr ptr)
 Return the set of classes which Darknet must ignore.
 
SInt Darknet::skipped_classes (Darknet::NetworkPtr ptr, const SInt &classes_to_skip)
 Set the classes which Darknet must ignore, completely over-writing all previous values.
 
cv::Mat Darknet::visualize_heatmap (const cv::Mat &heatmap, const cv::ColormapTypes colourmap=cv::ColormapTypes::COLORMAP_JET)
 Convert a heatmap created with Darknet::create_yolo_heatmaps() to an easy-to-view image.
 
std::string Darknet::trim (const std::string &str)
 
std::string & Darknet::trim (std::string &str)
 
std::string Darknet::lowercase (const std::string &str)
 
std::string & Darknet::lowercase (std::string &str)
 

Detailed Description

Include this file to get access to the new Darknet V3 C++ API.

https://darknetcv.ai/api/api.html