Skip to content

Commit 14d5098

Browse files
committed
Merge pull request opencv#20903 from alalek:samples_fix_nothreads_build
2 parents c0c71d6 + 6d5fdfb commit 14d5098

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

samples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ else()
118118
find_package(Threads)
119119
endif()
120120
if((TARGET Threads::Threads OR HAVE_THREADS) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS)
121+
set(HAVE_THREADS 1)
121122
add_definitions(-DHAVE_THREADS=1)
122123
endif()
123124

samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
#include <list>
66
#include <iostream>
7+
8+
9+
#if !defined(HAVE_THREADS)
10+
int main()
11+
{
12+
std::cout << "This sample is built without threading support. Sample code is disabled." << std::endl;
13+
return 0;
14+
}
15+
#else
16+
17+
718
#include <thread>
819
#include <mutex>
920
#include <condition_variable>
@@ -200,3 +211,5 @@ int main()
200211

201212
return 0;
202213
}
214+
215+
#endif

samples/dnn/object_detection.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
#include <opencv2/imgproc.hpp>
66
#include <opencv2/highgui.hpp>
77

8-
#ifdef CV_CXX11
8+
#if defined(CV_CXX11) && defined(HAVE_THREADS)
9+
#define USE_THREADS 1
10+
#endif
11+
12+
#ifdef USE_THREADS
913
#include <mutex>
1014
#include <thread>
1115
#include <queue>
@@ -56,7 +60,7 @@ void drawPred(int classId, float conf, int left, int top, int right, int bottom,
5660

5761
void callback(int pos, void* userdata);
5862

59-
#ifdef CV_CXX11
63+
#ifdef USE_THREADS
6064
template <typename T>
6165
class QueueFPS : public std::queue<T>
6266
{
@@ -106,7 +110,7 @@ class QueueFPS : public std::queue<T>
106110
TickMeter tm;
107111
std::mutex mutex;
108112
};
109-
#endif // CV_CXX11
113+
#endif // USE_THREADS
110114

111115
int main(int argc, char** argv)
112116
{
@@ -171,7 +175,7 @@ int main(int argc, char** argv)
171175
else
172176
cap.open(parser.get<int>("device"));
173177

174-
#ifdef CV_CXX11
178+
#ifdef USE_THREADS
175179
bool process = true;
176180

177181
// Frames capturing thread
@@ -271,7 +275,7 @@ int main(int argc, char** argv)
271275
framesThread.join();
272276
processingThread.join();
273277

274-
#else // CV_CXX11
278+
#else // USE_THREADS
275279
if (asyncNumReq)
276280
CV_Error(Error::StsNotImplemented, "Asynchronous forward is supported only with Inference Engine backend.");
277281

@@ -302,7 +306,7 @@ int main(int argc, char** argv)
302306

303307
imshow(kWinName, frame);
304308
}
305-
#endif // CV_CXX11
309+
#endif // USE_THREADS
306310
return 0;
307311
}
308312

0 commit comments

Comments
 (0)