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();
293 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
294 inline void setMinimumStackSize(
const rlim_t &requiredStackSize)
296 m_minStackSize = requiredStackSize;
301 (void)requiredStackSize;
302 static bool hasNotBeenDisplayed =
true;
303 if (hasNotBeenDisplayed) {
304 std::cerr <<
"vpCannyEdgeDetection::setStackSize() has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl;
305 hasNotBeenDisplayed =
false;
318 m_storeListEdgePoints = storeEdgePoints;
331 if (!m_storeListEdgePoints) {
334 return m_edgePointsList;
345 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
346 inline rlim_t getMinimumStackSize()
const
348 return m_minStackSize;
353 const unsigned int limit = 65532000;
361 typedef enum EdgeType
373 int m_gaussianKernelSize;
374 float m_gaussianStdev;
378 bool m_areGradientAvailable;
379 unsigned int m_gradientFilterKernelSize;
386 std::map<std::pair<unsigned int, unsigned int>,
float> m_edgeCandidateAndGradient;
389 float m_lowerThreshold;
391 float m_lowerThresholdRatio;
393 float m_upperThreshold;
394 float m_upperThresholdRatio;
398 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
399 rlim_t m_minStackSize;
401 bool m_storeListEdgePoints;
402 std::map<std::pair<unsigned int, unsigned int>, EdgeType> m_edgePointsCandidates;
405 std::vector<vpImagePoint> m_edgePointsList;
413 void initGaussianFilters();
418 void initGradientFilters();
437 void performEdgeThinning(
const float &lowerThreshold);
452 void performHysteresisThresholding(
const float &lowerThreshold,
const float &upperThreshold);
461 bool recursiveSearchForStrongEdge(
const std::pair<unsigned int, unsigned int> &coordinates);
469 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 recursive algorithm. If not called,...
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.