OpenPoseAdapter.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package visionx::MonocularOpenPoseEstimation
17 * @author Fabian Peller <fabian.peller@kit.edu>
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#pragma once
25
26
27// STD/STL
28#include <filesystem>
29#include <memory>
30#include <mutex>
31
32// OpenCV 2
33#include <opencv2/core/core.hpp>
34
35// IVT
36#include <Image/ByteImage.h>
37#include <Math/Math2d.h>
38
39// OpenPose
40#include <openpose/core/headers.hpp>
41#include <openpose/pose/headers.hpp>
42#include <openpose/utilities/headers.hpp>
43
44// ugly hack to check op version. Since 1.6.0 they used custom headers to reduce the amounts of includes (E.g. string or cv2)
45#if __has_include(<openpose/core/string.hpp>)
46#define OP_CUSTOM_STRING_HEADERS = 1
47#endif
48#if __has_include(<openpose/core/matrix.hpp>)
49#define OP_CUSTOM_MATRIX_HEADERS = 1
50#endif
51
52// ArmarX
54
55#include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
56
57#include <VisionX/interface/components/OpenPoseEstimationInterface.h>
59
60namespace armarx
61{
62 class OpenPoseAdapter;
63 typedef std::shared_ptr<OpenPoseAdapter> MonocularOpenPoseEstimationPtr;
64
66 {
67 public:
69 {
70 std::string net_resolution = "-1x368";
71 std::string output_resolution = "-1x-1";
73 std::string model_folder = "models/";
74 double scale_gap = 0.3;
75 int scale_number = 1;
78 };
79
80 public:
82
83#if defined(OP_CUSTOM_STRING_HEADERS)
84 static op::String
85 ConvertToOPCustomType(const std::string& x)
86 {
87 return op::String(x);
88 }
89#else
90 static std::string
91 ConvertToOPCustomType(const std::string& x)
92 {
93 return x;
94 }
95#endif
96
97#if defined(OP_CUSTOM_MATRIX_HEADERS)
98 static op::Matrix
99 ConvertToOPCustomType(const cv::Mat& x)
100 {
101 return op::Matrix(&x);
102 }
103#else
104 static cv::Mat
105 ConvertToOPCustomType(const cv::Mat& x)
106 {
107 return x;
108 }
109#endif
110
111 op::Array<float> getOpenposeKeypoints(const CByteImage* imageBuffer);
112 HumanPose2DMap convert2DKeypointsToIce(const op::Array<float>& op_keypoints,
113 const CByteImage* rgbImage) const;
114
115 std::vector<float> getPoseColors() const;
116 std::vector<unsigned int> getPoseBodyPartPairsRender() const;
117
118 // generate images out of pose
119 void render2DResultImage(const CByteImage& inputImage,
120 const op::Array<float>& keypoints,
121 CByteImage& resultImage,
122 float renderThreshold);
123
124 // get color
125 armarx::DrawColor24Bit
126 getDominantColorOfPatch(const CByteImage& image, const Vec2d& point, int windowSize) const;
127
128 private:
129 void setupOpenPoseEnvironment();
130
131
132 public:
134
135 // OpenPose
137 std::shared_ptr<op::ScaleAndSizeExtractor> scaleAndSizeExtractor;
138 std::shared_ptr<op::CvMatToOpInput> cvMatToOpInput;
139 std::shared_ptr<op::CvMatToOpOutput> cvMatToOpOutput;
140 std::shared_ptr<op::PoseExtractorCaffe> poseExtractorCaffe;
141 std::shared_ptr<op::OpOutputToCvMat> opOutputToCvMat;
142 op::PoseModel poseModel;
143 };
144} // namespace armarx
OpenPoseSettings settings
op::Array< float > getOpenposeKeypoints(const CByteImage *imageBuffer)
std::shared_ptr< op::CvMatToOpInput > cvMatToOpInput
std::shared_ptr< op::ScaleAndSizeExtractor > scaleAndSizeExtractor
std::shared_ptr< op::PoseExtractorCaffe > poseExtractorCaffe
static cv::Mat ConvertToOPCustomType(const cv::Mat &x)
std::shared_ptr< op::OpOutputToCvMat > opOutputToCvMat
OpenPoseAdapter(const OpenPoseSettings &)
void render2DResultImage(const CByteImage &inputImage, const op::Array< float > &keypoints, CByteImage &resultImage, float renderThreshold)
armarx::DrawColor24Bit getDominantColorOfPatch(const CByteImage &image, const Vec2d &point, int windowSize) const
HumanPose2DMap convert2DKeypointsToIce(const op::Array< float > &op_keypoints, const CByteImage *rgbImage) const
static std::string ConvertToOPCustomType(const std::string &x)
std::shared_ptr< op::CvMatToOpOutput > cvMatToOpOutput
std::vector< unsigned int > getPoseBodyPartPairsRender() const
std::vector< float > getPoseColors() const
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< OpenPoseAdapter > MonocularOpenPoseEstimationPtr