Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpCannyEdgeDetection Class Reference

#include <visp3/core/vpCannyEdgeDetection.h>

Public Member Functions

Detection methods
vpImage< unsigned char > detect (const vpImage< vpRGBa > &I_color)
 
vpImage< unsigned char > detect (const vpImage< unsigned char > &I)
 
Setters
void setGradients (const vpImage< float > &dIx, const vpImage< float > &dIy)
 
void setCannyThresholds (const float &lowerThresh, const float &upperThresh)
 
void setGaussianFilterParameters (const int &kernelSize, const float &stdev)
 

Constructors and initialization

 vpCannyEdgeDetection ()
 
 vpCannyEdgeDetection (const int &gaussianKernelSize, const float &gaussianStdev, const float &lowerThreshold=-1., const float &upperThreshold=-1.)
 
 vpCannyEdgeDetection (const std::string &jsonPath)
 
void initFromJSON (const std::string &jsonPath)
 
void from_json (const json &j, vpCannyEdgeDetection &detector)
 
void to_json (json &j, const vpCannyEdgeDetection &detector)
 

Detailed Description

json namespace shortcut

Definition at line 49 of file vpCannyEdgeDetection.h.

Constructor & Destructor Documentation

◆ vpCannyEdgeDetection() [1/3]

vpCannyEdgeDetection::vpCannyEdgeDetection ( )

Default constructor of the vpCannyEdgeDetection class. The thresholds used during the hysteresis thresholding step are set to be automatically computed.

Definition at line 39 of file vpCannyEdgeDetection.cpp.

◆ vpCannyEdgeDetection() [2/3]

vpCannyEdgeDetection::vpCannyEdgeDetection ( const int &  gaussianKernelSize,
const float &  gaussianStdev,
const float &  lowerThreshold = -1.,
const float &  upperThreshold = -1. 
)

Construct a new vpCannyEdgeDetection object.

Parameters
[in]gaussianKernelSize: The size of the Gaussian filter kernel. Must be odd.
[in]gaussianStdev: The standard deviation of the Gaussian filter.
[in]lowerThreshold: The lower threshold of the hysteresis thresholding step. If negative, will be computed from the upper threshold.
[in]upperThreshold: The upper threshold of the hysteresis thresholding step. If negative, will be computed from the median of the gray values of the image.

Definition at line 49 of file vpCannyEdgeDetection.cpp.

◆ vpCannyEdgeDetection() [3/3]

vpCannyEdgeDetection::vpCannyEdgeDetection ( const std::string &  jsonPath)

Construct a new vpCannyEdgeDetection object.

Parameters
[in]jsonPath: The path towards the JSON file to use to initialize the vpCannyEdgeDetection object.

Definition at line 61 of file vpCannyEdgeDetection.cpp.

References initFromJSON().

Member Function Documentation

◆ detect() [1/2]

vpImage< unsigned char > vpCannyEdgeDetection::detect ( const vpImage< unsigned char > &  I)

Detect the edges in a gray-scale image.

Parameters
[in]I: A gray-scale image, in ViSP format.
Returns
vpImage<unsigned char> 255 means an edge, 0 means not an edge.

Definition at line 124 of file vpCannyEdgeDetection.cpp.

References vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

◆ detect() [2/2]

vpImage< unsigned char > vpCannyEdgeDetection::detect ( const vpImage< vpRGBa > &  I_color)

Detect the edges in an image. Convert the color image into a gray-scale image.

Parameters
[in]I_color: An RGB image, in ViSP format.
Returns
vpImage<unsigned char> 255 means an edge, 0 means not an edge.

Definition at line 116 of file vpCannyEdgeDetection.cpp.

References vpImageConvert::convert().

Referenced by vpImageFilter::canny().

◆ initFromJSON()

void vpCannyEdgeDetection::initFromJSON ( const std::string &  jsonPath)

Initialize all the algorithm parameters using the JSON file whose path is jsonPath. Throw a vpException error if the file does not exist.

Parameters
[in]jsonPath: The path towards the JSON configuration file.

Definition at line 67 of file vpCannyEdgeDetection.cpp.

References vpException::ioError.

Referenced by vpCannyEdgeDetection().

◆ setCannyThresholds()

void vpCannyEdgeDetection::setCannyThresholds ( const float &  lowerThresh,
const float &  upperThresh 
)
inline

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
[in]lowerThresh: 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.
[in]upperThresh: The upper threshold: each point whose gradient is greater than this threshold is said to be a strong edge point and is kept.

Definition at line 267 of file vpCannyEdgeDetection.h.

◆ setGaussianFilterParameters()

void vpCannyEdgeDetection::setGaussianFilterParameters ( const int &  kernelSize,
const float &  stdev 
)
inline

Set the Gaussian Filters kernel size and standard deviation and initialize the aforementioned filters.

Parameters
[in]kernelSize: The size of the Gaussian filters kernel.
[in]stdev: The standard deviation of the Gaussian filters used to blur and compute the gradient of the image.

Definition at line 281 of file vpCannyEdgeDetection.h.

◆ setGradients()

void vpCannyEdgeDetection::setGradients ( const vpImage< float > &  dIx,
const vpImage< float > &  dIy 
)
inline

Set the Gradients of the image that will be processed.

Parameters
[in]dIx: Gradient along the horizontal axis of the image.
[in]dIy: Gradient along the vertical axis of the image.

Definition at line 249 of file vpCannyEdgeDetection.h.

Friends And Related Function Documentation

◆ from_json

void from_json ( const json &  j,
vpCannyEdgeDetection detector 
)
friend

Read the detector configuration from JSON. All values are optional and if an argument is not present, the default value defined in the constructor is kept.

Parameters
j: The JSON object, resulting from the parsing of a JSON file.
detector: The detector that will be initialized from the JSON data.

Definition at line 185 of file vpCannyEdgeDetection.h.

◆ to_json

void to_json ( json &  j,
const vpCannyEdgeDetection detector 
)
friend

Parse a vpCannyEdgeDetection object into JSON format.

Parameters
j: A JSON parser object.
detector: The vpCannyEdgeDetection object that must be parsed into JSON format.

Definition at line 199 of file vpCannyEdgeDetection.h.