31 #ifndef _vpCannyEdgeDetection_h_
32 #define _vpCannyEdgeDetection_h_
39 #include <visp3/core/vpConfig.h>
40 #include <visp3/core/vpImage.h>
41 #include <visp3/core/vpImageFilter.h>
44 #ifdef VISP_HAVE_NLOHMANN_JSON
45 #include <nlohmann/json.hpp>
63 int m_gaussianKernelSize;
64 float m_gaussianStdev;
68 bool m_areGradientAvailable;
69 unsigned int m_gradientFilterKernelSize;
76 std::map<std::pair<unsigned int, unsigned int>,
float> m_edgeCandidateAndGradient;
79 float m_lowerThreshold;
81 float m_lowerThresholdRatio;
83 float m_upperThreshold;
84 float m_upperThresholdRatio;
88 std::map<std::pair<unsigned int, unsigned int>, EdgeType> m_edgePointsCandidates;
98 void initGaussianFilters();
103 void initGradientFilters();
122 void performEdgeThinning(
const float &lowerThreshold);
137 void performHysteresisThresholding(
const float &lowerThreshold,
const float &upperThreshold);
146 bool recursiveSearchForStrongEdge(
const std::pair<unsigned int, unsigned int> &coordinates);
154 void performEdgeTracking();
185 vpCannyEdgeDetection(
const int &gaussianKernelSize,
const float &gaussianStdev,
const unsigned int &sobelAperture,
186 const float &lowerThreshold = -1.f,
const float &upperThreshold = -1.f,
187 const float &lowerThresholdRatio = 0.6f,
const float &upperThresholdRatio = 0.8f,
191 #ifdef VISP_HAVE_NLOHMANN_JSON
206 void initFromJSON(
const std::string &jsonPath);
218 filteringAndGradientName = j.value(
"filteringAndGradientType", filteringAndGradientName);
220 detector.m_gaussianKernelSize = j.value(
"gaussianSize", detector.m_gaussianKernelSize);
221 detector.m_gaussianStdev = j.value(
"gaussianStdev", detector.m_gaussianStdev);
222 detector.m_lowerThreshold = j.value(
"lowerThreshold", detector.m_lowerThreshold);
223 detector.m_lowerThresholdRatio = j.value(
"lowerThresholdRatio", detector.m_lowerThresholdRatio);
224 detector.m_gradientFilterKernelSize = j.value(
"gradientFilterKernelSize", detector.m_gradientFilterKernelSize);
225 detector.m_upperThreshold = j.value(
"upperThreshold", detector.m_upperThreshold);
226 detector.m_upperThresholdRatio = j.value(
"upperThresholdRatio", detector.m_upperThresholdRatio);
239 {
"filteringAndGradientType", filteringAndGradientName},
240 {
"gaussianSize", detector.m_gaussianKernelSize},
241 {
"gaussianStdev", detector.m_gaussianStdev},
242 {
"lowerThreshold", detector.m_lowerThreshold},
243 {
"lowerThresholdRatio", detector.m_lowerThresholdRatio},
244 {
"gradientFilterKernelSize", detector.m_gradientFilterKernelSize},
245 {
"upperThreshold", detector.m_upperThreshold},
246 {
"upperThresholdRatio", detector.m_upperThresholdRatio}
254 #ifdef HAVE_OPENCV_CORE
292 m_filteringAndGradientType = type;
293 initGradientFilters();
306 m_areGradientAvailable =
true;
322 m_lowerThreshold = lowerThresh;
323 m_upperThreshold = upperThresh;
340 m_lowerThresholdRatio = lowerThreshRatio;
341 m_upperThresholdRatio = upperThreshRatio;
354 m_gaussianKernelSize = kernelSize;
355 m_gaussianStdev = stdev;
356 initGaussianFilters();
366 m_gradientFilterKernelSize = apertureSize;
367 initGradientFilters();
void setFilteringAndGradientType(const vpImageFilter::vpCannyFilteringAndGradientType &type)
Set the Filtering And Gradient operators to apply to the image before the edge detection operation.
void setMask(const vpImage< bool > *p_mask)
Set a mask to ignore pixels for which the mask is false.
void setCannyThresholdsRatio(const float &lowerThreshRatio, const float &upperThreshRatio)
Set the lower and upper Canny Thresholds ratio that are used to compute them automatically....
friend void from_json(const nlohmann::json &j, vpCannyEdgeDetection &detector)
Read the detector configuration from JSON. All values are optional and if an argument is not present,...
void setGradients(const vpImage< float > &dIx, const vpImage< float > &dIy)
Set the Gradients of the image that will be processed.
friend void to_json(nlohmann::json &j, const vpCannyEdgeDetection &detector)
Parse a vpCannyEdgeDetection object into JSON format.
void setCannyThresholds(const float &lowerThresh, const float &upperThresh)
Set the lower and upper Canny Thresholds used to qualify the edge point candidates....
void setGradientFilterAperture(const unsigned int &apertureSize)
Set the parameters of the gradient filter (Sobel or Scharr) kernel size filters.
void setGaussianFilterParameters(const int &kernelSize, const float &stdev)
Set the Gaussian Filters kernel size and standard deviation and initialize the aforementioned filters...
vpCannyFilteringAndGradientType
Canny filter and gradient operators to apply on the image before the edge detection stage.
@ CANNY_GBLUR_SOBEL_FILTERING
Apply Gaussian blur + Sobel operator on the input image.
static vpCannyFilteringAndGradientType vpCannyFilteringAndGradientTypeFromString(const std::string &name)
Cast a string into a vpImageFilter::vpCannyFilteringAndGradientType.
static std::string vpCannyFilteringAndGradientTypeToString(const vpCannyFilteringAndGradientType &type)
Cast a vpImageFilter::vpCannyFilteringAndGradientType into a string, to know its name.