CannyEdgeDetection¶
- class CannyEdgeDetection(*args, **kwargs)¶
Bases:
pybind11_object
Class that implements the Canny’s edge detector. It is possible to use a boolean mask to ignore some pixels of the input gray-scale image.
Warning
If the stack size is not sufficient, a SEGFAULT can occur on some images which are really over-exposed.
Note
The maximum stack on MacOS seems to be 65532000 bytes, see https://stackoverflow.com/a/13261334
Overloaded function.
__init__(self: visp._visp.core.CannyEdgeDetection) -> None
Default constructor of the vpCannyEdgeDetection class. The thresholds used during the hysteresis thresholding step are set to be automatically computed.
__init__(self: visp._visp.core.CannyEdgeDetection, gaussianKernelSize: int, gaussianStdev: float, sobelAperture: int, lowerThreshold: float = -1.f, upperThreshold: float = -1.f, lowerThresholdRatio: float = 0.6f, upperThresholdRatio: float = 0.8f, filteringType: visp._visp.core.ImageFilter.CannyFilteringAndGradientType = vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING, storeEdgePoints: bool = false) -> None
Construct a new vpCannyEdgeDetection object that uses Gaussian blur + Sobel operators to compute the edge map.
- Parameters:
- gaussianKernelSize
The size of the Gaussian filter kernel. Must be odd.
- gaussianStdev
The standard deviation of the Gaussian filter.
- sobelAperture
The size of the Sobel filters kernel. Must be odd.
- lowerThreshold
The lower threshold of the hysteresis thresholding step. If negative, will be computed from the upper threshold.
- upperThreshold
The upper threshold of the hysteresis thresholding step. If negative, will be computed from the histogram of the absolute gradient.
- lowerThresholdRatio
If the thresholds must be computed,the lower threshold will be equal to the upper threshold times lowerThresholdRatio .
- upperThresholdRatio
If the thresholds must be computed,the upper threshold will be equal to the value such as the number of pixels of the image times upperThresholdRatio have an absolute gradient lower than the upper threshold.
- filteringType
The filtering and gradient operators to apply to the image before the edge detection operation.
- storeEdgePoints
If true, the list of edge-points will be available using ** vpCannyEdgeDetection::getEdgePointsList() ** .
__init__(self: visp._visp.core.CannyEdgeDetection, jsonPath: str) -> None
Construct a new vpCannyEdgeDetection object.
- Parameters:
- jsonPath
The path towards the JSON file to use to initialize the vpCannyEdgeDetection object.
Methods
Overloaded function.
Overloaded function.
Get the list of edge-points that have been detected.
Get the minimum stack size used by the algorithm.
Initialize all the algorithm parameters using the JSON file whose path is jsonPath .
Set the lower and upper Canny Thresholds used to qualify the edge point candidates.
Set the lower and upper Canny Thresholds ratio that are used to compute them automatically.
Set the Filtering And Gradient operators to apply to the image before the edge detection operation.
Set the Gaussian Filters kernel size and standard deviation and initialize the aforementioned filters.
Set the parameters of the gradient filter (Sobel or Scharr) kernel size filters.
Set the Gradients of the image that will be processed.
Set the minimum stack size, expressed in bytes, due to the recursive algorithm.
If set to true, the list of the detected edge-points will be available calling the method ** vpCannyEdgeDetection::getEdgePointsList() ** .
Inherited Methods
Operators
__doc__
Overloaded function.
__module__
Attributes
__annotations__
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.CannyEdgeDetection) -> None
Default constructor of the vpCannyEdgeDetection class. The thresholds used during the hysteresis thresholding step are set to be automatically computed.
__init__(self: visp._visp.core.CannyEdgeDetection, gaussianKernelSize: int, gaussianStdev: float, sobelAperture: int, lowerThreshold: float = -1.f, upperThreshold: float = -1.f, lowerThresholdRatio: float = 0.6f, upperThresholdRatio: float = 0.8f, filteringType: visp._visp.core.ImageFilter.CannyFilteringAndGradientType = vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING, storeEdgePoints: bool = false) -> None
Construct a new vpCannyEdgeDetection object that uses Gaussian blur + Sobel operators to compute the edge map.
- Parameters:
- gaussianKernelSize
The size of the Gaussian filter kernel. Must be odd.
- gaussianStdev
The standard deviation of the Gaussian filter.
- sobelAperture
The size of the Sobel filters kernel. Must be odd.
- lowerThreshold
The lower threshold of the hysteresis thresholding step. If negative, will be computed from the upper threshold.
- upperThreshold
The upper threshold of the hysteresis thresholding step. If negative, will be computed from the histogram of the absolute gradient.
- lowerThresholdRatio
If the thresholds must be computed,the lower threshold will be equal to the upper threshold times lowerThresholdRatio .
- upperThresholdRatio
If the thresholds must be computed,the upper threshold will be equal to the value such as the number of pixels of the image times upperThresholdRatio have an absolute gradient lower than the upper threshold.
- filteringType
The filtering and gradient operators to apply to the image before the edge detection operation.
- storeEdgePoints
If true, the list of edge-points will be available using ** vpCannyEdgeDetection::getEdgePointsList() ** .
__init__(self: visp._visp.core.CannyEdgeDetection, jsonPath: str) -> None
Construct a new vpCannyEdgeDetection object.
- Parameters:
- jsonPath
The path towards the JSON file to use to initialize the vpCannyEdgeDetection object.
- detect(*args, **kwargs)¶
Overloaded function.
detect(self: visp._visp.core.CannyEdgeDetection, cv_I: cv::Mat) -> visp._visp.core.ImageGray
detect(self: visp._visp.core.CannyEdgeDetection, I_color: visp._visp.core.ImageRGBa) -> visp._visp.core.ImageGray
Detect the edges in an image. Convert the color image into a gray-scale image.
- Parameters:
- I_color
An RGB image, in ViSP format.
- Returns:
vpImage<unsigned char> 255 means an edge, 0 means not an edge.
detect(self: visp._visp.core.CannyEdgeDetection, I: visp._visp.core.ImageGray) -> visp._visp.core.ImageGray
Detect the edges in a gray-scale image.
- Parameters:
- I
A gray-scale image, in ViSP format.
- Returns:
vpImage<unsigned char> 255 means an edge, 0 means not an edge.
- getEdgePointsList(self) list[visp.core.ImagePoint] ¶
Get the list of edge-points that have been detected.
- Returns:
std::vector<vpImagePoint> The edge-points list.
- getMinimumStackSize(self) int ¶
Get the minimum stack size used by the algorithm.
- Returns:
rlim_t The minimum stack size.
- initFromJSON(self, jsonPath: str) None ¶
Initialize all the algorithm parameters using the JSON file whose path is jsonPath . Throw a ** vpException ** error if the file does not exist.
- setCannyThresholds(self, lowerThresh: float, upperThresh: float) None ¶
Set the lower and upper Canny Thresholds used to qualify the edge point candidates. Edge point candidates whose gradient is between these two values is kept only if it linked somehow to a strong edge point.
- Parameters:
- lowerThresh: float¶
The lower threshold: each point whose gradient is below this threshold is discarded. When lower threshold value is negative, Canny recommendation is applied to have the lower threshold 3 times lower than the upper threshold.
- upperThresh: float¶
The upper threshold: each point whose gradient is greater than this threshold is said to be a strong edge point and is kept.
- setCannyThresholdsRatio(self, lowerThreshRatio: float, upperThreshRatio: float) None ¶
Set the lower and upper Canny Thresholds ratio that are used to compute them automatically. To ask to compute automatically the thresholds, you must set the lower and upper thresholds with negative values using the appropriate setter.
Note
See vpCannyEdgeDetection::setCannyThresholds(const float&, const float&)
- Parameters:
- lowerThreshRatio: float¶
The lower threshold ratio: if the thresholds are computed automatically, the lower threshold will be equal to the upper threshold multiplied by lowerThreshRatio .
- upperThreshRatio: float¶
The upper threshold ratio: if the thresholds are computed automatically, the upper threshold will be set such as upperThreshRatio times the number of pixels of the image have their absolute gradient lower then the upper threshold.
- setFilteringAndGradientType(self, type: visp.core.ImageFilter.CannyFilteringAndGradientType) None ¶
Set the Filtering And Gradient operators to apply to the image before the edge detection operation.
- Parameters:
- type: visp.core.ImageFilter.CannyFilteringAndGradientType¶
The operators to apply.
- setGaussianFilterParameters(self, kernelSize: int, stdev: float) None ¶
Set the Gaussian Filters kernel size and standard deviation and initialize the aforementioned filters.
- setGradientFilterAperture(self, apertureSize: int) None ¶
Set the parameters of the gradient filter (Sobel or Scharr) kernel size filters.
- setGradients(self, dIx: visp.core.ImageFloat, dIy: visp.core.ImageFloat) None ¶
Set the Gradients of the image that will be processed.
- Parameters:
- dIx: visp.core.ImageFloat¶
Gradient along the horizontal axis of the image.
- dIy: visp.core.ImageFloat¶
Gradient along the vertical axis of the image.
- setMinimumStackSize(self, requiredStackSize: int) None ¶
Set the minimum stack size, expressed in bytes, due to the recursive algorithm. If not called, the stack size is left at its default value when running the Canny edge detection algorithm.
Note
The stack size is changed back to its original value after before leaving the detect() function.
Note
On Windows, the minimum stack size is defined at compilation time and cannot be changed during runtime.
Note
The maximum stack on MacOS seems to be 65532000 bytes, see https://stackoverflow.com/a/13261334
Warning
If the stack size is not sufficient, a SEGFAULT can occur on some images which are really over-exposed.