KLGImageProvider.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::KLGImageProvider
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
27 
28 #include <ArmarXCore/interface/observers/ObserverInterface.h>
29 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
30 
31 #include <Eigen/Core>
32 
33 #include <opencv2/opencv.hpp>
34 
36 #include <VisionX/interface/components/RGBDImageProvider.h>
37 
38 
41 
42 namespace armarx
43 {
44  /**
45  * @class KLGImageProviderPropertyDefinitions
46  * @brief
47  */
50  {
51  public:
54  {
55  defineOptionalProperty<std::string>("DebugObserverName", "DebugObserver", "Name of the topic the DebugObserver listens on");
56  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the DebugDrawerTopic");
57 
58  defineOptionalProperty<std::string>("FileName", "VisionX/examples/point_clouds/", "path to the klg log file");
59  defineOptionalProperty<bool>("Rewind", true, "loop through the point clouds");
60 
61  defineOptionalProperty<Eigen::Vector2i>("Dimensions", Eigen::Vector2i(640, 480), "")
62  .map("320x240", Eigen::Vector2i(320, 240))
63  .map("640x480", Eigen::Vector2i(640, 480))
64  .map("320x240", Eigen::Vector2i(320, 240))
65  .map("640x480", Eigen::Vector2i(640, 480))
66  .map("800x600", Eigen::Vector2i(800, 600))
67  .map("768x576", Eigen::Vector2i(768, 576))
68  .map("1024x768", Eigen::Vector2i(1024, 768))
69  .map("1024x1024", Eigen::Vector2i(1024, 1024))
70  .map("1280x960", Eigen::Vector2i(1280, 960))
71  .map("1600x1200", Eigen::Vector2i(1600, 1200));
72 
73 
74  defineOptionalProperty<std::string>("ReferenceFrameName", "DepthCamera", "Optional reference frame name.");
75  }
76  };
77 
78  /**
79  * @defgroup Component-KLGImageProvider KLGImageProvider
80  * @ingroup VisionX-Components
81  * A description of the component KLGImageProvider.
82  *
83  * @class KLGImageProvider
84  * @ingroup Component-KLGImageProvider
85  * @brief Brief description of class KLGImageProvider.
86  *
87  * Adds support for the klg format used by ElasticFusion
88  */
90  virtual public visionx::CapturingImageProvider,
91  virtual public visionx::RGBDCapturingImageProviderInterface
92  {
93  public:
94  /**
95  * @see armarx::ManagedIceObject::getDefaultName()
96  */
97  std::string getDefaultName() const override
98  {
99  return "KLGImageProvider";
100  }
101 
102 
103  visionx::StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override
104  {
105  visionx::StereoCalibration stereoCalibration;
106 
107  Eigen::Vector2i dimensions = getProperty<Eigen::Vector2i>("Dimensions");
108 
109  visionx::CameraParameters RGBCameraIntrinsics;
110  RGBCameraIntrinsics.distortion = {0, 0, 0};
111  RGBCameraIntrinsics.focalLength = {525.0, 525.0};
112  RGBCameraIntrinsics.height = dimensions(1);
113  RGBCameraIntrinsics.principalPoint = {dimensions(0) / 2.0f, dimensions(1) / 2.0f};
115  RGBCameraIntrinsics.translation = visionx::tools::convertEigenVecToVisionX(Eigen::Vector3f::Zero());
116  RGBCameraIntrinsics.width = dimensions(0);
117 
118  visionx::CameraParameters DepthCameraIntrinsics;
119  DepthCameraIntrinsics.distortion = {0, 0, 0};
120  DepthCameraIntrinsics.focalLength = {525.0, 525.0};
121  DepthCameraIntrinsics.height = dimensions(1);
122  DepthCameraIntrinsics.principalPoint = {dimensions(0) / 2.0f, dimensions(1) / 2.0f};
123  DepthCameraIntrinsics.rotation = visionx::tools::convertEigenMatToVisionX(Eigen::Matrix3f::Identity());
124  DepthCameraIntrinsics.translation = {0.075, 0, 0};
125  DepthCameraIntrinsics.width = dimensions(0);
126 
127 
128  stereoCalibration.calibrationLeft = visionx::tools::createDefaultMonocularCalibration();
129  stereoCalibration.calibrationRight = visionx::tools::createDefaultMonocularCalibration();
130  stereoCalibration.calibrationLeft.cameraParam = RGBCameraIntrinsics;
131  stereoCalibration.calibrationRight.cameraParam = DepthCameraIntrinsics;
132  stereoCalibration.rectificationHomographyLeft = visionx::tools::convertEigenMatToVisionX(Eigen::Matrix3f::Zero());
133  stereoCalibration.rectificationHomographyRight = visionx::tools::convertEigenMatToVisionX(Eigen::Matrix3f::Zero());
134 
135 
136  return stereoCalibration;
137  }
138 
139  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override
140  {
141  return true;
142  }
143 
144  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
145  {
146  return getProperty<std::string>("ReferenceFrameName");
147  }
148 
149  protected:
150 
151  void onInitCapturingImageProvider() override;
152 
153  void onExitCapturingImageProvider() override;
154 
155  void onStartCapture(float frameRate) override;
156 
157  void onStopCapture() override;
158 
159  bool capture(void** ppImageBuffers) override;
160 
161 
162  /**
163  * @see PropertyUser::createPropertyDefinitions()
164  */
166 
167  private:
168  DebugDrawerInterfacePrx debugDrawer;
169  DebugObserverInterfacePrx debugObserver;
170 
171  CByteImage** rgbImages;
172 
173  int32_t currentFrame;
174  int32_t totalFrames;
175  FILE* fp;
176  bool doRewind;
177 
178  cv::Mat depthBuffer;
179 
180 
181 
182  };
183 }
184 
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:198
armarx::KLGImageProvider::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: KLGImageProvider.cpp:41
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::KLGImageProvider
Brief description of class KLGImageProvider.
Definition: KLGImageProvider.h:89
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::KLGImageProvider::onStartCapture
void onStartCapture(float frameRate) override
This is called when the image provider capturing has been started.
Definition: KLGImageProvider.cpp:86
armarx::KLGImageProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KLGImageProvider.h:144
armarx::KLGImageProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: KLGImageProvider.cpp:192
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
visionx::tools::convertEigenVecToVisionX
visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v)
Definition: TypeMapping.cpp:655
armarx::KLGImageProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: KLGImageProvider.cpp:205
armarx::KLGImageProviderPropertyDefinitions
Definition: KLGImageProvider.h:48
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
armarx::KLGImageProvider::getDefaultName
std::string getDefaultName() const override
Definition: KLGImageProvider.h:97
Component.h
armarx::KLGImageProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KLGImageProvider.h:139
CapturingImageProvider.h
armarx::KLGImageProvider::onStopCapture
void onStopCapture() override
This is called when the image provider capturing has been stopped.
Definition: KLGImageProvider.cpp:99
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::KLGImageProviderPropertyDefinitions::KLGImageProviderPropertyDefinitions
KLGImageProviderPropertyDefinitions(std::string prefix)
Definition: KLGImageProvider.h:52
visionx::tools::convertEigenMatToVisionX
visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m)
Definition: TypeMapping.cpp:677
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
visionx::CapturingImageProviderPropertyDefinitions
Definition: CapturingImageProvider.h:37
ImageUtil.h
armarx::KLGImageProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: KLGImageProvider.h:103
TypeMapping.h
visionx::tools::createDefaultMonocularCalibration
MonocularCalibration createDefaultMonocularCalibration()
Creates a MonocularCalibration with all parameters set to a neutral value.
Definition: ImageUtil.cpp:237
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
visionx::CapturingImageProviderPropertyDefinitions::CapturingImageProviderPropertyDefinitions
CapturingImageProviderPropertyDefinitions(std::string prefix)
Definition: CapturingImageProvider.h:40