OpenPose 1.0.0rc2 OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wPeopleJsonSaver.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
2 #define OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
3
4 #include <openpose/core/common.hpp>
5 #include <openpose/filestream/peopleJsonSaver.hpp>
6 #include <openpose/thread/workerConsumer.hpp>
7
8 namespace op
9 {
10 template<typename TDatums>
11 class WPeopleJsonSaver : public WorkerConsumer<TDatums>
12 {
13 public:
14 explicit WPeopleJsonSaver(const std::shared_ptr<PeopleJsonSaver>& peopleJsonSaver);
15
16 virtual ~WPeopleJsonSaver();
17
18 void initializationOnThread();
19
20 void workConsumer(const TDatums& tDatums);
21
22 private:
23 const std::shared_ptr<PeopleJsonSaver> spPeopleJsonSaver;
24
25 DELETE_COPY(WPeopleJsonSaver);
26 };
27 }
28
29
30
31
32
33 // Implementation
34 #include <openpose/utilities/pointerContainer.hpp>
35 namespace op
36 {
37 template<typename TDatums>
38 WPeopleJsonSaver<TDatums>::WPeopleJsonSaver(const std::shared_ptr<PeopleJsonSaver>& peopleJsonSaver) :
39 spPeopleJsonSaver{peopleJsonSaver}
40 {
41 }
42
43 template<typename TDatums>
44 WPeopleJsonSaver<TDatums>::~WPeopleJsonSaver()
45 {
46 }
47
48 template<typename TDatums>
49 void WPeopleJsonSaver<TDatums>::initializationOnThread()
50 {
51 }
52
53 template<typename TDatums>
54 void WPeopleJsonSaver<TDatums>::workConsumer(const TDatums& tDatums)
55 {
56 try
57 {
58 if (checkNoNullNorEmpty(tDatums))
59 {
60 // Debugging log
61 dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
62 // Profiling speed
63 const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
64 // Save body/face/hand keypoints to JSON file
65 const auto& tDatumFirst = (*tDatums)[0];
66 const auto baseFileName = (!tDatumFirst.name.empty() ? tDatumFirst.name
67 : std::to_string(tDatumFirst.id)) + "_keypoints";
68 const bool humanReadable = false;
69 for (auto i = 0u ; i < tDatums->size() ; i++)
70 {
71 const auto& tDatum = (*tDatums)[i];
72 // const auto fileName = baseFileName;
73 const auto fileName = baseFileName + (i != 0 ? "_" + std::to_string(i) : "");
74
75 const std::vector<std::pair<Array<float>, std::string>> keypointVector{
76 // 2D
77 std::make_pair(tDatum.poseKeypoints, "pose_keypoints_2d"),
78 std::make_pair(tDatum.faceKeypoints, "face_keypoints_2d"),
79 std::make_pair(tDatum.handKeypoints[0], "hand_left_keypoints_2d"),
80 std::make_pair(tDatum.handKeypoints[1], "hand_right_keypoints_2d"),
81 // 3D
82 std::make_pair(tDatum.poseKeypoints3D, "pose_keypoints_3d"),
83 std::make_pair(tDatum.faceKeypoints3D, "face_keypoints_3d"),
84 std::make_pair(tDatum.handKeypoints3D[0], "hand_left_keypoints_3d"),
85 std::make_pair(tDatum.handKeypoints3D[1], "hand_right_keypoints_3d")
86 };
87 // Save keypoints
88 spPeopleJsonSaver->save(keypointVector, tDatum.poseCandidates, fileName, humanReadable);
89 }
90 // Profiling speed
91 Profiler::timerEnd(profilerKey);
92 Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
93 // Debugging log
94 dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
95 }
96 }
97 catch (const std::exception& e)
98 {
99 this->stop();
100 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
101 }
102 }
103
104 COMPILE_TEMPLATE_DATUM(WPeopleJsonSaver);
105 }
106
107 #endif // OPENPOSE_FILESTREAM_W_PEOPLE_JSON_SAVER_HPP
op::Priority::Low
op::WorkerConsumer
Definition: workerConsumer.hpp:10
op::WPeopleJsonSaver::initializationOnThread
void initializationOnThread()
Definition: wPeopleJsonSaver.hpp:49
op::WPeopleJsonSaver
Definition: wPeopleJsonSaver.hpp:11
op::WPeopleJsonSaver::WPeopleJsonSaver
WPeopleJsonSaver(const std::shared_ptr< PeopleJsonSaver > &peopleJsonSaver)
Definition: wPeopleJsonSaver.hpp:38
op::WPeopleJsonSaver::~WPeopleJsonSaver
virtual ~WPeopleJsonSaver()
Definition: wPeopleJsonSaver.hpp:44
common.hpp
op::Profiler::timerInit
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
op::error
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
pointerContainer.hpp
peopleJsonSaver.hpp
op::dLog
void dLog(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:53
workerConsumer.hpp
op::checkNoNullNorEmpty
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
Definition: pointerContainer.hpp:7
op::Profiler::printAveragedTimeMsOnIterationX
static void printAveragedTimeMsOnIterationX(const std::string &key, const int line, const std::string &function, const std::string &file, const unsigned long long x=DEFAULT_X)
op::COMPILE_TEMPLATE_DATUM
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
op::Profiler::timerEnd
static void timerEnd(const std::string &key)
op::WPeopleJsonSaver::workConsumer
void workConsumer(const TDatums &tDatums)
Definition: wPeopleJsonSaver.hpp:54
cl::string
std::string string
Definition: cl2.hpp:574