From 616ba21d10934fc587489401ab647d4d2dc3c28d Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Fri, 1 Sep 2017 14:55:22 -0400 Subject: [PATCH] Coco JSON extractor now working any coco folder --- doc/release_notes.md | 18 +++++++++++------- examples/tests/pose_accuracy_coco_test.sh | 2 +- include/openpose/filestream/cocoJsonSaver.hpp | 2 +- include/openpose/filestream/wCocoJsonSaver.hpp | 6 +----- include/openpose/utilities/string.hpp | 2 ++ src/openpose/filestream/cocoJsonSaver.cpp | 4 +++- src/openpose/utilities/string.cpp | 14 ++++++++++++++ 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/doc/release_notes.md b/doc/release_notes.md index ddb66d66..8c5ed870 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -85,13 +85,17 @@ OpenPose Library - Release Notes ## Current version (future OpenPose 1.0.2) 1. Main improvements: - 1. Caffe turned into DLL library. - 2. OpenPose is now completely portable across Windows 10 computers (with Nvidia graphic card). - 3. Added OpenPose 1.0.1 portable demo. - 4. Removed Python and some unnecessary boost dependencies on the VS project. - 5. Replaced all double quotes by angle brackets in include statements (issue #61). - 6. Added 3-D reconstruction demo. - 7. Auto-detection of the camera index. + 1. Added OpenCV 3.3 compatibility. + 2. Caffe turned into DLL library. + 3. OpenPose is now completely portable across Windows 10 computers (with Nvidia graphic card). + 4. Added OpenPose 1.0.1 portable demo. + 5. Removed Python and some unnecessary boost dependencies on the VS project. + 6. Replaced all double quotes by angle brackets in include statements (issue #61). + 7. Added 3-D reconstruction demo. + 8. Auto-detection of the camera index. + 9. Speed up of ~30% in op::floatPtrToUCharCvMat. + 10. COCO extractor now extracts image ID from the image name itslef (format "string_%d"). Before, only working with validation test, now applicable to e.g. test sets. + 11. Changed display texts, added `OpenPose` name. 2. Main bugs fixed: 1. Pycaffe can now be imported from Python. 2. Fixed `Tutorial/Wrapper` VS linking errors. diff --git a/examples/tests/pose_accuracy_coco_test.sh b/examples/tests/pose_accuracy_coco_test.sh index 21f35055..6d404d9c 100644 --- a/examples/tests/pose_accuracy_coco_test.sh +++ b/examples/tests/pose_accuracy_coco_test.sh @@ -19,7 +19,7 @@ # ./build/examples/openpose/openpose.bin --image_dir "/home/gines/devel/images/val2014" --write_coco_json ../evaluation/coco/results/openpose/1_3.json --no_display --render_pose 0 --scale_number 3 --scale_gap 0.25 --frame_last 3558 # # 4 scales -# ./build/examples/openpose/openpose.bin --num_gpu 1 --image_dir "/home/gines/devel/images/val2014" --write_coco_json ../evaluation/coco/results/openpose/1_4.json --no_display --render_pose 0 --scale_number 4 --scale_gap 0.25 --net_resolution "1312x736" --frame_last 3558 +# ./build/examples/openpose/openpose.bin --num_gpu 1 --image_dir "/home/gines/devel/images/val2014" --write_coco_json ../evaluation/coco/results/openpose/1_4.json --no_display --render_pose 0 --num_gpu 1 --scale_number 4 --scale_gap 0.25 --net_resolution "1312x736" --frame_last 3558 # Debugging - Rendered frames saved # ./build/examples/openpose/openpose.bin --image_dir "/home/gines/devel/images/val2014" --write_images ../evaluation/coco/results/openpose/frameOutput --no_display diff --git a/include/openpose/filestream/cocoJsonSaver.hpp b/include/openpose/filestream/cocoJsonSaver.hpp index a1e03ccb..a0f0c88e 100644 --- a/include/openpose/filestream/cocoJsonSaver.hpp +++ b/include/openpose/filestream/cocoJsonSaver.hpp @@ -20,7 +20,7 @@ namespace op ~CocoJsonSaver(); - void record(const Array& poseKeypoints, const unsigned long long imageId); + void record(const Array& poseKeypoints, const std::string& imageName); private: JsonOfstream mJsonOfstream; diff --git a/include/openpose/filestream/wCocoJsonSaver.hpp b/include/openpose/filestream/wCocoJsonSaver.hpp index 54bc543a..17a74536 100644 --- a/include/openpose/filestream/wCocoJsonSaver.hpp +++ b/include/openpose/filestream/wCocoJsonSaver.hpp @@ -60,11 +60,7 @@ namespace op // T* to T const auto& tDatum = tDatums->at(0); // Record json in COCO format - const std::string stringToRemove = "COCO_val2014_"; - const auto stringToRemoveEnd = tDatum.name.find(stringToRemove) + stringToRemove.size(); - const auto imageId = std::stoull(tDatum.name.substr(stringToRemoveEnd, tDatum.name.size() - stringToRemoveEnd)); - // Record json in COCO format if file within desired range of images - spCocoJsonSaver->record(tDatum.poseKeypoints, imageId); + spCocoJsonSaver->record(tDatum.poseKeypoints, tDatum.name); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__, Profiler::DEFAULT_X); diff --git a/include/openpose/utilities/string.hpp b/include/openpose/utilities/string.hpp index 16df3134..3a9cbafd 100644 --- a/include/openpose/utilities/string.hpp +++ b/include/openpose/utilities/string.hpp @@ -5,6 +5,8 @@ namespace op { + OP_API unsigned long long getLastNumber(const std::string& string); + /** * This template function turns an integer number into a fixed-length std::string. * @param number T integer corresponding to the integer to be formatted. diff --git a/src/openpose/filestream/cocoJsonSaver.cpp b/src/openpose/filestream/cocoJsonSaver.cpp index ba0dc2f0..e8870bf6 100644 --- a/src/openpose/filestream/cocoJsonSaver.cpp +++ b/src/openpose/filestream/cocoJsonSaver.cpp @@ -1,3 +1,4 @@ +#include #include namespace op @@ -27,12 +28,13 @@ namespace op } } - void CocoJsonSaver::record(const Array& poseKeypoints, const unsigned long long imageId) + void CocoJsonSaver::record(const Array& poseKeypoints, const std::string& imageName) { try { const auto numberPeople = poseKeypoints.getSize(0); const auto numberBodyParts = poseKeypoints.getSize(1); + const auto imageId = getLastNumber(imageName); for (auto person = 0 ; person < numberPeople ; person++) { // Comma at any moment but first element diff --git a/src/openpose/utilities/string.cpp b/src/openpose/utilities/string.cpp index a15857b0..57432eac 100644 --- a/src/openpose/utilities/string.cpp +++ b/src/openpose/utilities/string.cpp @@ -3,6 +3,20 @@ namespace op { + unsigned long long getLastNumber(const std::string& string) + { + try + { + const auto stringNumber = string.substr(string.find_last_not_of("0123456789") + 1); + return std::stoull(stringNumber); + } + catch (const std::exception& e) + { + error(e.what(), __LINE__, __FUNCTION__, __FILE__); + return 0ull; + } + } + template std::string toFixedLengthString(const T number, const unsigned long long stringLength) { -- GitLab