From b365f48e482d12801aee75d2888ca4ea608ca97e Mon Sep 17 00:00:00 2001 From: Gines Hidalgo Date: Fri, 19 Jun 2020 19:13:05 -0400 Subject: [PATCH] C++ tutorial API only cv::imshow if not empty --- doc/modules/python_module.md | 5 +++++ doc/release_notes.md | 1 + .../01_body_from_image_default.cpp | 9 +++++++-- .../02_whole_body_from_image_default.cpp | 9 +++++++-- .../tutorial_api_cpp/03_keypoints_from_image.cpp | 9 +++++++-- .../tutorial_api_cpp/04_keypoints_from_images.cpp | 5 ++++- .../05_keypoints_from_images_multi_gpu.cpp | 5 ++++- examples/tutorial_api_cpp/06_face_from_image.cpp | 9 +++++++-- examples/tutorial_api_cpp/07_hand_from_image.cpp | 9 +++++++-- .../tutorial_api_cpp/08_heatmaps_from_image.cpp | 5 ++++- .../09_keypoints_from_heatmaps.cpp | 9 +++++++-- .../12_asynchronous_custom_output.cpp | 5 ++++- ...asynchronous_custom_input_output_and_datum.cpp | 5 ++++- .../17_synchronous_custom_output.cpp | 15 ++++++++++----- .../18_synchronous_custom_all_and_datum.cpp | 15 ++++++++++----- 15 files changed, 88 insertions(+), 27 deletions(-) diff --git a/doc/modules/python_module.md b/doc/modules/python_module.md index ee6db4e5..80422a7e 100644 --- a/doc/modules/python_module.md +++ b/doc/modules/python_module.md @@ -106,6 +106,11 @@ Windows: ## Common Issues +### Do not use PIL +In order to read images in Python, make sure to use OpenCV (do not use PIL). We found that feeding a PIL image format to OpenPose results in the input image appearing in grey and duplicated 9 times (so the output skeleton appear 3 times smaller than they should be, and duplicated 9 times). + + +### Cannot Import Name PyOpenPose The error in general is that PyOpenPose cannot be found (an error similar to: `ImportError: cannot import name pyopenpose`). Ensure first that `BUILD_PYTHON` flag is set to ON. If the error persists, check the following: In the script you are running, check for the following line, and run the following command in the same location as where the file is diff --git a/doc/release_notes.md b/doc/release_notes.md index e3fc9127..f3c105f8 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -419,6 +419,7 @@ OpenPose Library - Release Notes 2. Functions or parameters renamed: 3. Main bugs fixed: 1. 90 and 270-degree rotations working again. + 2. C++ tutorial API demos only try to cv::imshow the image if it is not empty (avoding the assert that it would trigger otherwise). 4. Changes/additions that affect the compatibility with the OpenPose Unity Plugin: diff --git a/examples/tutorial_api_cpp/01_body_from_image_default.cpp b/examples/tutorial_api_cpp/01_body_from_image_default.cpp index 20863d2c..dc6b0975 100644 --- a/examples/tutorial_api_cpp/01_body_from_image_default.cpp +++ b/examples/tutorial_api_cpp/01_body_from_image_default.cpp @@ -29,8 +29,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/02_whole_body_from_image_default.cpp b/examples/tutorial_api_cpp/02_whole_body_from_image_default.cpp index 8e04ae89..a8fd6706 100644 --- a/examples/tutorial_api_cpp/02_whole_body_from_image_default.cpp +++ b/examples/tutorial_api_cpp/02_whole_body_from_image_default.cpp @@ -29,8 +29,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/03_keypoints_from_image.cpp b/examples/tutorial_api_cpp/03_keypoints_from_image.cpp index d5eec836..1dcacc34 100644 --- a/examples/tutorial_api_cpp/03_keypoints_from_image.cpp +++ b/examples/tutorial_api_cpp/03_keypoints_from_image.cpp @@ -31,8 +31,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/04_keypoints_from_images.cpp b/examples/tutorial_api_cpp/04_keypoints_from_images.cpp index 80b80296..67ea5d6a 100644 --- a/examples/tutorial_api_cpp/04_keypoints_from_images.cpp +++ b/examples/tutorial_api_cpp/04_keypoints_from_images.cpp @@ -31,7 +31,10 @@ bool display(const std::shared_ptr>>& dat { // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + if (!cvMat.empty()) + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/05_keypoints_from_images_multi_gpu.cpp b/examples/tutorial_api_cpp/05_keypoints_from_images_multi_gpu.cpp index 20442a54..aa7537ac 100644 --- a/examples/tutorial_api_cpp/05_keypoints_from_images_multi_gpu.cpp +++ b/examples/tutorial_api_cpp/05_keypoints_from_images_multi_gpu.cpp @@ -37,7 +37,10 @@ bool display(const std::shared_ptr>>& dat { // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + if (!cvMat.empty()) + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/06_face_from_image.cpp b/examples/tutorial_api_cpp/06_face_from_image.cpp index 273a5083..c0940216 100644 --- a/examples/tutorial_api_cpp/06_face_from_image.cpp +++ b/examples/tutorial_api_cpp/06_face_from_image.cpp @@ -34,8 +34,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/07_hand_from_image.cpp b/examples/tutorial_api_cpp/07_hand_from_image.cpp index b2d67a47..d114e6ce 100644 --- a/examples/tutorial_api_cpp/07_hand_from_image.cpp +++ b/examples/tutorial_api_cpp/07_hand_from_image.cpp @@ -34,8 +34,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/08_heatmaps_from_image.cpp b/examples/tutorial_api_cpp/08_heatmaps_from_image.cpp index e1b5c451..b5dc52ee 100644 --- a/examples/tutorial_api_cpp/08_heatmaps_from_image.cpp +++ b/examples/tutorial_api_cpp/08_heatmaps_from_image.cpp @@ -57,7 +57,10 @@ bool display( cv::applyColorMap(desiredChannelHeatMapUint8, desiredChannelHeatMapUint8, cv::COLORMAP_JET); cv::addWeighted(netInputImageUint8, 0.5, desiredChannelHeatMapUint8, 0.5, 0., imageToRender); // Display image - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", imageToRender); + if (!imageToRender.empty()) + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", imageToRender); + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/09_keypoints_from_heatmaps.cpp b/examples/tutorial_api_cpp/09_keypoints_from_heatmaps.cpp index 152bf3f1..11e63f69 100644 --- a/examples/tutorial_api_cpp/09_keypoints_from_heatmaps.cpp +++ b/examples/tutorial_api_cpp/09_keypoints_from_heatmaps.cpp @@ -34,8 +34,13 @@ void display(const std::shared_ptr>>& dat { // Display image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - cv::waitKey(0); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + cv::waitKey(0); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/12_asynchronous_custom_output.cpp b/examples/tutorial_api_cpp/12_asynchronous_custom_output.cpp index ee16e363..5aa7276e 100644 --- a/examples/tutorial_api_cpp/12_asynchronous_custom_output.cpp +++ b/examples/tutorial_api_cpp/12_asynchronous_custom_output.cpp @@ -28,7 +28,10 @@ public: { // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + if (!cvMat.empty()) + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/13_asynchronous_custom_input_output_and_datum.cpp b/examples/tutorial_api_cpp/13_asynchronous_custom_input_output_and_datum.cpp index e823f288..4e086794 100644 --- a/examples/tutorial_api_cpp/13_asynchronous_custom_input_output_and_datum.cpp +++ b/examples/tutorial_api_cpp/13_asynchronous_custom_input_output_and_datum.cpp @@ -110,7 +110,10 @@ public: { // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + if (!cvMat.empty()) + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + else + op::opLog("Empty cv::Mat as output.", op::Priority::High); } else op::opLog("Nullptr or empty datumsPtr found.", op::Priority::High); diff --git a/examples/tutorial_api_cpp/17_synchronous_custom_output.cpp b/examples/tutorial_api_cpp/17_synchronous_custom_output.cpp index 114fe446..68e3c42a 100644 --- a/examples/tutorial_api_cpp/17_synchronous_custom_output.cpp +++ b/examples/tutorial_api_cpp/17_synchronous_custom_output.cpp @@ -82,11 +82,16 @@ public: { // Display rendered output image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) - const char key = (char)cv::waitKey(1); - if (key == 27) - this->stop(); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) + const char key = (char)cv::waitKey(1); + if (key == 27) + this->stop(); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } } } diff --git a/examples/tutorial_api_cpp/18_synchronous_custom_all_and_datum.cpp b/examples/tutorial_api_cpp/18_synchronous_custom_all_and_datum.cpp index 1bb26412..76d4efea 100644 --- a/examples/tutorial_api_cpp/18_synchronous_custom_all_and_datum.cpp +++ b/examples/tutorial_api_cpp/18_synchronous_custom_all_and_datum.cpp @@ -204,11 +204,16 @@ public: { // Display rendered output image const cv::Mat cvMat = OP_OP2CVCONSTMAT(datumsPtr->at(0)->cvOutputData); - cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); - // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) - const char key = (char)cv::waitKey(1); - if (key == 27) - this->stop(); + if (!cvMat.empty()) + { + cv::imshow(OPEN_POSE_NAME_AND_VERSION + " - Tutorial C++ API", cvMat); + // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) + const char key = (char)cv::waitKey(1); + if (key == 27) + this->stop(); + } + else + op::opLog("Empty cv::Mat as output.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__); } } } -- GitLab