RGBDHandLocalizer.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::ArmarXObjects::RGBDHandLocalizer
19  * @author Markus Grotz ( markus dot grotz at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
28 #include <math.h>
29 
30 #include <Eigen/Geometry>
31 
32 #include <pcl/filters/crop_box.h>
33 
34 #include <opencv2/opencv.hpp>
35 
38 
40 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
43 
47 #include <VisionX/interface/components/ObjectLocalizerInterfaces.h>
50 
51 #include "bloblabeler.h"
52 #include <Image/ImageProcessor.h>
53 #include <Image/IplImageAdaptor.h>
55 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
56 #include <MemoryX/interface/workingmemory/WorkingMemoryUpdaterBase.h>
57 
58 namespace visionx
59 {
60  /**
61  * @class RGBDHandLocalizerPropertyDefinitions
62  * @brief
63  */
65  {
66  public:
69  {
70  defineOptionalProperty<std::string>("providerName", "OpenNIPointCloudProvider", "");
71  defineOptionalProperty<std::string>(
72  "RobotStateComponentProxyName", "RobotStateComponent", "");
73  defineOptionalProperty<std::string>("HandNameInRobotModel", "TCP R", "");
74  defineOptionalProperty<std::string>("HandNameInMemory", "handright3aRGBD", "");
75  defineOptionalProperty<std::string>("SensorFrameName", "DepthCamera", "");
76  defineOptionalProperty<std::string>(
77  "RightHandNameViewSelection", "handright3a", "Name of the normal hand");
78  defineOptionalProperty<std::string>("MarkerName", "Marker R", "");
79  defineOptionalProperty<std::string>(
80  "DebugDrawerTopicName",
81  "DebugDrawerUpdates",
82  "Name of the debug drawer topic that should be used");
83 
84  defineOptionalProperty<bool>(
85  "PrimitiveCalibrationOnStart",
86  true,
87  "If true the component calibrates itself in a primitive way.");
88  defineOptionalProperty<float>("MarkerRadiusMM", 10, "");
89 
90  defineOptionalProperty<float>("uncertaintyMM", 100, "");
91  //Green
92  defineOptionalProperty<int>("hueMin", 48, "");
93  defineOptionalProperty<int>("hueMax", 90, "");
94 
95  defineOptionalProperty<int>("satMin", 50, "");
96  defineOptionalProperty<int>("satMax", 255, "");
97 
98  defineOptionalProperty<int>("valMin", 105, "");
99  defineOptionalProperty<int>("valMax", 255, "");
100  }
101  };
102 
103  /**
104  * @defgroup Component-RGBDHandLocalizer RGBDHandLocalizer
105  * @ingroup VisionX-Components
106  * A description of the component RGBDHandLocalizer.
107  *
108  * @class RGBDHandLocalizer
109  * @ingroup Component-RGBDHandLocalizer
110  * @brief Brief description of class RGBDHandLocalizer.
111  *
112  * Detailed description of class RGBDHandLocalizer.
113  */
115 
116  virtual public PointCloudAndImageProcessor,
117  virtual public ObjectLocalizerPointCloudAndImageInterface
118  {
119  public:
120  /**
121  * @see armarx::ManagedIceObject::getDefaultName()
122  */
123  std::string
124  getDefaultName() const override
125  {
126  return "RGBDHandLocalizer";
127  }
128 
129  memoryx::ObjectLocalizationResultList
130  localizeObjectClasses(const memoryx::ObjectClassNameList&, const Ice::Current&) override;
131 
132  protected:
133  /**
134  * @see PropertyUser::createPropertyDefinitions()
135  */
137 
138  void process() override;
139 
140  void onInitPointCloudAndImageProcessor() override;
141  void onConnectPointCloudAndImageProcessor() override;
143  void onExitPointCloudAndImageProcessor() override;
144 
145  private:
146  CByteImage** images;
147  int numImages;
148  std::string providerName;
149  armarx::RobotStateComponentInterfacePrx robotStatePrx = nullptr;
151  getFramedPosition(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr, int x, int y);
152  armarx::TimestampVariantPtr timestamp;
153  armarx::FramedPosePtr realHandPose = nullptr;
154  CByteImage** result;
155 
156  int calibrationCounter = 0;
157  Eigen::Vector3f calibrationSum = Eigen::Vector3f::Zero();
158 
159  std::mutex positionLock;
160  armarx::DebugDrawerInterfacePrx debugDrawerTopic;
161  pcl::CropBox<pcl::PointXYZRGBA> cropper;
162 
163  std::string sensorFrameName;
164  std::string markerFrameName;
165  std::string handFrameName;
166 
167  // PointCloudAndImageProcessor interface
168  void calcPositions(cv::Mat& binaryImage,
169  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pointcloud,
170  std::vector<Eigen::Vector3f>& medianCoordinates);
171  void cropFilter(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr input,
172  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr output,
173  float uncertaintyMM,
174  Eigen::Vector3f guessMM);
175  };
176 } // namespace visionx
RemoteRobot.h
PointCloudAndImageProcessor.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::RGBDHandLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RGBDHandLocalizer.cpp:31
visionx::RGBDHandLocalizerPropertyDefinitions
Definition: RGBDHandLocalizer.h:64
visionx::RGBDHandLocalizer::onConnectPointCloudAndImageProcessor
void onConnectPointCloudAndImageProcessor() override
Implement this method in your PointCloudAndImageProcessor in order execute parts when the component i...
Definition: RGBDHandLocalizer.cpp:56
IceInternal::Handle< TimestampVariant >
visionx::RGBDHandLocalizer::onExitPointCloudAndImageProcessor
void onExitPointCloudAndImageProcessor() override
Exit the ImapeProcessor component.
Definition: RGBDHandLocalizer.cpp:97
ImageProcessor.h
PCLUtilities.h
FramedPose.h
visionx::RGBDHandLocalizer::process
void process() override
Process the vision component.
Definition: RGBDHandLocalizer.cpp:113
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
visionx::RGBDHandLocalizer::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &, const Ice::Current &) override
Definition: RGBDHandLocalizer.cpp:380
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:12
TimestampVariant.h
visionx::RGBDHandLocalizer::onInitPointCloudAndImageProcessor
void onInitPointCloudAndImageProcessor() override
Setup the vision component.
Definition: RGBDHandLocalizer.cpp:38
visionx::RGBDHandLocalizer
Brief description of class RGBDHandLocalizer.
Definition: RGBDHandLocalizer.h:114
visionx::RGBDHandLocalizerPropertyDefinitions::RGBDHandLocalizerPropertyDefinitions
RGBDHandLocalizerPropertyDefinitions(std::string prefix)
Definition: RGBDHandLocalizer.h:67
Component.h
visionx::RGBDHandLocalizer::onDisconnectPointCloudAndImageProcessor
void onDisconnectPointCloudAndImageProcessor() override
Implement this method in the PointCloudAndImageProcessor in order to execute parts when the component...
Definition: RGBDHandLocalizer.cpp:91
ProbabilityMeasures.h
visionx::RGBDHandLocalizer::getDefaultName
std::string getDefaultName() const override
Definition: RGBDHandLocalizer.h:124
bloblabeler.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
ImageUtil.h
TypeMapping.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
visionx::PointCloudAndImageProcessor
The PointCloudAndImageProcessor class provides an interface for access to PointCloudProviders and Ima...
Definition: PointCloudAndImageProcessor.h:105
RobotStateComponent.h