31 #ifndef VP_CANNY_EDGE_DETECTION_H
32 #define VP_CANNY_EDGE_DETECTION_H
38 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
39 #include <sys/resource.h>
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpImageFilter.h>
46 #include <visp3/core/vpRGBa.h>
49 #ifdef VISP_HAVE_NLOHMANN_JSON
50 #include VISP_NLOHMANN_JSON(json.hpp)
96 vpCannyEdgeDetection(
const int &gaussianKernelSize,
const float &gaussianStdev,
const unsigned int &sobelAperture,
97 const float &lowerThreshold = -1.f,
const float &upperThreshold = -1.f,
98 const float &lowerThresholdRatio = 0.6f,
const float &upperThresholdRatio = 0.8f,
100 const bool &storeEdgePoints =
false);
103 #ifdef VISP_HAVE_NLOHMANN_JSON
118 void initFromJSON(
const std::string &jsonPath);
141 #ifdef HAVE_OPENCV_CORE
185 m_filteringAndGradientType = type;
186 initGradientFilters();
199 m_areGradientAvailable =
true;
215 m_lowerThreshold = lowerThresh;
216 m_upperThreshold = upperThresh;
233 m_lowerThresholdRatio = lowerThreshRatio;
234 m_upperThresholdRatio = upperThreshRatio;
247 m_gaussianKernelSize = kernelSize;
248 m_gaussianStdev = stdev;
249 initGaussianFilters();
259 m_gradientFilterKernelSize = apertureSize;
260 initGradientFilters();
291 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
292 inline void setMinimumStackSize(
const rlim_t &requiredStackSize)
294 m_minStackSize = requiredStackSize;
299 (void)requiredStackSize;
300 static bool hasNotBeenDisplayed =
true;
301 if (hasNotBeenDisplayed) {
302 std::cerr <<
"setStackSize has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl;
303 hasNotBeenDisplayed =
false;
316 m_storeListEdgePoints = storeEdgePoints;
329 if (!m_storeListEdgePoints) {
332 return m_edgePointsList;
343 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
344 inline rlim_t getMinimumStackSize()
const
346 return m_minStackSize;
351 const unsigned int limit = 65532000;
359 typedef enum EdgeType
371 int m_gaussianKernelSize;
372 float m_gaussianStdev;
376 bool m_areGradientAvailable;
377 unsigned int m_gradientFilterKernelSize;
384 std::map<std::pair<unsigned int, unsigned int>,
float> m_edgeCandidateAndGradient;
387 float m_lowerThreshold;
389 float m_lowerThresholdRatio;
391 float m_upperThreshold;
392 float m_upperThresholdRatio;
396 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
397 rlim_t m_minStackSize;
399 bool m_storeListEdgePoints;
400 std::map<std::pair<unsigned int, unsigned int>, EdgeType> m_edgePointsCandidates;
403 std::vector<vpImagePoint> m_edgePointsList;
411 void initGaussianFilters();
416 void initGradientFilters();
435 void performEdgeThinning(
const float &lowerThreshold);
450 void performHysteresisThresholding(
const float &lowerThreshold,
const float &upperThreshold);
459 bool recursiveSearchForStrongEdge(
const std::pair<unsigned int, unsigned int> &coordinates);
467 void performEdgeTracking();
Class that implements the Canny's edge detector. It is possible to use a boolean mask to ignore some ...
unsigned int getMinimumStackSize() const
Get the minimum stack size used by the algorithm.
void setStoreEdgePoints(const bool &storeEdgePoints)
If set to true, the list of the detected edge-points will be available calling the method vpCannyEdge...
void setFilteringAndGradientType(const vpImageFilter::vpCannyFilteringAndGradientType &type)
Set the Filtering And Gradient operators to apply to the image before the edge detection operation.
std::vector< vpImagePoint > getEdgePointsList() const
Get the list of edge-points that have been detected.
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....
void setMinimumStackSize(const unsigned int &requiredStackSize)
Set the minimum stack size, expressed in bytes, due to the recursivity of the algorithm.
void setGradients(const vpImage< float > &dIx, const vpImage< float > &dIy)
Set the Gradients of the image that will be processed.
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...
error that can be emitted by ViSP classes.
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.