Skip to content

Commit 29ea7e2

Browse files
Face/hand working with any output resolution
1 parent a203249 commit 29ea7e2

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

doc/release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ OpenPose Library - Release Notes
215215
1. Main improvements:
216216
1. Flir cameras: Added software trigger and a dedicated thread to keep reading images to remove latency (analogously to webcamReader).
217217
2. Functions or parameters renamed:
218+
1. Removed scale parameter from hand and face rectangle extractor (causing wrong results if custom `--output_resolution`).
218219
3. Main bugs fixed:
220+
1. Hand and face work properly again with any `--output_resolution`.
219221

220222

221223

include/openpose/face/faceDetector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace op
1111
public:
1212
explicit FaceDetector(const PoseModel poseModel);
1313

14-
std::vector<Rectangle<float>> detectFaces(const Array<float>& poseKeypoints, const double scaleInputToOutput) const;
14+
std::vector<Rectangle<float>> detectFaces(const Array<float>& poseKeypoints) const;
1515

1616
private:
1717
const unsigned int mNeck;

include/openpose/face/wFaceDetector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace op
5656
const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
5757
// Detect people face
5858
for (auto& tDatum : *tDatums)
59-
tDatum.faceRectangles = spFaceDetector->detectFaces(tDatum.poseKeypoints, tDatum.scaleInputToOutput);
59+
tDatum.faceRectangles = spFaceDetector->detectFaces(tDatum.poseKeypoints);
6060
// Profiling speed
6161
Profiler::timerEnd(profilerKey);
6262
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);

include/openpose/hand/handDetector.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace op
1414
public:
1515
explicit HandDetector(const PoseModel poseModel);
1616

17-
std::vector<std::array<Rectangle<float>, 2>> detectHands(const Array<float>& poseKeypoints, const double scaleInputToOutput) const;
17+
std::vector<std::array<Rectangle<float>, 2>> detectHands(const Array<float>& poseKeypoints) const;
1818

19-
std::vector<std::array<Rectangle<float>, 2>> trackHands(const Array<float>& poseKeypoints, const double scaleInputToOutput);
19+
std::vector<std::array<Rectangle<float>, 2>> trackHands(const Array<float>& poseKeypoints);
2020

2121
void updateTracker(const std::array<Array<float>, 2>& handKeypoints, const unsigned long long id);
2222

include/openpose/hand/wHandDetector.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace op
5656
const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
5757
// Detect people hand
5858
for (auto& tDatum : *tDatums)
59-
tDatum.handRectangles = spHandDetector->detectHands(tDatum.poseKeypoints, tDatum.scaleInputToOutput);
59+
tDatum.handRectangles = spHandDetector->detectHands(tDatum.poseKeypoints);
6060
// Profiling speed
6161
Profiler::timerEnd(profilerKey);
6262
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);

include/openpose/hand/wHandDetectorTracking.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace op
5656
const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
5757
// Detect people hand
5858
for (auto& tDatum : *tDatums)
59-
tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints, tDatum.scaleInputToOutput);
59+
tDatum.handRectangles = spHandDetector->trackHands(tDatum.poseKeypoints);
6060
// Profiling speed
6161
Profiler::timerEnd(profilerKey);
6262
Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);

src/openpose/face/faceDetector.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ namespace op
1515
{
1616
}
1717

18-
inline Rectangle<float> getFaceFromPoseKeypoints(const Array<float>& poseKeypoints, const unsigned int personIndex, const unsigned int neck,
19-
const unsigned int headNose, const unsigned int lEar, const unsigned int rEar,
20-
const unsigned int lEye, const unsigned int rEye, const float threshold)
18+
inline Rectangle<float> getFaceFromPoseKeypoints(const Array<float>& poseKeypoints, const unsigned int personIndex,
19+
const unsigned int neck, const unsigned int headNose,
20+
const unsigned int lEar, const unsigned int rEar,
21+
const unsigned int lEye, const unsigned int rEye,
22+
const float threshold)
2123
{
2224
try
2325
{
@@ -58,13 +60,17 @@ namespace op
5860
{
5961
pointTopLeft.x += (posePtr[lEye*3] + posePtr[lEar*3] + posePtr[headNose*3]) / 3.f;
6062
pointTopLeft.y += (posePtr[lEye*3+1] + posePtr[lEar*3+1] + posePtr[headNose*3+1]) / 3.f;
61-
faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, lEye) + getDistance(poseKeypoints, personIndex, headNose, lEar) + getDistance(poseKeypoints, personIndex, neck, headNose));
63+
faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, lEye)
64+
+ getDistance(poseKeypoints, personIndex, headNose, lEar)
65+
+ getDistance(poseKeypoints, personIndex, neck, headNose));
6266
}
6367
else // if(lEyeScoreAbove)
6468
{
6569
pointTopLeft.x += (posePtr[rEye*3] + posePtr[rEar*3] + posePtr[headNose*3]) / 3.f;
6670
pointTopLeft.y += (posePtr[rEye*3+1] + posePtr[rEar*3+1] + posePtr[headNose*3+1]) / 3.f;
67-
faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, rEye) + getDistance(poseKeypoints, personIndex, headNose, rEar) + getDistance(poseKeypoints, personIndex, neck, headNose));
71+
faceSize += 0.85f * (getDistance(poseKeypoints, personIndex, headNose, rEye)
72+
+ getDistance(poseKeypoints, personIndex, headNose, rEar)
73+
+ getDistance(poseKeypoints, personIndex, neck, headNose));
6874
}
6975
}
7076
// else --> 2 * dist(neck, headNose)
@@ -108,7 +114,7 @@ namespace op
108114
}
109115
}
110116

111-
std::vector<Rectangle<float>> FaceDetector::detectFaces(const Array<float>& poseKeypoints, const double scaleInputToOutput) const
117+
std::vector<Rectangle<float>> FaceDetector::detectFaces(const Array<float>& poseKeypoints) const
112118
{
113119
try
114120
{
@@ -119,7 +125,8 @@ namespace op
119125
// Otherwise, get face position(s)
120126
if (!poseKeypoints.empty())
121127
for (auto person = 0 ; person < numberPeople ; person++)
122-
faceRectangles.at(person) = getFaceFromPoseKeypoints(poseKeypoints, person, mNeck, mNose, mLEar, mREar, mLEye, mREye, threshold) / (float)scaleInputToOutput;
128+
faceRectangles.at(person) = getFaceFromPoseKeypoints(
129+
poseKeypoints, person, mNeck, mNose, mLEar, mREar, mLEye, mREye, threshold);
123130
return faceRectangles;
124131
}
125132
catch (const std::exception& e)

src/openpose/hand/handDetector.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ namespace op
130130
{
131131
}
132132

133-
std::vector<std::array<Rectangle<float>, 2>> HandDetector::detectHands(const Array<float>& poseKeypoints, const double scaleInputToOutput) const
133+
std::vector<std::array<Rectangle<float>, 2>> HandDetector::detectHands(const Array<float>& poseKeypoints) const
134134
{
135135
try
136136
{
@@ -148,8 +148,6 @@ namespace op
148148
mPoseIndexes[(int)PosePart::LShoulder], mPoseIndexes[(int)PosePart::RWrist],
149149
mPoseIndexes[(int)PosePart::RElbow], mPoseIndexes[(int)PosePart::RShoulder], threshold
150150
);
151-
handRectangles.at(person).at(0) /= (float) scaleInputToOutput;
152-
handRectangles.at(person).at(1) /= (float) scaleInputToOutput;
153151
}
154152
}
155153
return handRectangles;
@@ -161,13 +159,13 @@ namespace op
161159
}
162160
}
163161

164-
std::vector<std::array<Rectangle<float>, 2>> HandDetector::trackHands(const Array<float>& poseKeypoints, const double scaleInputToOutput)
162+
std::vector<std::array<Rectangle<float>, 2>> HandDetector::trackHands(const Array<float>& poseKeypoints)
165163
{
166164
try
167165
{
168166
std::lock_guard<std::mutex> lock{mMutex};
169167
// Baseline detectHands
170-
auto handRectangles = detectHands(poseKeypoints, scaleInputToOutput);
168+
auto handRectangles = detectHands(poseKeypoints);
171169
// If previous hands saved
172170
for (auto& handRectangle : handRectangles)
173171
{

src/openpose/producer/spinnakerWrapper.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ namespace op
354354
}
355355
if (imagesExtracted)
356356
{
357-
const std::lock_guard<std::mutex> lock{mBufferMutex};
357+
std::unique_lock<std::mutex> lock{mBufferMutex};
358358
std::swap(mBuffer, imagePtrs);
359+
lock.unlock();
360+
std::this_thread::sleep_for(std::chrono::microseconds{1});
359361
}
360362
}
361363
}
@@ -408,23 +410,9 @@ namespace op
408410
std::this_thread::sleep_for(std::chrono::microseconds{5});
409411
}
410412
}
411-
// Commented code was supposed to clean buffer, but `NewestFirstOverwrite` does that
412413
// Getting frames
413414
// Retrieve next received image and ensure image completion
414415
// Spinnaker::ImagePtr imagePtr = cameraPtrs.at(i)->GetNextImage();
415-
// Clean buffer + retrieve next received image + ensure image completion
416-
// auto durationMs = 0.;
417-
// // for (auto counter = 0 ; counter < 10 ; counter++)
418-
// while (durationMs < 1.)
419-
// {
420-
// const auto begin = std::chrono::high_resolution_clock::now();
421-
// for (auto i = 0u; i < cameraPtrs.size(); i++)
422-
// imagePtrs.at(i) = cameraPtrs.at(i)->GetNextImage();
423-
// durationMs = std::chrono::duration_cast<std::chrono::nanoseconds>(
424-
// std::chrono::high_resolution_clock::now()-begin
425-
// ).count() * 1e-6;
426-
// // log("Time extraction (ms): " + std::to_string(durationMs), Priority::High);
427-
// }
428416

429417
// All images completed
430418
bool imagesExtracted = true;

0 commit comments

Comments
 (0)