From 2a07aa59fb3a3742b9fdb70c53403f011a524c93 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Sun, 7 May 2017 09:40:24 -0400 Subject: [PATCH] Now working on OpenCV with Qt support --- examples/openpose/rtpose.cpp | 37 ++++++++++--------- .../1_openpose_read_and_display.cpp | 21 ++++++----- .../2_user_processing_function.cpp | 21 ++++++----- .../3_user_input_processing_and_output.cpp | 21 ++++++----- ...user_input_processing_output_and_datum.cpp | 21 ++++++----- .../tutorial_wrapper/2_user_synchronous.cpp | 31 +++++++++------- include/openpose/wrapper/wrapper.hpp | 4 ++ 7 files changed, 89 insertions(+), 67 deletions(-) diff --git a/examples/openpose/rtpose.cpp b/examples/openpose/rtpose.cpp index 14d70065..da66dc90 100755 --- a/examples/openpose/rtpose.cpp +++ b/examples/openpose/rtpose.cpp @@ -268,24 +268,27 @@ int opRealTimePoseDemo() op::log("Starting thread(s)", op::Priority::Max); // Option a) Recommended - Also using the main thread (this thread) for processing (it saves 1 thread) // Start, run & stop threads - // opWrapper.exec(); // It blocks this thread until all threads have finished + opWrapper.exec(); // It blocks this thread until all threads have finished - // Option b) Keeping this thread free in case you want to do something else meanwhile, e.g. profiling the GPU memory - // Start threads - opWrapper.start(); - // Profile used GPU memory - // 1: wait ~10sec so the memory has been totally loaded on GPU - // 2: profile the GPU memory - const auto sleepTimeMs = 10; - for (auto i = 0 ; i < 10000/sleepTimeMs && opWrapper.isRunning() ; i++) - std::this_thread::sleep_for(std::chrono::milliseconds{sleepTimeMs}); - op::Profiler::profileGpuMemory(__LINE__, __FUNCTION__, __FILE__); - // Keep program alive while running threads - while (opWrapper.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{sleepTimeMs}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - opWrapper.stop(); + // // Option b) Keeping this thread free in case you want to do something else meanwhile, e.g. profiling the GPU memory + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // opWrapper.start(); + // // Profile used GPU memory + // // 1: wait ~10sec so the memory has been totally loaded on GPU + // // 2: profile the GPU memory + // const auto sleepTimeMs = 10; + // for (auto i = 0 ; i < 10000/sleepTimeMs && opWrapper.isRunning() ; i++) + // std::this_thread::sleep_for(std::chrono::milliseconds{sleepTimeMs}); + // op::Profiler::profileGpuMemory(__LINE__, __FUNCTION__, __FILE__); + // // Keep program alive while running threads + // while (opWrapper.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{sleepTimeMs}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // opWrapper.stop(); // Measuring total time const auto totalTimeSec = (double)std::chrono::duration_cast(std::chrono::high_resolution_clock::now()-timerBegin).count() * 1e-9; diff --git a/examples/tutorial_thread/1_openpose_read_and_display.cpp b/examples/tutorial_thread/1_openpose_read_and_display.cpp index ef896966..7056cd32 100644 --- a/examples/tutorial_thread/1_openpose_read_and_display.cpp +++ b/examples/tutorial_thread/1_openpose_read_and_display.cpp @@ -164,16 +164,19 @@ int openPoseTutorialThread1() op::log("Starting thread(s)", op::Priority::Max); // Two different ways of running the program on multithread enviroment // Option a) Using the main thread (this thread) for processing (it saves 1 thread, recommended) - // threadManager.exec(); // It blocks this thread until all threads have finished + threadManager.exec(); // It blocks this thread until all threads have finished // Option b) Giving to the user the control of this thread - // Start threads - threadManager.start(); - // Keep program alive while running threads. Here the user could perform any other desired function - while (threadManager.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{33}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - threadManager.stop(); + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // threadManager.start(); + // // Keep program alive while running threads. Here the user could perform any other desired function + // while (threadManager.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{33}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // threadManager.stop(); // ------------------------- CLOSING ------------------------- // Logging information message diff --git a/examples/tutorial_thread/2_user_processing_function.cpp b/examples/tutorial_thread/2_user_processing_function.cpp index 78189757..027986aa 100644 --- a/examples/tutorial_thread/2_user_processing_function.cpp +++ b/examples/tutorial_thread/2_user_processing_function.cpp @@ -206,16 +206,19 @@ int openPoseTutorialThread2() op::log("Starting thread(s)", op::Priority::Max); // Two different ways of running the program on multithread enviroment // Option a) Using the main thread (this thread) for processing (it saves 1 thread, recommended) - // threadManager.exec(); // It blocks this thread until all threads have finished + threadManager.exec(); // It blocks this thread until all threads have finished // Option b) Giving to the user the control of this thread - // Start threads - threadManager.start(); - // Keep program alive while running threads. Here the user could perform any other desired function - while (threadManager.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{33}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - threadManager.stop(); + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // threadManager.start(); + // // Keep program alive while running threads. Here the user could perform any other desired function + // while (threadManager.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{33}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // threadManager.stop(); // ------------------------- CLOSING ------------------------- // Logging information message diff --git a/examples/tutorial_thread/3_user_input_processing_and_output.cpp b/examples/tutorial_thread/3_user_input_processing_and_output.cpp index ebb21608..17d6e464 100644 --- a/examples/tutorial_thread/3_user_input_processing_and_output.cpp +++ b/examples/tutorial_thread/3_user_input_processing_and_output.cpp @@ -197,16 +197,19 @@ int openPoseTutorialThread3() op::log("Starting thread(s)", op::Priority::Max); // Two different ways of running the program on multithread enviroment // Option a) Using the main thread (this thread) for processing (it saves 1 thread, recommended) - // threadManager.exec(); // It blocks this thread until all threads have finished + threadManager.exec(); // It blocks this thread until all threads have finished // Option b) Giving to the user the control of this thread - // Start threads - threadManager.start(); - // Keep program alive while running threads. Here the user could perform any other desired function - while (threadManager.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{33}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - threadManager.stop(); + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // threadManager.start(); + // // Keep program alive while running threads. Here the user could perform any other desired function + // while (threadManager.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{33}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // threadManager.stop(); // ------------------------- CLOSING ------------------------- // Logging information message diff --git a/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp b/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp index c5d2e081..075f4458 100644 --- a/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp +++ b/examples/tutorial_thread/4_user_input_processing_output_and_datum.cpp @@ -209,16 +209,19 @@ int openPoseTutorialThread4() op::log("Starting thread(s)", op::Priority::Max); // Two different ways of running the program on multithread enviroment // Option a) Using the main thread (this thread) for processing (it saves 1 thread, recommended) - // threadManager.exec(); // It blocks this thread until all threads have finished + threadManager.exec(); // It blocks this thread until all threads have finished // Option b) Giving to the user the control of this thread - // Start threads - threadManager.start(); - // Keep program alive while running threads. Here the user could perform any other desired function - while (threadManager.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{33}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - threadManager.stop(); + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // threadManager.start(); + // // Keep program alive while running threads. Here the user could perform any other desired function + // while (threadManager.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{33}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // threadManager.stop(); // ------------------------- CLOSING ------------------------- // Logging information message diff --git a/examples/tutorial_wrapper/2_user_synchronous.cpp b/examples/tutorial_wrapper/2_user_synchronous.cpp index ac047e48..7d738944 100644 --- a/examples/tutorial_wrapper/2_user_synchronous.cpp +++ b/examples/tutorial_wrapper/2_user_synchronous.cpp @@ -365,22 +365,25 @@ int openPoseTutorialWrapper2() // Two different ways of running the program on multithread enviroment // // Option a) Recommended - Also using the main thread (this thread) for processing (it saves 1 thread) // // Start, run & stop threads - // opWrapper.exec(); // It blocks this thread until all threads have finished + opWrapper.exec(); // It blocks this thread until all threads have finished // Option b) Keeping this thread free in case you want to do something else meanwhile, e.g. profiling the GPU memory - // Start threads - opWrapper.start(); - // Profile used GPU memory - // 1: wait ~10sec so the memory has been totally loaded on GPU - // 2: profile the GPU memory - std::this_thread::sleep_for(std::chrono::milliseconds{1000}); - op::log("Random task here...", op::Priority::Max); - // Keep program alive while running threads - while (opWrapper.isRunning()) - std::this_thread::sleep_for(std::chrono::milliseconds{33}); - // Stop and join threads - op::log("Stopping thread(s)", op::Priority::Max); - opWrapper.stop(); + // // VERY IMPORTANT NOTE: if OpenCV is compiled with Qt support, this option will not work. Qt needs the main thread to + // // plot visual results, so the final GUI (which uses OpenCV) would return an exception similar to: + // // `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections` + // // Start threads + // opWrapper.start(); + // // Profile used GPU memory + // // 1: wait ~10sec so the memory has been totally loaded on GPU + // // 2: profile the GPU memory + // std::this_thread::sleep_for(std::chrono::milliseconds{1000}); + // op::log("Random task here...", op::Priority::Max); + // // Keep program alive while running threads + // while (opWrapper.isRunning()) + // std::this_thread::sleep_for(std::chrono::milliseconds{33}); + // // Stop and join threads + // op::log("Stopping thread(s)", op::Priority::Max); + // opWrapper.stop(); // Measuring total time const auto totalTimeSec = (double)std::chrono::duration_cast(std::chrono::high_resolution_clock::now()-timerBegin).count() * 1e-9; diff --git a/include/openpose/wrapper/wrapper.hpp b/include/openpose/wrapper/wrapper.hpp index f9e4a13b..a79119cc 100644 --- a/include/openpose/wrapper/wrapper.hpp +++ b/include/openpose/wrapper/wrapper.hpp @@ -123,6 +123,10 @@ namespace op * Function to start multi-threading. * Similar to exec(), but start() does not block the thread that calls the function. It just opens new threads, so it * lets the user perform other tasks meanwhile on the calling thread. + * VERY IMPORTANT NOTE: if the GUI is selected and OpenCV is compiled with Qt support, this option will not work. Qt + * needs the main thread to plot visual results, so the final GUI (which uses OpenCV) would return an exception + * similar to: `QMetaMethod::invoke: Unable to invoke methods with return values in queued connections`. Use exec() + * in that case. */ void start();