Skip to content

Commit

Permalink
[CORE] Increased stack size for Canny algo
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGNEAU Romain committed Oct 31, 2024
1 parent 6adf6a0 commit 4c89a32
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion modules/core/src/image/vpCannyEdgeDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@

#include <visp3/core/vpImageConvert.h>

#ifdef VISP_USE_MSVC
#pragma comment(linker, "/STACK:256000000") // Increase max recursion depth
#elif !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
#include <sys/resource.h>
#endif

#if (VISP_CXX_STANDARD == VISP_CXX_STANDARD_98) // Check if cxx98
namespace
{
Expand Down Expand Up @@ -239,7 +245,26 @@ vpCannyEdgeDetection::detect(const vpImage<vpRGBa> &I_color)
vpImage<unsigned char>
vpCannyEdgeDetection::detect(const vpImage<unsigned char> &I)
{
// // Clearing the previous results
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
// Increase stack size due to the recursive algorithm
const rlim_t kStackSize = 256 * 1024 * 1024; // min stack size = 256 MB
rlim_t initialStackSize;
struct rlimit rl;
int result;
result = getrlimit(RLIMIT_STACK, &rl);
if (result == 0) {
if (rl.rlim_cur < kStackSize) {
initialStackSize = rl.rlim_cur;
rl.rlim_cur = kStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0) {
throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result));

}
}
}
#endif
// // Clearing the previous results
m_edgeMap.resize(I.getHeight(), I.getWidth(), 0);
m_edgeCandidateAndGradient.clear();
m_edgePointsCandidates.clear();
Expand Down Expand Up @@ -272,6 +297,18 @@ vpCannyEdgeDetection::detect(const vpImage<unsigned char> &I)

// // Step 5: edge tracking
performEdgeTracking();

#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
// Reset stack size to its original value
if (rl.rlim_cur > initialStackSize) {
rl.rlim_cur = initialStackSize;
result = setrlimit(RLIMIT_STACK, &rl);
if (result != 0) {
throw(vpException(vpException::fatalError, "setrlimit returned result = %d\n", result));

}
}
#endif
return m_edgeMap;
}

Expand Down

0 comments on commit 4c89a32

Please sign in to comment.