From 6d5fdfbf73070e79bb6b061fd96827e8d43b037f Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 19 Oct 2021 09:28:12 +0000 Subject: [PATCH] samples: fix build without threading support --- samples/CMakeLists.txt | 1 + .../videoio/orbbec_astra/orbbec_astra.cpp | 13 +++++++++++++ samples/dnn/object_detection.cpp | 16 ++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 9d8f588083..910454ca71 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -120,6 +120,7 @@ else() find_package(Threads) endif() if((TARGET Threads::Threads OR HAVE_THREADS) AND NOT OPENCV_EXAMPLES_DISABLE_THREADS) + set(HAVE_THREADS 1) add_definitions(-DHAVE_THREADS=1) endif() diff --git a/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp b/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp index 581b1768f1..6bb9f904af 100644 --- a/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp +++ b/samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp @@ -4,6 +4,17 @@ #include #include + + +#if !defined(HAVE_THREADS) +int main() +{ + std::cout << "This sample is built without threading support. Sample code is disabled." << std::endl; + return 0; +} +#else + + #include #include #include @@ -200,3 +211,5 @@ int main() return 0; } + +#endif diff --git a/samples/dnn/object_detection.cpp b/samples/dnn/object_detection.cpp index 5ff112fe5d..6fc8b2ab61 100644 --- a/samples/dnn/object_detection.cpp +++ b/samples/dnn/object_detection.cpp @@ -5,7 +5,11 @@ #include #include -#ifdef CV_CXX11 +#if defined(CV_CXX11) && defined(HAVE_THREADS) +#define USE_THREADS 1 +#endif + +#ifdef USE_THREADS #include #include #include @@ -56,7 +60,7 @@ void drawPred(int classId, float conf, int left, int top, int right, int bottom, void callback(int pos, void* userdata); -#ifdef CV_CXX11 +#ifdef USE_THREADS template class QueueFPS : public std::queue { @@ -106,7 +110,7 @@ private: TickMeter tm; std::mutex mutex; }; -#endif // CV_CXX11 +#endif // USE_THREADS int main(int argc, char** argv) { @@ -171,7 +175,7 @@ int main(int argc, char** argv) else cap.open(parser.get("device")); -#ifdef CV_CXX11 +#ifdef USE_THREADS bool process = true; // Frames capturing thread @@ -271,7 +275,7 @@ int main(int argc, char** argv) framesThread.join(); processingThread.join(); -#else // CV_CXX11 +#else // USE_THREADS if (asyncNumReq) CV_Error(Error::StsNotImplemented, "Asynchronous forward is supported only with Inference Engine backend."); @@ -302,7 +306,7 @@ int main(int argc, char** argv) imshow(kWinName, frame); } -#endif // CV_CXX11 +#endif // USE_THREADS return 0; }