-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various fixes for ViSP Canny implementation #1490
Conversation
rolalaro
commented
Oct 30, 2024
- Fix throwing an exception when the Canny's ratio for automatic computation of the thresholds are wrong
- Fix of the list of edge points
- Cleaning Canny tutorial + added a test there for the edge list
Weak edges that turned into strong edges were not added to the list of edges.
Check if C++ standard is greater or equal to C++11 before calling createDisplay, otherwise call allocateDisplay and free the memory at the end of the program
…ORE] Added test of edge-list feature The software arguments management was a bit messy, so introduced a structure holding all the parameters Introduced a test function to ensure that the edge-list correctly reflect the Canny output image
Throw an exception when the Canny's ratio are outside the expected boundaries
Ensure that lower ratio < upper ratio
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1490 +/- ##
==========================================
- Coverage 53.88% 53.84% -0.04%
==========================================
Files 442 442
Lines 53778 53848 +70
==========================================
+ Hits 28978 28996 +18
- Misses 24800 24852 +52 ☔ View full report in Codecov by Sentry. |
[FIX] Removed percentage symbol [CORE] Added check notFOund in OpenCV implem
For some reasons, changing the ulimit -s 8192
./tutorial-canny -i /tmp/img2.png --gradient 3 0.5
Canny Configuration:
Filtering + gradient operators = gaussianblur+sobel-filtering
Gaussian filter kernel size = 3
Gaussian filter standard deviation = 0.500000
Gradient filter kernel size = 3
Canny edge filter thresholds = [-1.000000 ; -1.000000]
Canny edge filter thresholds ratio (for auto-thresholding) = [0.600000 ; 0.800000]
setrlimit returned result = -1 ; errno=Invalid argument My issue occurs on some really over-exposed images and should not be the typical use-case. To avoid putting too much efforts on some edge cases, I would propose:
diff --git a/modules/core/include/visp3/core/vpCannyEdgeDetection.h b/modules/core/include/visp3/core/vpCannyEdgeDetection.h
index e70360f40..0e9026d32 100644
--- a/modules/core/include/visp3/core/vpCannyEdgeDetection.h
+++ b/modules/core/include/visp3/core/vpCannyEdgeDetection.h
@@ -385,7 +385,7 @@ private:
* \return true We found a strong edge point in its 8-connected neighborhood.
* \return false We did not found a strong edge point in its 8-connected neighborhood.
*/
- bool recursiveSearchForStrongEdge(const std::pair<unsigned int, unsigned int> &coordinates);
+ bool recursiveSearchForStrongEdge(const std::pair<unsigned int, unsigned int> &coordinates, int &depth);
/**
* \brief Perform edge tracking.
diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp
index e8a5b5f01..e2aa11033 100644
--- a/modules/core/src/image/vpCannyEdgeDetection.cpp
+++ b/modules/core/src/image/vpCannyEdgeDetection.cpp
@@ -258,8 +258,7 @@ vpCannyEdgeDetection::detect(const vpImage<unsigned char> &I)
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0) {
- throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result));
-
+ throw(vpException(vpException::fatalError, "setrlimit returned result = %d ; errno=%s\n", result, strerror(errno)));
}
}
}
@@ -530,22 +529,34 @@ vpCannyEdgeDetection::performEdgeTracking()
{
std::map<std::pair<unsigned int, unsigned int>, EdgeType>::iterator it;
std::map<std::pair<unsigned int, unsigned int>, EdgeType>::iterator m_edgePointsCandidates_end = m_edgePointsCandidates.end();
+ unsigned int nbStrongEdges = 0, nbWeakEdges = 0;
for (it = m_edgePointsCandidates.begin(); it != m_edgePointsCandidates_end; ++it) {
if (it->second == STRONG_EDGE) {
m_edgeMap[it->first.first][it->first.second] = 255;
if (m_storeListEdgePoints) {
m_edgePointsList.push_back(vpImagePoint(it->first.first, it->first.second));
}
+ ++nbStrongEdges;
}
else if (it->second == WEAK_EDGE) {
- recursiveSearchForStrongEdge(it->first);
+ int depth = 0;
+ recursiveSearchForStrongEdge(it->first, depth);
+ std::cout << "[vpCannyEdgeDetection::performEdgeTracking]depth = " << depth << std::endl;
+ ++nbWeakEdges;
}
}
+ std::cout << "[vpCannyEdgeDetection::performEdgeTracking]#strong edges = " << nbStrongEdges << std::endl;
+ std::cout << "[vpCannyEdgeDetection::performEdgeTracking]#weak edges = " << nbWeakEdges << std::endl;
}
bool
-vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair<unsigned int, unsigned int> &coordinates)
+vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair<unsigned int, unsigned int> &coordinates, int &depth)
{
+ depth++;
+ if (depth >= 65390) {
+ throw vpException(vpException::fatalError, "Reach the max number of allowed function calls recursion!");
+ }
+
bool hasFoundStrongEdge = false;
int nbRows = m_dIx.getRows();
int nbCols = m_dIx.getCols();
@@ -575,10 +586,9 @@ vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair<unsigned int,
// the continue is replaced by the test
}
if (edge_in_image_limit == false) {
-
- try {
- std::pair<unsigned int, unsigned int> key_candidate(idRow, idCol);
- // Checking if the 8-neighbor point is in the list of edge candidates
+ std::pair<unsigned int, unsigned int> key_candidate(idRow, idCol);
+ // Checking if the 8-neighbor point is in the list of edge candidates
+ if (m_edgePointsCandidates.find(key_candidate) != m_edgePointsCandidates.end()) {
EdgeType type_candidate = m_edgePointsCandidates.at(key_candidate);
if (type_candidate == STRONG_EDGE) {
// The 8-neighbor point is a strong edge => the weak edge becomes a strong edge
@@ -586,12 +596,9 @@ vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair<unsigned int,
}
else if (type_candidate == WEAK_EDGE) {
// Checking if the WEAK_EDGE neighbor has a STRONG_EDGE neighbor
- hasFoundStrongEdge = recursiveSearchForStrongEdge(key_candidate);
+ hasFoundStrongEdge = recursiveSearchForStrongEdge(key_candidate, depth);
}
}
- catch (...) {
- // continue - nothing to do
- }
}
++dc;
} |
Or maybe add two functions Add another function |
From what I read, only POSIX systems can set dynamically the stack size. On windows systems, the stack size of a program can only be changed during compilation. So the setStackSize function should either be available only for POSIX systems or throw an exception for Windows systems. |
…k size [CORE] Made the minimum stack size used in the detect method of the vpCannyEdgeDetection class an attribute that the user can either decrease or increase to meet their requirements. [DOC] Documented the fact that the stack size can lead to a segfault when the method is called for particular images and the specificities of each platform