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 
30 
33 
34 #include <MemoryX/interface/workingmemory/WorkingMemoryUpdaterBase.h>
36 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
37 
40 #include <VisionX/interface/components/ObjectLocalizerInterfaces.h>
44 
45 #include <Eigen/Geometry>
46 
47 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
49 
50 #include <opencv2/opencv.hpp>
51 #include <Image/IplImageAdaptor.h>
52 #include <Image/ImageProcessor.h>
53 #include <pcl/filters/crop_box.h>
54 #include "bloblabeler.h"
55 #include <math.h>
56 
57 namespace visionx
58 {
59  /**
60  * @class RGBDHandLocalizerPropertyDefinitions
61  * @brief
62  */
65  {
66  public:
69  {
70  defineOptionalProperty<std::string>("providerName", "OpenNIPointCloudProvider", "");
71  defineOptionalProperty<std::string>("RobotStateComponentProxyName", "RobotStateComponent", "");
72  defineOptionalProperty<std::string>("HandNameInRobotModel", "TCP R", "");
73  defineOptionalProperty<std::string>("HandNameInMemory", "handright3aRGBD", "");
74  defineOptionalProperty<std::string>("SensorFrameName", "DepthCamera", "");
75  defineOptionalProperty<std::string>("RightHandNameViewSelection", "handright3a", "Name of the normal hand");
76  defineOptionalProperty<std::string>("MarkerName", "Marker R", "");
77  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the debug drawer topic that should be used");
78 
79  defineOptionalProperty<bool>("PrimitiveCalibrationOnStart", true, "If true the component calibrates itself in a primitive way.");
80  defineOptionalProperty<float>("MarkerRadiusMM", 10, "");
81 
82  defineOptionalProperty<float>("uncertaintyMM", 100, "");
83  //Green
84  defineOptionalProperty<int>("hueMin", 48, "");
85  defineOptionalProperty<int>("hueMax", 90, "");
86 
87  defineOptionalProperty<int>("satMin", 50, "");
88  defineOptionalProperty<int>("satMax", 255, "");
89 
90  defineOptionalProperty<int>("valMin", 105, "");
91  defineOptionalProperty<int>("valMax", 255, "");
92  }
93  };
94 
95  /**
96  * @defgroup Component-RGBDHandLocalizer RGBDHandLocalizer
97  * @ingroup VisionX-Components
98  * A description of the component RGBDHandLocalizer.
99  *
100  * @class RGBDHandLocalizer
101  * @ingroup Component-RGBDHandLocalizer
102  * @brief Brief description of class RGBDHandLocalizer.
103  *
104  * Detailed description of class RGBDHandLocalizer.
105  */
107 
108  virtual public PointCloudAndImageProcessor,
109  virtual public ObjectLocalizerPointCloudAndImageInterface
110  {
111  public:
112  /**
113  * @see armarx::ManagedIceObject::getDefaultName()
114  */
115  std::string getDefaultName() const override
116  {
117  return "RGBDHandLocalizer";
118  }
119 
120  memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList&, const Ice::Current&) override;
121 
122  protected:
123 
124  /**
125  * @see PropertyUser::createPropertyDefinitions()
126  */
128 
129  void process() override;
130 
131  void onInitPointCloudAndImageProcessor() override;
132  void onConnectPointCloudAndImageProcessor() override;
134  void onExitPointCloudAndImageProcessor() override;
135 
136  private:
137 
138  CByteImage** images;
139  int numImages;
140  std::string providerName;
141  armarx::RobotStateComponentInterfacePrx robotStatePrx = nullptr;
142  armarx::FramedPosition getFramedPosition(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr, int x, int y);
143  armarx::TimestampVariantPtr timestamp;
144  armarx::FramedPosePtr realHandPose = nullptr;
145  CByteImage** result;
146 
147  int calibrationCounter = 0;
148  Eigen::Vector3f calibrationSum = Eigen::Vector3f::Zero();
149 
150  std::mutex positionLock;
151  armarx::DebugDrawerInterfacePrx debugDrawerTopic;
152  pcl::CropBox<pcl::PointXYZRGBA> cropper;
153 
154  std::string sensorFrameName;
155  std::string markerFrameName;
156  std::string handFrameName;
157 
158  // PointCloudAndImageProcessor interface
159  void calcPositions(cv::Mat& binaryImage, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pointcloud, std::vector<Eigen::Vector3f>& medianCoordinates);
160  void cropFilter(pcl::PointCloud<pcl::PointXYZRGBA>::Ptr input, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr output, float uncertaintyMM, Eigen::Vector3f guessMM);
161 
162  };
163 }
164 
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:333
visionx::RGBDHandLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RGBDHandLocalizer.cpp:32
visionx::RGBDHandLocalizerPropertyDefinitions
Definition: RGBDHandLocalizer.h:63
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:93
ImageProcessor.h
PCLUtilities.h
FramedPose.h
visionx::RGBDHandLocalizer::process
void process() override
Process the vision component.
Definition: RGBDHandLocalizer.cpp:108
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
visionx::RGBDHandLocalizer::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const memoryx::ObjectClassNameList &, const Ice::Current &) override
Definition: RGBDHandLocalizer.cpp:353
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
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:106
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:88
ProbabilityMeasures.h
visionx::RGBDHandLocalizer::getDefaultName
std::string getDefaultName() const override
Definition: RGBDHandLocalizer.h:115
bloblabeler.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
ImageUtil.h
TypeMapping.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
visionx::PointCloudAndImageProcessor
The PointCloudAndImageProcessor class provides an interface for access to PointCloudProviders and Ima...
Definition: PointCloudAndImageProcessor.h:97
RobotStateComponent.h