robokudo.utils.comparators

Classes

FeatureComparator

Base class for feature comparators.

TranslationComparator

Extended FeatureComparator that computes similarity based on translation distance between query and object values.

BboxComparator

Extended FeatureComparator that computes similarity based on the bounding box size difference between query and object values.

SizeComparator

Extended FeatureComparator that computes similarity based on the sum difference between query and object values.

ClassnameComparator

Extended FeatureComparator that computes similarity based on the string equality between query and object values.

HistogramComparator

Extended FeatureComparator that computes similarity based on the cv2.HISTCMP_CORREL comparison between query and object values.

SemanticColorComparator

Extended FeatureComparator that computes similarity based on string similarity and color ratio difference between query and object values.

AdditionalDataComparator

Extended FeatureComparator that computes similarity based on numerical difference or simple value comparison between query and object values.

RoiComparator

Extended FeatureComparator that computes similarity based on overlap percentage between query and object values.

Module Contents

class robokudo.utils.comparators.FeatureComparator(weight: float)

Base class for feature comparators.

weight

Weight of this comparator in the final similarity score.

abstract compute_similarity(query_value: typing_extensions.Any, obj_value: typing_extensions.Any) float

Computes similarity between query and object values.

Parameters:
  • query_value – The translation to use as a baseline for comparison.

  • obj_value – The value to compare against query_value.

Returns:

A similarity score between 0.0 (no similarity at all) and 1.0 (completely identical).

class robokudo.utils.comparators.TranslationComparator(weight: float, max_distance: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on translation distance between query and object values.

max_distance

Maximum distance between query and object values for which the similarity is 0.0.

compute_similarity(query_value: typing_extensions.Tuple[float, float, float], obj_value: typing_extensions.Tuple[float, float, float]) float

Computes similarity based on translation distance between query and object values.

Parameters:
  • query_value – The translation to use as a baseline for comparison.

  • obj_value – The translation to compare against query_value.

Returns:

A similarity score between 0.0 (distance equal to or larger than self.max_distance) and 1.0 (completely identical).

class robokudo.utils.comparators.BboxComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on the bounding box size difference between query and object values.

compute_similarity(query_value: robokudo.types.annotation.BoundingBox3DAnnotation, obj_value: robokudo.types.annotation.BoundingBox3DAnnotation) float

Computes similarity between bounding boxes based on their sizes.

Parameters:
  • query_value – The bounding box to use as a baseline for comparison.

  • obj_value – The bounding box to compare against query_value.

Returns:

A similarity score between 0.0 (obj_value is 0% the size of query_value) and 1.0 (identical bounding box sizes).

class robokudo.utils.comparators.SizeComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on the sum difference between query and object values.

compute_similarity(query_value: typing_extensions.List, obj_value: typing_extensions.List) float

Computes similarity of two lists based on their sum differences.

Parameters:
  • query_value – The list to use as a baseline for comparison.

  • obj_value – The list to compare against query_value.

Returns:

A similarity score between 0.0 (sum of obj_value is 100% smaller or larger than sum of query_value) and 1.0 (identical sums).

class robokudo.utils.comparators.ClassnameComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on the string equality between query and object values.

compute_similarity(query_value: robokudo.types.annotation.Classification, obj_value: robokudo.types.annotation.Classification) float

Computes similarity between classnames based on string equality.

Parameters:
  • query_value – The classname to use as a baseline for comparison.

  • obj_value – The classname to compare against query_value.

Returns:

A similarity score between 0.0 (not identical) and 1.0 (identical).

class robokudo.utils.comparators.HistogramComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on the cv2.HISTCMP_CORREL comparison between query and object values.

compute_similarity(query_value: robokudo.types.annotation.ColorHistogram, obj_value: robokudo.types.annotation.ColorHistogram) float

Computes similarity between ColorHistogram objects based on the cv2.HISTCMP_CORREL metric.

Parameters:
  • query_value – The histogram to use as a baseline for comparison.

  • obj_value – The histogram to compare against query_value.

Returns:

A similarity score between 0.0 (completely different) and 1.0 (identical).

class robokudo.utils.comparators.SemanticColorComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on string similarity and color ratio difference between query and object values.

compute_similarity(query_value: robokudo.types.annotation.SemanticColor, obj_value: robokudo.types.annotation.SemanticColor) float

Computes similarity between SemanticColor objects based on the cv2.HISTCMP_CORREL metric.

Parameters:
  • query_value – The semantic color annotation to use as a baseline for comparison.

  • obj_value – The semantic color annotation to compare against query_value.

Returns:

A similarity score between 0.0 (completely different colors or color ratio) and 1.0 (identical color and color ratio).

class robokudo.utils.comparators.AdditionalDataComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on numerical difference or simple value comparison between query and object values.

compute_similarity(query_value: typing_extensions.Any, obj_value: typing_extensions.Any) float

Computes similarity between any value or object based on numerical difference or value equality.

If query_value and obj_value are numerical this FeatureComparator will normalize their numerical difference. Otherwise a simple equality check is performed, 0.0 is returned if they are not equal, 1.0 if they are equal.

Parameters:
  • query_value – The object or value to use as a baseline for comparison.

  • obj_value – The object or value to compare against query_value.

Returns:

A similarity score between 0.0 (no similarity) and 1.0 (identical values).

class robokudo.utils.comparators.RoiComparator(weight: float)

Bases: FeatureComparator

Extended FeatureComparator that computes similarity based on overlap percentage between query and object values.

compute_similarity(query_value: robokudo.types.cv.Rect, obj_value: robokudo.types.cv.Rect) float

Computes the similarity of two Region of Interests by calculating their area overlap and returning it as a percentage.

Parameters:
  • query_value – The rectangle to use as a baseline for comparison.

  • obj_value – The rectangle to compare against query_value.

Returns:

A similarity score between 0.0 (no overlap) and 1.0 (100% overlap).