Skip to content

Commit 22f0ea0

Browse files
committed
ximgproc: avoid data race in StructuredEdgeDetection::detectEdges()
1 parent 6ae9809 commit 22f0ea0

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

modules/ximgproc/src/structured_edge_detection.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@
3737
//
3838
//M*/
3939

40+
#include "precomp.hpp"
41+
4042
#include <vector>
4143
#include <algorithm>
4244
#include <iterator>
4345
#include <iostream>
4446
#include <cmath>
4547

46-
#include "precomp.hpp"
47-
4848
#include "advanced_types.hpp"
4949

50+
#ifdef CV_CXX11
51+
#define CV_USE_PARALLEL_PREDICT_EDGES_1 1
52+
#define CV_USE_PARALLEL_PREDICT_EDGES_2 0 //1, see https://github.com/opencv/opencv_contrib/issues/2346
53+
#else
54+
#define CV_USE_PARALLEL_PREDICT_EDGES_1 0
55+
#define CV_USE_PARALLEL_PREDICT_EDGES_2 0
56+
#endif
57+
5058
/********************* Helper functions *********************/
5159

5260
/*!
@@ -730,7 +738,7 @@ class StructuredEdgeDetectionImpl : public StructuredEdgeDetection
730738
}
731739
// lookup tables for mapping linear index to offset pairs
732740

733-
#ifdef CV_CXX11
741+
#if CV_USE_PARALLEL_PREDICT_EDGES_1
734742
parallel_for_(cv::Range(0, height), [&](const cv::Range& range)
735743
#else
736744
const cv::Range range(0, height);
@@ -779,7 +787,7 @@ class StructuredEdgeDetectionImpl : public StructuredEdgeDetection
779787
}
780788
}
781789
}
782-
#ifdef CV_CXX11
790+
#if CV_USE_PARALLEL_PREDICT_EDGES_1
783791
);
784792
#endif
785793

@@ -788,8 +796,10 @@ class StructuredEdgeDetectionImpl : public StructuredEdgeDetection
788796
dstM.setTo(0);
789797

790798
float step = 2.0f * CV_SQR(stride) / CV_SQR(ipSize) / nTreesEval;
791-
#ifdef CV_CXX11
799+
#if CV_USE_PARALLEL_PREDICT_EDGES_2
792800
parallel_for_(cv::Range(0, height), [&](const cv::Range& range)
801+
#elif CV_USE_PARALLEL_PREDICT_EDGES_1
802+
const cv::Range range(0, height);
793803
#endif
794804
{
795805
for(int i = range.start; i < range.end; ++i)
@@ -814,7 +824,7 @@ class StructuredEdgeDetectionImpl : public StructuredEdgeDetection
814824
}
815825
}
816826
}
817-
#ifdef CV_CXX11
827+
#if CV_USE_PARALLEL_PREDICT_EDGES_2
818828
);
819829
#endif
820830

0 commit comments

Comments
 (0)