AzureKinectIRImageProvider.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::AzureKinectIRImageProvider
17  * @author Christoph Pohl <christoph.pohl@kit.edu>
18  * @author Christian R. G. Dreher <c.dreher@kit.edu>
19  * @date 2019
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 
25 #pragma once
26 
27 #include <chrono>
28 #include <condition_variable>
29 #include <mutex>
30 
31 #include <Eigen/Core>
32 
33 #include <opencv2/opencv.hpp>
34 
38 #include <ArmarXCore/interface/observers/ObserverInterface.h>
39 
40 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
41 
44 #include <VisionX/interface/components/RGBDImageProvider.h>
46 
47 #include <k4a/k4a.h>
48 #include <k4a/k4a.hpp>
49 
50 
51 namespace visionx
52 {
53  /// @class AzureKinectIRImageProviderPropertyDefinitions
56  {
57  public:
59  };
60 
61 
62  /**
63  * @defgroup Component-AzureKinectIRImageProvider AzureKinectIRImageProvider
64  * @ingroup VisionX-Components
65  * Provides support for Intel RealSense cameras for ArmarX.
66  *
67  * @class AzureKinectIRImageProvider
68  * @ingroup Component-AzureKinectIRImageProvider
69  * @brief Brief description of class AzureKinectIRImageProvider.
70  */
72  virtual public visionx::StereoCalibrationCaptureProviderInterface,
73  virtual public visionx::CapturingImageProvider
74  {
75  public:
76  /**
77  * @see armarx::ManagedIceObject::getDefaultName()
78  */
79  virtual std::string getDefaultName() const override;
80 
81  std::string getReferenceFrame(const Ice::Current& current) override;
82 
83  StereoCalibration getStereoCalibration(const Ice::Current& current) override;
84 
85  bool getImagesAreUndistorted(const Ice::Current& current) override;
86 
87  protected:
88 
89  /**
90  * @see PropertyUser::createPropertyDefinitions()
91  */
93 
94  // ManagedIceObject interface
95 
96  protected:
97  bool hasSharedMemorySupport(const Ice::Current& c = Ice::emptyCurrent) override
98  {
99  return true;
100  }
101 
102  void onInitCapturingImageProvider() override;
103 
104  void onExitCapturingImageProvider() override;
105 
106  void onStartCapture(float frames_per_second) override;
107 
108  void onStopCapture() override;
109 
110  bool capture(void** pp_image_buffers) override;
111 
112  // Gets the dimensions of the color images that the color camera will produce for a
113  // given color resolution.
114  static inline std::pair<int, int> GetColorDimensions(const k4a_color_resolution_t resolution)
115  {
116  switch (resolution)
117  {
118  case K4A_COLOR_RESOLUTION_720P:
119  return { 1280, 720 };
120  case K4A_COLOR_RESOLUTION_2160P:
121  return { 3840, 2160 };
122  case K4A_COLOR_RESOLUTION_1440P:
123  return { 2560, 1440 };
124  case K4A_COLOR_RESOLUTION_1080P:
125  return { 1920, 1080 };
126  case K4A_COLOR_RESOLUTION_3072P:
127  return { 4096, 3072 };
128  case K4A_COLOR_RESOLUTION_1536P:
129  return { 2048, 1536 };
130 
131  default:
132  throw std::logic_error("Invalid color dimensions value!");
133  }
134  }
135 
136  // Gets the dimensions of the depth images that the depth camera will produce for a
137  // given depth mode.
138  static inline std::pair<int, int> GetDepthDimensions(const k4a_depth_mode_t depth_mode)
139  {
140  switch (depth_mode)
141  {
142  case K4A_DEPTH_MODE_NFOV_2X2BINNED:
143  return { 320, 288 };
144  case K4A_DEPTH_MODE_NFOV_UNBINNED:
145  return { 640, 576 };
146  case K4A_DEPTH_MODE_WFOV_2X2BINNED:
147  return { 512, 512 };
148  case K4A_DEPTH_MODE_WFOV_UNBINNED:
149  return { 1024, 1024 };
150  case K4A_DEPTH_MODE_PASSIVE_IR:
151  return { 1024, 1024 };
152 
153  default:
154  throw std::logic_error("Invalid depth dimensions value!");
155  }
156  }
157 
158  static std::string VersionToString(const k4a_version_t& version)
159  {
160  std::stringstream s;
161  s << version.major << "." << version.minor << "." << version.iteration;
162  return s.str();
163  }
164 
165  private:
166  visionx::CByteImageUPtr resultIRImage;
167 
168  k4a::device device;
169  k4a_device_configuration_t config;
170  k4a::calibration k4aCalibration;
171  k4a::transformation transformation;
172  std::pair<int, int> depthDim;
173 
174  };
175 }
CapturingPointCloudProvider.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::AzureKinectIRImageProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &current) override
Definition: AzureKinectIRImageProvider.cpp:216
visionx::AzureKinectIRImageProvider::onStopCapture
void onStopCapture() override
This is called when the image provider capturing has been stopped.
Definition: AzureKinectIRImageProvider.cpp:211
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::AzureKinectIRImageProviderPropertyDefinitions::AzureKinectIRImageProviderPropertyDefinitions
AzureKinectIRImageProviderPropertyDefinitions(std::string prefix)
Definition: AzureKinectIRImageProvider.cpp:78
visionx::AzureKinectIRImageProvider::getDefaultName
virtual std::string getDefaultName() const override
Definition: AzureKinectIRImageProvider.cpp:157
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::AzureKinectIRImageProvider::GetColorDimensions
static std::pair< int, int > GetColorDimensions(const k4a_color_resolution_t resolution)
Definition: AzureKinectIRImageProvider.h:114
RunningTask.h
visionx::AzureKinectIRImageProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &current) override
Definition: AzureKinectIRImageProvider.cpp:222
visionx::CByteImageUPtr
std::unique_ptr< CByteImage > CByteImageUPtr
Definition: ImageProvider.h:57
visionx::AzureKinectIRImageProvider::getStereoCalibration
StereoCalibration getStereoCalibration(const Ice::Current &current) override
Definition: AzureKinectIRImageProvider.cpp:228
visionx::AzureKinectIRImageProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: AzureKinectIRImageProvider.cpp:206
visionx::AzureKinectIRImageProvider::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: AzureKinectIRImageProvider.cpp:84
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:106
visionx::CapturingImageProvider
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
Definition: CapturingImageProvider.h:52
visionx::AzureKinectIRImageProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: AzureKinectIRImageProvider.h:97
visionx::AzureKinectIRImageProvider::VersionToString
static std::string VersionToString(const k4a_version_t &version)
Definition: AzureKinectIRImageProvider.h:158
visionx::AzureKinectIRImageProvider::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: AzureKinectIRImageProvider.cpp:163
Component.h
visionx::AzureKinectIRImageProviderPropertyDefinitions
Definition: AzureKinectIRImageProvider.h:54
CapturingImageProvider.h
TimeUtil.h
visionx::AzureKinectIRImageProvider::onStartCapture
void onStartCapture(float frames_per_second) override
This is called when the image provider capturing has been started.
Definition: AzureKinectIRImageProvider.cpp:91
IceUtil::Handle< class PropertyDefinitionContainer >
DepthImageUtils.h
visionx::AzureKinectIRImageProvider::GetDepthDimensions
static std::pair< int, int > GetDepthDimensions(const k4a_depth_mode_t depth_mode)
Definition: AzureKinectIRImageProvider.h:138
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
visionx::AzureKinectIRImageProvider
Brief description of class AzureKinectIRImageProvider.
Definition: AzureKinectIRImageProvider.h:71