DarkHelp  v1.7.11-3
C++ API for the neural network framework Darknet
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
DarkHelp::PredictionResult Struct Referencefinal

Structure used to store interesting information on predictions. More...

#include "DarkHelpPredictionResult.hpp"

Collaboration diagram for DarkHelp::PredictionResult:

Public Member Functions

 PredictionResult ()
 Constructor. More...
 
PredictionResultclear ()
 Erase all the information in this prediction object. More...
 
bool empty () const
 Returns true if this prediction hasn't yet been initialized, or if clear() has been called. More...
 

Public Attributes

MClassProbabilities all_probabilities
 This is only useful if you have multiple classes, and an object may be one of several possible classes. More...
 
int best_class
 The class that obtained the highest probability. More...
 
float best_probability
 The probability of the class that obtained the highest value. More...
 
std::string name
 A name to use for the object. More...
 
size_t object_id
 If object tracking is in use, then the unique object ID will be stored here by the tracker. More...
 
cv::Point2f original_point
 The original normalized X and Y coordinate returned by darknet. More...
 
cv::Size2f original_size
 The original normalized width and height returned by darknet. More...
 
cv::Rect rect
 OpenCV rectangle which describes where the object is located in the original image. More...
 
int tile
 The tile number on which this object was found. More...
 

Detailed Description

Structure used to store interesting information on predictions.

A vector of these is created and returned to the caller every time DarkHelp::NN::predict() is called. The most recent predictions are also stored in DarkHelp::NN::prediction_results.

Constructor & Destructor Documentation

◆ PredictionResult()

DarkHelp::PredictionResult::PredictionResult ( )
inline

Constructor.

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

PredictionResult& DarkHelp::PredictionResult::clear ( )
inline

Erase all the information in this prediction object.

References all_probabilities, best_class, best_probability, name, object_id, original_point, original_size, rect, and tile.

Referenced by PredictionResult().

Here is the caller graph for this function:

◆ empty()

bool DarkHelp::PredictionResult::empty ( ) const
inline

Returns true if this prediction hasn't yet been initialized, or if clear() has been called.

References all_probabilities, original_size, and rect.

Member Data Documentation

◆ all_probabilities

MClassProbabilities DarkHelp::PredictionResult::all_probabilities

This is only useful if you have multiple classes, and an object may be one of several possible classes.

Note
This will contain all non-zero class/probability pairs.

For example, if your classes in your names file are defined like this:

car
person
truck
bus

Then an image of a truck may be 10.5% car, 0% person, 95.8% truck, and 60.3% bus. Only the non-zero values are ever stored in this map, which for this example would be the following:

  • 0 -> 0.105 // car
  • 2 -> 0.958 // truck
  • 3 -> 0.603 // bus

The C++ map would contains the following values:

all_probabilities = { {0, 0.105}, {2, 0.958}, {3, 0.603} };
MClassProbabilities all_probabilities
This is only useful if you have multiple classes, and an object may be one of several possible classe...
Definition: DarkHelpPredictionResult.hpp:137

(Note how person is not stored in the map, since the probability for that class is 0%.)

In addition to all_probabilities, the best results will also be duplicated in DarkHelp::PredictionResult::best_class and DarkHelp::PredictionResult::best_probability, which in this example would contain the values representing the truck:

Referenced by clear(), empty(), DarkHelp::NN::name_prediction(), DarkHelp::operator<<(), DarkHelp::NN::predict_internal_darknet(), and DarkHelp::yolo_load_annotations().

◆ best_class

int DarkHelp::PredictionResult::best_class

The class that obtained the highest probability.

For example, if an object is predicted to be 80% car or 60% truck, then the class id of the car would be stored in this variable.

See also
DarkHelp::PredictionResult::best_probability
DarkHelp::PredictionResult::all_probabilities

Referenced by clear(), DarkHelp::NN::name_prediction(), DarkHelp::operator<<(), DarkHelp::NN::predict_internal_darknet(), and DarkHelp::yolo_load_annotations().

◆ best_probability

float DarkHelp::PredictionResult::best_probability

The probability of the class that obtained the highest value.

For example, if an object is predicted to be 80% car or 60% truck, then the value of 0.80 would be stored in this variable.

See also
DarkHelp::PredictionResult::best_class
DarkHelp::PredictionResult::all_probabilities

Referenced by clear(), DarkHelp::NN::name_prediction(), DarkHelp::operator<<(), DarkHelp::NN::predict_internal_darknet(), and DarkHelp::yolo_load_annotations().

◆ name

std::string DarkHelp::PredictionResult::name

A name to use for the object.

If an object has multiple probabilities, then the one with the highest probability will be listed first. For example, a name could be "car 80%, truck 60%". The name is used as a label when calling DarkHelp::NN::annotate().

See also
DarkHelp::Config::names_include_percentage

Referenced by clear(), DarkHelp::NN::name_prediction(), DarkHelp::operator<<(), and DarkHelp::yolo_load_annotations().

◆ object_id

size_t DarkHelp::PredictionResult::object_id

If object tracking is in use, then the unique object ID will be stored here by the tracker.

Otherwise, this field will be zero. Object tracking is not active by default.

See also
DarkHelp::PositionTracker
Since
May 2023

Referenced by clear(), and DarkHelp::operator<<().

◆ original_point

cv::Point2f DarkHelp::PredictionResult::original_point

The original normalized X and Y coordinate returned by darknet.

This is the normalized mid-point, not the corner. If in doubt, you probably want to use rect.x and rect.y instead of this value.

Given this example annotated 230x134 image:

The original_point returned would be:

  • original_point.x = 0.652174 (mid x / image width, or 150 / 230)
  • original_point.y = 0.608209 (mid y / image height, or 81.5 / 134)
See also
DarkHelp::PredictionResult::rect
DarkHelp::PredictionResult::original_size

Referenced by clear(), DarkHelp::NN::predict_internal_darknet(), DarkHelp::NN::snap_annotation(), and DarkHelp::yolo_load_annotations().

◆ original_size

cv::Size2f DarkHelp::PredictionResult::original_size

The original normalized width and height returned by darknet.

If in doubt, you probably want to use rect.width and rect.height instead of this value.

Given this example annotated 230x134 image:

The original_size returned would be:

  • original_size.width = 0.469565 (rect width / image width, or 108 / 230)
  • original_size.height = 0.649254 (rect height / image height, or 87 / 134)
See also
DarkHelp::PredictionResult::rect
DarkHelp::PredictionResult::original_point

Referenced by clear(), empty(), DarkHelp::NN::predict_internal_darknet(), DarkHelp::NN::snap_annotation(), and DarkHelp::yolo_load_annotations().

◆ rect

cv::Rect DarkHelp::PredictionResult::rect

OpenCV rectangle which describes where the object is located in the original image.

Given this example annotated 230x134 image:

The red rectangle returned would be:

  • rect.x = 96 (top left)
  • rect.y = 38 (top left)
  • rect.width = 108
  • rect.height = 87
See also
DarkHelp::PredictionResult::original_point
DarkHelp::PredictionResult::original_size

Referenced by clear(), empty(), DarkHelp::operator<<(), DarkHelp::NN::predict_internal_darknet(), DarkHelp::NN::snap_annotation(), and DarkHelp::yolo_load_annotations().

◆ tile

int DarkHelp::PredictionResult::tile

The tile number on which this object was found.

This is mostly for debug purposes and only if tiling has been enabled (see DarkHelp::Config::enable_tiles), otherwise the value will always be zero.

Referenced by clear(), DarkHelp::operator<<(), DarkHelp::NN::predict_internal_darknet(), DarkHelp::NN::predict_internal_opencv(), and DarkHelp::yolo_load_annotations().


The documentation for this struct was generated from the following file: