OpenPoseEstimationComponent.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::ArmarXObjects::OpenPoseEstimation
17  * @author Stefan Reither ( stef dot reither at web dot de )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 #pragma once
23 
24 // STD/STL
25 #include <mutex>
26 
27 // IVT
28 #include <Image/ByteImage.h>
29 #include <Image/ImageProcessor.h>
30 #include <Math/Math2d.h>
31 #include <Math/Math3d.h>
32 
33 // Simox
34 #include <VirtualRobot/Robot.h>
35 
36 // ArmarX
39 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
43 
44 // OpenPose stuff
45 #include <VisionX/interface/components/OpenPoseEstimationInterface.h>
47 
48 #include "OpenPoseEstimationUtil.h"
49 
50 namespace armarx
51 {
53  public OpenPoseEstimationInterface,
55  {
56  public:
58 
59  // Helper functions
60  virtual void preOnInitImageProcessor();
61  virtual void preOnConnectImageProcessor();
62  virtual void postOnConnectImageProcessor();
63  virtual void preOnDisconnectImageProcessor();
64  virtual void postOnDisconnectImageProcessor();
65 
66  virtual void postCreatePropertyDefinitions(PropertyDefinitionsPtr& properties);
67 
68  // HumanPoseEstimation Interface
69  void enableHumanPoseEstimation(const EnableHumanPoseEstimationInput& input,
70  const Ice::Current& = Ice::emptyCurrent) override;
71 
72  // OpenPoseEstimation Interface
73  void start(const Ice::Current& = Ice::emptyCurrent) override;
74  void stop(const Ice::Current& = Ice::emptyCurrent) override;
75  void start3DPoseEstimation(const Ice::Current& = Ice::emptyCurrent) override;
76  void stop3DPoseEstimation(const Ice::Current& = Ice::emptyCurrent) override;
77 
78  virtual void renderOutputImage(const op::Array<float>&);
79  virtual void reportEntities();
80  virtual void visualize();
81 
82  protected:
83  // main loop
84  void loop();
85 
86  public:
87  bool active_upon_startup = false;
88 
89  // ImageBuffer und ImageInformations
90  CByteImage** imageBuffer;
91  unsigned int numImages;
93  armarx::MetaInfoSizeBasePtr imageMetaInfo;
94  std::mutex imageBufferMutex;
95 
96  visionx::ImageFormatInfo rgbImageFormat;
97  CByteImage* rgbImageBuffer;
98  std::mutex rgbImageBufferMutex;
99 
100  // ErrorCounters
101  std::uint64_t timeoutCounter2d{0};
102  std::uint64_t readErrorCounter2d{0};
103  std::uint64_t sucessCounter2d{0};
104 
105  // Topics
106  OpenPose2DListenerPrx listener2DPrx;
107 
108  // OpenPose Buffers
109  HumanPose2DMap openposeResult;
110 
111  // ImageBuffer und ImageInformations
113  CByteImage** openposeResultImage;
114  std::atomic_bool result_image_ready = false;
115 
116  // OpenPose renderer
118  float op_render_threshold = 0.05f;
120 
123 
124  // Visualization
125  std::string layerName = "OpenPoseEstimation";
126 
127  // Threads and program flow information
129  std::atomic_bool running2D = false;
130  std::atomic_bool update_ready; // Is true, if new updates are available
131  std::atomic_long timestamp_of_update; // Contains the timestamp of the currently available update
132  };
133 }
ArVizComponentPlugin.h
armarx::OpenPoseEstimationComponentPluginUser::openpose_is_initialized
bool openpose_is_initialized
Definition: OpenPoseEstimationComponent.h:119
armarx::OpenPoseEstimationComponentPluginUser::openpose_initializing_mutex
std::mutex openpose_initializing_mutex
Definition: OpenPoseEstimationComponent.h:121
armarx::OpenPoseEstimationComponentPluginUser::OpenPoseEstimationComponentPluginUser
OpenPoseEstimationComponentPluginUser()
Definition: OpenPoseEstimationComponent.cpp:94
armarx::OpenPoseEstimationComponentPluginUser::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: OpenPoseEstimationComponent.h:93
armarx::OpenPoseEstimationComponentPluginUser::update_ready
std::atomic_bool update_ready
Definition: OpenPoseEstimationComponent.h:130
armarx::OpenPoseEstimationComponentPluginUser::rgbImageBuffer
CByteImage * rgbImageBuffer
Definition: OpenPoseEstimationComponent.h:97
armarx::OpenPoseEstimationComponentPluginUser::active_upon_startup
bool active_upon_startup
Definition: OpenPoseEstimationComponent.h:87
armarx::OpenPoseEstimationComponentPluginUser::preOnDisconnectImageProcessor
virtual void preOnDisconnectImageProcessor()
Definition: OpenPoseEstimationComponent.cpp:85
armarx::MonocularOpenPoseEstimationPtr
std::shared_ptr< OpenPoseAdapter > MonocularOpenPoseEstimationPtr
Definition: OpenPoseAdapter.h:60
armarx::OpenPoseEstimationComponentPluginUser::result_image_ready
std::atomic_bool result_image_ready
Definition: OpenPoseEstimationComponent.h:114
armarx::OpenPoseEstimationComponentPluginUser::sucessCounter2d
std::uint64_t sucessCounter2d
Definition: OpenPoseEstimationComponent.h:103
armarx::OpenPoseEstimationComponentPluginUser::listener2DPrx
OpenPose2DListenerPrx listener2DPrx
Definition: OpenPoseEstimationComponent.h:106
armarx::OpenPoseEstimationComponentPluginUser::layerName
std::string layerName
Definition: OpenPoseEstimationComponent.h:125
armarx::OpenPoseEstimationComponentPluginUser::op_render_threshold
float op_render_threshold
Definition: OpenPoseEstimationComponent.h:118
armarx::OpenPoseEstimationComponentPluginUser::preOnInitImageProcessor
virtual void preOnInitImageProcessor()
Definition: OpenPoseEstimationComponent.cpp:70
RunningTask.h
armarx::OpenPoseEstimationComponentPluginUser::openposeResultImage
CByteImage ** openposeResultImage
Definition: OpenPoseEstimationComponent.h:113
armarx::OpenPoseEstimationComponentPluginUser::start
void start(const Ice::Current &=Ice::emptyCurrent) override
Definition: OpenPoseEstimationComponent.cpp:168
visionx::ImageProviderInfo
Definition: ImageProcessor.h:466
armarx::OpenPoseEstimationComponentPluginUser::readErrorCounter2d
std::uint64_t readErrorCounter2d
Definition: OpenPoseEstimationComponent.h:102
armarx::OpenPoseEstimationComponentPluginUser::start3DPoseEstimation
void start3DPoseEstimation(const Ice::Current &=Ice::emptyCurrent) override
Definition: OpenPoseEstimationComponent.cpp:196
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:36
armarx::OpenPoseEstimationComponentPluginUser::loop
void loop()
Definition: OpenPoseEstimationComponent.cpp:116
ImageProcessor.h
armarx::OpenPoseEstimationComponentPluginUser::stop
void stop(const Ice::Current &=Ice::emptyCurrent) override
Definition: OpenPoseEstimationComponent.cpp:183
armarx::OpenPoseEstimationComponentPluginUser::numImages
unsigned int numImages
Definition: OpenPoseEstimationComponent.h:91
armarx::OpenPoseEstimationComponentPluginUser::timestamp_of_update
std::atomic_long timestamp_of_update
Definition: OpenPoseEstimationComponent.h:131
armarx::OpenPoseEstimationComponentPluginUser::openposeTask
armarx::RunningTask< OpenPoseEstimationComponentPluginUser >::pointer_type openposeTask
Definition: OpenPoseEstimationComponent.h:128
armarx::OpenPoseAdapter::OpenPoseSettings
Definition: OpenPoseAdapter.h:66
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::OpenPoseEstimationComponentPluginUser::postOnConnectImageProcessor
virtual void postOnConnectImageProcessor()
Definition: OpenPoseEstimationComponent.cpp:62
OpenPoseEstimationUtil.h
armarx::OpenPoseEstimationComponentPluginUser::running2D
std::atomic_bool running2D
Definition: OpenPoseEstimationComponent.h:129
armarx::OpenPoseEstimationComponentPluginUser::timeoutCounter2d
std::uint64_t timeoutCounter2d
Definition: OpenPoseEstimationComponent.h:101
OpenPoseAdapter.h
armarx::OpenPoseEstimationComponentPluginUser::openposeResultImageMutex
std::mutex openposeResultImageMutex
Definition: OpenPoseEstimationComponent.h:112
armarx::OpenPoseEstimationComponentPluginUser::imageProviderInfo
visionx::ImageProviderInfo imageProviderInfo
Definition: OpenPoseEstimationComponent.h:92
armarx::OpenPoseEstimationComponentPluginUser::rgbImageBufferMutex
std::mutex rgbImageBufferMutex
Definition: OpenPoseEstimationComponent.h:98
armarx::OpenPoseEstimationComponentPluginUser::stop3DPoseEstimation
void stop3DPoseEstimation(const Ice::Current &=Ice::emptyCurrent) override
Definition: OpenPoseEstimationComponent.cpp:201
armarx::OpenPoseEstimationComponentPluginUser::postOnDisconnectImageProcessor
virtual void postOnDisconnectImageProcessor()
Definition: OpenPoseEstimationComponent.cpp:80
armarx::OpenPoseEstimationComponentPluginUser
Definition: OpenPoseEstimationComponent.h:52
armarx::OpenPoseEstimationComponentPluginUser::renderOutputImage
virtual void renderOutputImage(const op::Array< float > &)
Definition: OpenPoseEstimationComponent.cpp:98
armarx::OpenPoseEstimationComponentPluginUser::openposeResult
HumanPose2DMap openposeResult
Definition: OpenPoseEstimationComponent.h:109
armarx::OpenPoseEstimationComponentPluginUser::reportEntities
virtual void reportEntities()
Definition: OpenPoseEstimationComponent.cpp:103
armarx::OpenPoseEstimationComponentPluginUser::visualize
virtual void visualize()
Definition: OpenPoseEstimationComponent.cpp:109
armarx::OpenPoseEstimationComponentPluginUser::rgbImageFormat
visionx::ImageFormatInfo rgbImageFormat
Definition: OpenPoseEstimationComponent.h:96
armarx::OpenPoseEstimationComponentPluginUser::preOnConnectImageProcessor
virtual void preOnConnectImageProcessor()
Definition: OpenPoseEstimationComponent.cpp:75
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::OpenPoseEstimationComponentPluginUser::imageBuffer
CByteImage ** imageBuffer
Definition: OpenPoseEstimationComponent.h:90
armarx::OpenPoseEstimationComponentPluginUser::openposePtr
MonocularOpenPoseEstimationPtr openposePtr
Definition: OpenPoseEstimationComponent.h:122
armarx::OpenPoseEstimationComponentPluginUser::imageBufferMutex
std::mutex imageBufferMutex
Definition: OpenPoseEstimationComponent.h:94
ComponentPlugin.h
armarx::OpenPoseEstimationComponentPluginUser::enableHumanPoseEstimation
void enableHumanPoseEstimation(const EnableHumanPoseEstimationInput &input, const Ice::Current &=Ice::emptyCurrent) override
Definition: OpenPoseEstimationComponent.cpp:206
armarx::OpenPoseEstimationComponentPluginUser::op_settings
OpenPoseAdapter::OpenPoseSettings op_settings
Definition: OpenPoseEstimationComponent.h:117
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::OpenPoseEstimationComponentPluginUser::postCreatePropertyDefinitions
virtual void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties)
Definition: OpenPoseEstimationComponent.cpp:32
RobotStateComponent.h