ovl.detectors.threshold_detector module¶
-
class
ovl.detectors.threshold_detector.
ThresholdDetector
(threshold: ovl.thresholds.threshold.Threshold, morphological_functions)[source]¶ Bases:
ovl.detectors.detector.Detector
ThresholdDetector is a detector used to find contours in a binary image. The binary image is created using a Threshold object. Examples of this are binary threshold, color, multicolor thresholds.
For more information on binary thresholding and color thresholding refer to the documentation of the relevant Threshold object and: Binary Thresholding - https://docs.opencv.org/3.4/d7/d4d/tutorial_py_thresholding.html Color Thresholding - https://docs.opencv.org/master/da/d97/tutorial_threshold_inRange.html
Threshold also allows the usage of morphological functions which are functions that are applied on the binary image created by the threshold.
Note
Morphological functions are functions decorated with @image_filter that act on binary images.
Examples for morphological functions are erosion or dilation.
For more information on morphological functions: https://docs.opencv.org/3.4/d9/d61/tutorial_py_morphological_ops.html
-
apply_morphological_functions
(mask, morphological_functions=None)[source]¶ Applies all morphological functions on the mask (binary images) created using the threshold, Morphological functions are functions that are applied to binary images to alter the shape of “detected” regions
Parameters: - mask – the mask on which the functions should be applied
- morphological_functions – list of morphological_functions to be applied instead of self.morphological_functions
Returns: the applied mask
-
apply_threshold
(image: numpy.ndarray, threshold=None) → numpy.ndarray[source]¶ Gets a mask (binary image) for a given image and Threshold object (uses self.threshold if given threshold was none)
Parameters: - image – the numpy array of the image
- threshold – the Threshold object used to create the binary mask
Returns: the binary mask
-
detect
(image: numpy.ndarray, return_hierarchy=False, *args, **kwargs) → List[numpy.ndarray][source]¶ Gets a list of all the contours within the threshold that was given
Parameters: - image – image from which to get the contours
- return_hierarchy – if the hierarchy should be returned
Returns: list of all contours matching the range of hsv colours
-
find_contours_in_mask
(mask: numpy.ndarray, return_hierarchy=False, apply_morphs=True) → List[numpy.ndarray][source]¶ This function is used to find and extract contours (object shapes) from a binary image (image passed through a threshold)
Parameters: - mask – binary image (mask), a numpy array
- return_hierarchy – if the hierarchy should be returned
- apply_morphs – if the morphological functions should be applied.
Returns: the list of contours
-