SDK ML Utils

class Metavision::HOGDescriptor

Class wrapping the OpenCV HogDescriptor module. It implements a border coping mechanism as well.

Public Functions

HOGDescriptor(const cv::Size &windowSize, const cv::Size &blocksize, const cv::Size &blockstride, const cv::Size &cellsize, int nbins)

Construct an HOGDescriptor object.

Parameters
  • windowSize: Size of the area to compute the HOG on.

  • blocksize: Size of the individual block to compute the HOG (corresponds to squares, e.g. a value of 16 uses 16x16 squares).

  • blockstride: Space between two consecutive blocks. Using this parameter as less as the blocksize one could compute on overlapping blocks for instance.

  • cellsize: Size of the cells to compute gradient on. Must be less than blocksize.

  • nbins: Number of orientations chosen to discretize the HOG.

void compute_description(const cv::Mat &img_to_describe, const cv::Rect &roi, std::vector<float> &descriptor)

Computes a Histogram Of Gradient (HOG)

Parameters
  • [in] img_to_describe: Image representing the scene

  • [in] roi: Region Of Interest where the object is

  • [out] descriptor: Description of the object

struct Metavision::ProducerConsumerSynchronization

Synchronizes one producer with a consumer.

The producer checks if the consumer is ready (previous work is finished), it prepares the data for the consumer, and signals the consumer.

On its side, the consumer waits for data to be computed and applies a function as soon as the data is ready

Public Functions

ProducerConsumerSynchronization()

Creates a ProducerConsumerSynchronization object.

void data_is_ready()

Sets data available for the consumer.

Warning

This function should be called by the producer only

void producer_wait(std::atomic<bool> &done)

Waits for the consumer to be ready (should be called only by the producer)

Parameters
  • done: Boolean to release the condition. If done become True, the producer exits the function

template<typename L>
void consumer_wait(std::atomic<bool> &done, L &&lambda_function)

Waits for data to be computed.

Parameters
  • done: Boolean to release the condition. If done become True, the producer exits the function

  • lambda_function: Function to be called on data provided by the producer

void notify()

Notifies either producer or consumer to wake it up.

cv::Mat Metavision::RectTools::subwindow(const cv::Mat &in, const cv::Rect &window, int borderType = cv::BORDER_CONSTANT)

Extracts a copy of the subimage and adds border if parts of the subimage are missing.

Return

A copy of the subimage with its borders if required

Parameters
  • in: Input image from which the subimage is extracted

  • window: Description of the subimage bounds

  • borderType: Method to generate the borders

template<typename T1, typename T2>
float Metavision::Utils::intersection(const T1 &box1, const T2 &box2)

Computes intersection area of two boxes.

Return

proportion of intersection area

Parameters
  • box1: Description of a 2D box

  • box2: Description of a 2D box

template<typename T1, typename T2>
float Metavision::Utils::intersection_over_union(const T1 &box1, const T2 &box2)

Computes the ratio between intersection area and union area.

Return

Proportion of intersection area

Parameters
  • box1: Description of a 2D box

  • box2: Description of a 2D box

template<typename T1, typename T2>
float Metavision::Utils::compute_similarity_iou_using_classid(const T1 &box1, const T2 &box2)

Helper function to compute similarity, taking into account the class.

Return

Proportion of intersection area if class ID are the same, 0 otherwise

Parameters
  • box1: Description of a 2D box

  • box2: Description of a 2D box

template<typename T1, typename T2>
float Metavision::Utils::compute_similarity_iou_using_classid_and_similarity_matrix(const T1 &box1, const T2 &box2, const std::vector<float> &similarity_matrix, unsigned int nb_object_classes)

Helper function to compute similarity, taking into account the class and a similarity matrix

Return

Weighted proportion of intersection area (weights depends on class id)

Parameters
  • box1: Description of a 2D box

  • box2: Description of a 2D box

  • similarity_matrix: (nb_object_classes + 1) x (nb_object_classes + 1) matrix of similarity weights.

  • nb_object_classes: Number of valid object classes. class_id 0 is ‘background’ class and is not counted as a valid object class