Skip to content

Commit 88f3ade

Browse files
Tutorial wrapper: added how to read keypoint data
1 parent 4f81fe5 commit 88f3ade

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

doc/release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ OpenPose Library - Release Notes
104104

105105
## Current version (future OpenPose 1.0.3)
106106
1. Main improvements:
107+
1. Added how to use keypoint data in `examples/tutorial_wrapper/`.
107108
2. Main bugs fixed:
109+
1. Windows version crashing with std::map copy.

examples/tests/speed_test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Script for internal use. We might completely change it continuously and we will not answer questions about it.
2+
3+
# USAGE EXAMPLE
4+
# clear && clear && make all -j24 && bash ./examples/tests/speed_test.sh
5+
6+
# # Go back to main folder
7+
# cd ../../
8+
9+
# Get model speed
10+
~/devel/openpose_caffe_train/build/tools/caffe time -gpu 0 -model /mnt/DataUbuntu/openpose_train/training_results_light/pose/pose_training.prototxt
11+
# ./3rdparty/caffe/build/tools/caffe time -gpu 0 -model /mnt/DataUbuntu/openpose_train/training_results_light/pose/pose_training.prototxt

examples/tutorial_wrapper/1_user_asynchronous.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,37 @@ class UserOutputClass
242242
else
243243
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
244244
}
245+
void printKeypoitns(const std::shared_ptr<std::vector<UserDatum>>& datumsPtr)
246+
{
247+
// Example: How to use the pose keypoints
248+
if (datumsPtr != nullptr && !datumsPtr->empty())
249+
{
250+
op::log("\nKeypoints:");
251+
// Accesing each element of the keypoints
252+
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
253+
op::log("Person pose keypoints:");
254+
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
255+
{
256+
op::log("Person " + std::to_string(person) + " (x, y, score):");
257+
for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
258+
{
259+
std::string valueToPrint;
260+
for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
261+
{
262+
valueToPrint += std::to_string( poseKeypoints[{person, bodyPart, xyscore}] ) + " ";
263+
}
264+
op::log(valueToPrint);
265+
}
266+
}
267+
op::log(" ");
268+
// Alternative: just getting std::string equivalent
269+
op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString());
270+
op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString());
271+
op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString());
272+
}
273+
else
274+
op::log("Nullptr or empty datumsPtr found.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
275+
}
245276
};
246277

247278
int openPoseTutorialWrapper1()
@@ -319,7 +350,10 @@ int openPoseTutorialWrapper1()
319350
// Pop frame
320351
std::shared_ptr<std::vector<UserDatum>> datumProcessed;
321352
if (successfullyEmplaced && opWrapper.waitAndPop(datumProcessed))
353+
{
322354
userOutputClass.display(datumProcessed);
355+
userOutputClass.printKeypoitns(datumProcessed);
356+
}
323357
else
324358
op::log("Processed datum could not be emplaced.", op::Priority::High, __LINE__, __FUNCTION__, __FILE__);
325359
}

examples/tutorial_wrapper/2_user_synchronous.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,31 @@ class WUserOutput : public op::WorkerConsumer<std::shared_ptr<std::vector<UserDa
276276
// datum.poseKeypoints: Array<float> with the estimated pose
277277
if (datumsPtr != nullptr && !datumsPtr->empty())
278278
{
279+
// Show in command line the resulting pose keypoints for body, face and hands
280+
op::log("\nKeypoints:");
281+
// Accesing each element of the keypoints
282+
const auto& poseKeypoints = datumsPtr->at(0).poseKeypoints;
283+
op::log("Person pose keypoints:");
284+
for (auto person = 0 ; person < poseKeypoints.getSize(0) ; person++)
285+
{
286+
op::log("Person " + std::to_string(person) + " (x, y, score):");
287+
for (auto bodyPart = 0 ; bodyPart < poseKeypoints.getSize(1) ; bodyPart++)
288+
{
289+
std::string valueToPrint;
290+
for (auto xyscore = 0 ; xyscore < poseKeypoints.getSize(2) ; xyscore++)
291+
{
292+
valueToPrint += std::to_string( poseKeypoints[{person, bodyPart, xyscore}] ) + " ";
293+
}
294+
op::log(valueToPrint);
295+
}
296+
}
297+
op::log(" ");
298+
// Alternative: just getting std::string equivalent
299+
op::log("Face keypoints: " + datumsPtr->at(0).faceKeypoints.toString());
300+
op::log("Left hand keypoints: " + datumsPtr->at(0).handKeypoints[0].toString());
301+
op::log("Right hand keypoints: " + datumsPtr->at(0).handKeypoints[1].toString());
302+
303+
// Display rendered output image
279304
cv::imshow("User worker GUI", datumsPtr->at(0).cvOutputData);
280305
cv::waitKey(1); // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image)
281306
}

0 commit comments

Comments
 (0)