CropRobotFromImage.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::CropRobotFromImage
17  * @author Julian Zimmer ( urdbu at student dot 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 #ifndef _ARMARX_COMPONENT_VisionX_CropRobotFromImage_H
24 #define _ARMARX_COMPONENT_VisionX_CropRobotFromImage_H
25 
26 
27 
28 #include "MaskRobotInImage.h"
29 
31 
34 
37 #include <RobotAPI/interface/core/RobotState.h>
38 
39 
40 #include <VirtualRobot/Robot.h>
41 //
42 #include <VirtualRobot/VirtualRobotCommon.h>
43 
44 
47 //#include <VisionX/interface/components/CropRobotFromImageInterface.h>
48 #include <VisionX/interface/components/Calibration.h>
49 #include <VisionX/interface/components/PointCloudAndImageAndCalibrationProviderInterface.h>
50 
51 #include <mutex>
52 
53 #include <Eigen/Core>
54 
55 namespace armarx
56 {
57  /**
58  * @class CropRobotFromImagePropertyDefinitions
59  * @brief
60  */
63  {
64  public:
67  {
68  defineOptionalProperty<std::string>("providerName", "ImageProvider", "Name of the image provider that should be used");
69  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
70  defineOptionalProperty<std::string>("cameraFrameName", "DepthCameraSim", "The source frame name");
71 
72  defineOptionalProperty<float>("filterColorR", 0.f, "The red value of the background color that has to be different from the robots color. Range 0.f to 255.f");
73  defineOptionalProperty<float>("filterColorG", 177.f, "The green value of the background color that has to be different from the robots color. Range 0.f to 255.f");
74  defineOptionalProperty<float>("filterColorB", 64.f, "The blue value of the background color that has to be different from the robots color. Range 0.f to 255.f");
75 
76  defineOptionalProperty<float>("collisionModelInflationMargin", 0.f, "When the collision model is used for the offscreen rendering, it will be inflated by this margin.");
77 
78  defineOptionalProperty<int>("dilationStrength", 0, "The strength of the dilation after the masking, which can thicken the part that is cut from the image.");
79 
80  defineOptionalProperty<bool>("flipImages", 1, "Boolean that indicates, if the rendered image should be flipped. This is needed e.g. when camera nodes ending on 'Sim' are used.");
81  defineOptionalProperty<bool>("useFullModel", 1, "Boolean that indicates, if the full model should be used during the offscreen rendering. Otherwise the collision model will be used.");
82 
83 
84  defineOptionalProperty<int>("numResultImages", 1, "The number of images processed and provided.");
85  }
86  };
87 
88  /**
89  * @defgroup Component-CropRobotFromImage CropRobotFromImage
90  * @ingroup VisionX-Components
91  * A description of the component CropRobotFromImage.
92  *
93  * @class CropRobotFromImage
94  * @ingroup Component-CropRobotFromImage
95  * @brief Brief description of class CropRobotFromImage.
96  *
97  * Detailed description of class CropRobotFromImage.
98  */
100  virtual public visionx::ImageProcessor,
101  virtual public visionx::StereoCalibrationProcessorInterface
102  {
103 
104  public:
105  /**
106  * @see armarx::ManagedIceObject::getDefaultName()
107  */
108  virtual std::string getDefaultName() const override
109  {
110  return "CropRobotFromImage";
111  }
112 
113 
114  visionx::StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override
115  {
116  return stereoCalibration;
117  }
118 
119  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override
120  {
121  return imagesAreUndistorted;
122  }
123 
124  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
125  {
126  return referenceFrame;
127  }
128 
129  /*
130  void setStereoCalibration(visionx::StereoCalibration stereoCalibration, bool imagesAreUndistorted, const std::string& referenceFrame)
131  {
132  this->stereoCalibration = stereoCalibration;
133  this->imagesAreUndistorted = imagesAreUndistorted;
134  this->referenceFrame = referenceFrame;
135  //calibrationPrx->reportStereoCalibrationChanged(this->stereoCalibration, this->imagesAreUndistorted, this->referenceFrame);
136  }
137  */
138 
139 
140  protected:
141 
142  void process() override;
143 
144  void onInitImageProcessor() override;
145  void onConnectImageProcessor() override;
146  void onDisconnectImageProcessor() override;
147  void onExitImageProcessor() override;
148  /**
149  * @see PropertyUser::createPropertyDefinitions()
150  */
152  private:
153 
154  int width;
155  int height;
156 
157  float fov;
158 
159  int dilationStrength;
160 
161  std::mutex mutex;
162 
163  bool flipImages;
164  bool useFullModel;
165  float collisionModelInflationMargin;
166 
167  visionx::ImageProviderInfo imageProviderInfo;
168 
169 
170 
171  std::string providerName;
172  std::string cameraFrameName;
173 
174  int numImages, numResultImages;
175  CByteImage** images;
176  //CByteImage** result;
177 
178  visionx::MonocularCalibration depthCameraCalibration;
179 
180  VirtualRobot::RobotPtr localRobot;
181 
182  MaskRobotInImage* maskRobot;
183 
184  float backgroundR;
185  float backgroundG;
186  float backgroundB;
187 
188  RobotStateComponentInterfacePrx robotStateComponent;
189 
190 
191  visionx::StereoCalibration stereoCalibration;
192  bool imagesAreUndistorted;
193  //StereoCalibrationInterfacePrx calibrationPrx;
194  std::string referenceFrame;
195  };
196 }
197 
198 #endif
MaskRobotInImage.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::CropRobotFromImage::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: CropRobotFromImage.cpp:169
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
armarx::CropRobotFromImage::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: CropRobotFromImage.h:124
armarx::CropRobotFromImage::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: CropRobotFromImage.cpp:43
armarx::CropRobotFromImage::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CropRobotFromImage.cpp:243
Pose.h
armarx::CropRobotFromImage::onConnectImageProcessor
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: CropRobotFromImage.cpp:66
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::CropRobotFromImagePropertyDefinitions::CropRobotFromImagePropertyDefinitions
CropRobotFromImagePropertyDefinitions(std::string prefix)
Definition: CropRobotFromImage.h:65
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::ImageProcessorPropertyDefinitions::ImageProcessorPropertyDefinitions
ImageProcessorPropertyDefinitions(std::string prefix)
Definition: ImageProcessor.h:65
armarx::CropRobotFromImage::process
void process() override
Process the vision component.
Definition: CropRobotFromImage.cpp:178
armarx::CropRobotFromImagePropertyDefinitions
Definition: CropRobotFromImage.h:61
armarx::CropRobotFromImage::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: CropRobotFromImage.h:114
armarx::CropRobotFromImage::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Definition: CropRobotFromImage.h:119
visionx::ImageProviderInfo
Definition: ImageProcessor.h:466
ImageProcessor.h
FramedPose.h
armarx::CropRobotFromImage::onDisconnectImageProcessor
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
Definition: CropRobotFromImage.cpp:163
Component.h
armarx::MaskRobotInImage
A brief description.
Definition: MaskRobotInImage.h:62
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
ImageUtil.h
TypeMapping.h
armarx::CropRobotFromImage
Brief description of class CropRobotFromImage.
Definition: CropRobotFromImage.h:99
armarx::CropRobotFromImage::getDefaultName
virtual std::string getDefaultName() const override
Definition: CropRobotFromImage.h:108
ImageProvider.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18