From 29ea7e24dce4abae30faecf769855823ad7bb637 Mon Sep 17 00:00:00 2001 From: gineshidalgo99 Date: Sun, 1 Apr 2018 19:49:19 -0400 Subject: [PATCH] Face/hand working with any output resolution --- doc/release_notes.md | 2 ++ include/openpose/face/faceDetector.hpp | 2 +- include/openpose/face/wFaceDetector.hpp | 2 +- include/openpose/hand/handDetector.hpp | 4 ++-- include/openpose/hand/wHandDetector.hpp | 2 +- .../openpose/hand/wHandDetectorTracking.hpp | 2 +- src/openpose/face/faceDetector.cpp | 21 ++++++++++++------- src/openpose/hand/handDetector.cpp | 8 +++---- src/openpose/producer/spinnakerWrapper.cpp | 18 +++------------- 9 files changed, 28 insertions(+), 33 deletions(-) diff --git a/doc/release_notes.md b/doc/release_notes.md index bfe45a85..0dcea54e 100644 --- a/doc/release_notes.md +++ b/doc/release_notes.md @@ -215,7 +215,9 @@ OpenPose Library - Release Notes 1. Main improvements: 1. Flir cameras: Added software trigger and a dedicated thread to keep reading images to remove latency (analogously to webcamReader). 2. Functions or parameters renamed: + 1. Removed scale parameter from hand and face rectangle extractor (causing wrong results if custom `--output_resolution`). 3. Main bugs fixed: + 1. Hand and face work properly again with any `--output_resolution`. diff --git a/include/openpose/face/faceDetector.hpp b/include/openpose/face/faceDetector.hpp index 4482a779..70e6138a 100644 --- a/include/openpose/face/faceDetector.hpp +++ b/include/openpose/face/faceDetector.hpp @@ -11,7 +11,7 @@ namespace op public: explicit FaceDetector(const PoseModel poseModel); - std::vector> detectFaces(const Array& poseKeypoints, const double scaleInputToOutput) const; + std::vector> detectFaces(const Array& poseKeypoints) const; private: const unsigned int mNeck; diff --git a/include/openpose/face/wFaceDetector.hpp b/include/openpose/face/wFaceDetector.hpp index 7a6aa353..e0a31911 100644 --- a/include/openpose/face/wFaceDetector.hpp +++ b/include/openpose/face/wFaceDetector.hpp @@ -56,7 +56,7 @@ namespace op const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people face for (auto& tDatum : *tDatums) - tDatum.faceRectangles = spFaceDetector->detectFaces(tDatum.poseKeypoints, tDatum.scaleInputToOutput); + tDatum.faceRectangles = spFaceDetector->detectFaces(tDatum.poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/handDetector.hpp b/include/openpose/hand/handDetector.hpp index 1c98a9e5..0dc28dcf 100644 --- a/include/openpose/hand/handDetector.hpp +++ b/include/openpose/hand/handDetector.hpp @@ -14,9 +14,9 @@ namespace op public: explicit HandDetector(const PoseModel poseModel); - std::vector, 2>> detectHands(const Array& poseKeypoints, const double scaleInputToOutput) const; + std::vector, 2>> detectHands(const Array& poseKeypoints) const; - std::vector, 2>> trackHands(const Array& poseKeypoints, const double scaleInputToOutput); + std::vector, 2>> trackHands(const Array& poseKeypoints); void updateTracker(const std::array, 2>& handKeypoints, const unsigned long long id); diff --git a/include/openpose/hand/wHandDetector.hpp b/include/openpose/hand/wHandDetector.hpp index 65ae21a3..bf5b962e 100644 --- a/include/openpose/hand/wHandDetector.hpp +++ b/include/openpose/hand/wHandDetector.hpp @@ -56,7 +56,7 @@ namespace op const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand for (auto& tDatum : *tDatums) - tDatum.handRectangles = spHandDetector->detectHands(tDatum.poseKeypoints, tDatum.scaleInputToOutput); + tDatum.handRectangles = spHandDetector->detectHands(tDatum.poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/include/openpose/hand/wHandDetectorTracking.hpp b/include/openpose/hand/wHandDetectorTracking.hpp index 0ec1cd84..e6f6d5a6 100644 --- a/include/openpose/hand/wHandDetectorTracking.hpp +++ b/include/openpose/hand/wHandDetectorTracking.hpp @@ -56,7 +56,7 @@ namespace op const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__); // Detect people hand for (auto& tDatum : *tDatums) - tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints, tDatum.scaleInputToOutput); + tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints); // Profiling speed Profiler::timerEnd(profilerKey); Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__); diff --git a/src/openpose/face/faceDetector.cpp b/src/openpose/face/faceDetector.cpp index 84a425b7..18f2e495 100644 --- a/src/openpose/face/faceDetector.cpp +++ b/src/openpose/face/faceDetector.cpp @@ -15,9 +15,11 @@ namespace op { } - inline Rectangle getFaceFromPoseKeypoints(const Array& poseKeypoints, const unsigned int personIndex, const unsigned int neck, - const unsigned int headNose, const unsigned int lEar, const unsigned int rEar, - const unsigned int lEye, const unsigned int rEye, const float threshold) + inline Rectangle getFaceFromPoseKeypoints(const Array& poseKeypoints, const unsigned int personIndex, + const unsigned int neck, const unsigned int headNose, + const unsigned int lEar, const unsigned int rEar, + const unsigned int lEye, const unsigned int rEye, + const float threshold) { try { @@ -58,13 +60,17 @@ namespace op { pointTopLeft.x += (posePtr[lEye*3] + posePtr[lEar*3] + posePtr[headNose*3]) / 3.f; pointTopLeft.y += (posePtr[lEye*3+1] + posePtr[lEar*3+1] + posePtr[headNose*3+1]) / 3.f; - faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, lEye) + getDistance(poseKeypoints, personIndex, headNose, lEar) + getDistance(poseKeypoints, personIndex, neck, headNose)); + faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, lEye) + + getDistance(poseKeypoints, personIndex, headNose, lEar) + + getDistance(poseKeypoints, personIndex, neck, headNose)); } else // if(lEyeScoreAbove) { pointTopLeft.x += (posePtr[rEye*3] + posePtr[rEar*3] + posePtr[headNose*3]) / 3.f; pointTopLeft.y += (posePtr[rEye*3+1] + posePtr[rEar*3+1] + posePtr[headNose*3+1]) / 3.f; - faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, rEye) + getDistance(poseKeypoints, personIndex, headNose, rEar) + getDistance(poseKeypoints, personIndex, neck, headNose)); + faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, rEye) + + getDistance(poseKeypoints, personIndex, headNose, rEar) + + getDistance(poseKeypoints, personIndex, neck, headNose)); } } // else --> 2 * dist(neck, headNose) @@ -108,7 +114,7 @@ namespace op } } - std::vector> FaceDetector::detectFaces(const Array& poseKeypoints, const double scaleInputToOutput) const + std::vector> FaceDetector::detectFaces(const Array& poseKeypoints) const { try { @@ -119,7 +125,8 @@ namespace op // Otherwise, get face position(s) if (!poseKeypoints.empty()) for (auto person = 0 ; person < numberPeople ; person++) - faceRectangles.at(person) = getFaceFromPoseKeypoints(poseKeypoints, person, mNeck, mNose, mLEar, mREar, mLEye, mREye, threshold) / (float)scaleInputToOutput; + faceRectangles.at(person) = getFaceFromPoseKeypoints( + poseKeypoints, person, mNeck, mNose, mLEar, mREar, mLEye, mREye, threshold); return faceRectangles; } catch (const std::exception& e) diff --git a/src/openpose/hand/handDetector.cpp b/src/openpose/hand/handDetector.cpp index 919b2353..fd458fac 100644 --- a/src/openpose/hand/handDetector.cpp +++ b/src/openpose/hand/handDetector.cpp @@ -130,7 +130,7 @@ namespace op { } - std::vector, 2>> HandDetector::detectHands(const Array& poseKeypoints, const double scaleInputToOutput) const + std::vector, 2>> HandDetector::detectHands(const Array& poseKeypoints) const { try { @@ -148,8 +148,6 @@ namespace op mPoseIndexes[(int)PosePart::LShoulder], mPoseIndexes[(int)PosePart::RWrist], mPoseIndexes[(int)PosePart::RElbow], mPoseIndexes[(int)PosePart::RShoulder], threshold ); - handRectangles.at(person).at(0) /= (float) scaleInputToOutput; - handRectangles.at(person).at(1) /= (float) scaleInputToOutput; } } return handRectangles; @@ -161,13 +159,13 @@ namespace op } } - std::vector, 2>> HandDetector::trackHands(const Array& poseKeypoints, const double scaleInputToOutput) + std::vector, 2>> HandDetector::trackHands(const Array& poseKeypoints) { try { std::lock_guard lock{mMutex}; // Baseline detectHands - auto handRectangles = detectHands(poseKeypoints, scaleInputToOutput); + auto handRectangles = detectHands(poseKeypoints); // If previous hands saved for (auto& handRectangle : handRectangles) { diff --git a/src/openpose/producer/spinnakerWrapper.cpp b/src/openpose/producer/spinnakerWrapper.cpp index 66e2e4d5..507f5727 100644 --- a/src/openpose/producer/spinnakerWrapper.cpp +++ b/src/openpose/producer/spinnakerWrapper.cpp @@ -354,8 +354,10 @@ namespace op } if (imagesExtracted) { - const std::lock_guard lock{mBufferMutex}; + std::unique_lock lock{mBufferMutex}; std::swap(mBuffer, imagePtrs); + lock.unlock(); + std::this_thread::sleep_for(std::chrono::microseconds{1}); } } } @@ -408,23 +410,9 @@ namespace op std::this_thread::sleep_for(std::chrono::microseconds{5}); } } - // Commented code was supposed to clean buffer, but `NewestFirstOverwrite` does that // Getting frames // Retrieve next received image and ensure image completion // Spinnaker::ImagePtr imagePtr = cameraPtrs.at(i)->GetNextImage(); - // Clean buffer + retrieve next received image + ensure image completion - // auto durationMs = 0.; - // // for (auto counter = 0 ; counter < 10 ; counter++) - // while (durationMs < 1.) - // { - // const auto begin = std::chrono::high_resolution_clock::now(); - // for (auto i = 0u; i < cameraPtrs.size(); i++) - // imagePtrs.at(i) = cameraPtrs.at(i)->GetNextImage(); - // durationMs = std::chrono::duration_cast( - // std::chrono::high_resolution_clock::now()-begin - // ).count() * 1e-6; - // // log("Time extraction (ms): " + std::to_string(durationMs), Priority::High); - // } // All images completed bool imagesExtracted = true; -- GitLab