HandMarkerLocalization.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::Component
19  * @author Kai Welke (welke at kit dot edu)
20  * @date 2013
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 // VisionX
28 #include <VirtualRobot/VirtualRobot.h>
29 
31 
32 // forward declarations
33 class CByteImage;
34 class CVisualTargetLocator;
35 class CColorParameterSet;
36 
37 namespace visionx
38 {
41  {
42  public:
45  {
46  defineOptionalProperty<std::string>(
47  "ColorParameterFile",
48  "VisionX/examples/colors.txt",
49  "The color parameter file configures the colors used for segmentable recognition "
50  "(usually colors.txt)");
51  defineOptionalProperty<bool>(
52  "ShowSegmentedResultImages",
53  true,
54  "Decide whether to calculate color-segmented images with the marker color and show "
55  "them as result images. Causes small additional computational effort.");
56  defineOptionalProperty<std::string>(
57  "TCPNameLeft", "TCP L", "Name of the TCP of the left robot hand.");
58  defineOptionalProperty<std::string>(
59  "TCPNameRight", "TCP R", "Name of the TCP of the right robot hand.");
60  defineOptionalProperty<std::string>(
61  "MarkerNameLeft", "Marker L", "Name of the marker ball at the left robot hand.");
62  defineOptionalProperty<std::string>(
63  "MarkerNameRight", "Marker R", "Name of the marker ball at the right robot hand.");
64  defineOptionalProperty<bool>(
65  "UseVision",
66  true,
67  "You can switch off the use of the camera images. The returned pose will then just "
68  "be taken from the forward kinematics.");
69  defineOptionalProperty<std::string>(
70  "RobotStateComponentName",
71  "RobotStateComponent",
72  "Name of the RobotStateComponent that should be used");
73  defineOptionalProperty<float>(
74  "MaximalAcceptedDistanceFromForwardKinematics",
75  200,
76  "Maximal distance that the localization result may have from the position "
77  "determined by forward kinematics. If it is further away, it is discarded..");
78  }
79  };
80 
81  /**
82  * HandMarkerLocalization uses the CVisualTargetLocator of IVT in order to recognize and localize the marker balls at the hands of the robot.
83  * The returned hand pose takes the offset from marker to TCP into account, which is defined in the robot model file.
84  * The marker color is read from PriorKnowledge and CommonStorage via MemoryX.
85  * The hand localization is invoked automatically by the working memory if the object has been requested there.
86  */
88  {
89  public:
91 
92  /**
93  * @see PropertyUser::createPropertyDefinitions()
94  */
97  {
100  }
101 
102  /**
103  * @see Component::getDefaultName()
104  */
105  std::string
106  getDefaultName() const override
107  {
108  return "HandMarkerLocalization";
109  }
110 
111  protected:
112  /**
113  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
114  */
115  void onInitObjectLocalizerProcessor() override;
116 
117  /**
118  * Initialize stuff here?
119  *
120  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
121  */
122  void onConnectObjectLocalizerProcessor() override;
123 
124  /**
125  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
126  */
127  void
129  {
130  }
131 
132  /**
133  * Initializes segmentable recognition
134  *
135  * @return success
136  */
137  bool initRecognizer() override;
138 
139  /**
140  * Add a memory entity representing the hand marker in order to set its properties
141  *
142  * @param objectClassEntity entity containing all information available for the object class
143  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
144  *
145  * @return success of adding this entity
146  */
147  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
148  const memoryx::GridFileManagerPtr& fileManager) override;
149 
150  /**
151  * localize one or both hand markers
152  *
153  * @param objectClassNames is ignored here
154  * @param cameraImages the two input images
155  * @param resultImages the two result images. are provided if result images are enabled.
156  *
157  * @return list of object instances
158  */
159  memoryx::ObjectLocalizationResultList
160  localizeObjectClasses(const std::vector<std::string>& objectClassNames,
161  CByteImage** cameraImages,
162  armarx::MetaInfoSizeBasePtr imageMetaInfo,
163  CByteImage** resultImages) override;
164 
165 
166  private:
167  void drawCrossInImage(CByteImage* image, Eigen::Vector3f point, bool leftCamera);
168 
169 
170  // decides whether images or forward kinematic will be used
171  bool useVision;
172 
173  // locator for the tracking balls
174  CVisualTargetLocator* visualTargetLocator;
175  std::map<std::string, ObjectColor> markerColors;
176 
177  // remote robot for the orientation
178  VirtualRobot::RobotPtr localRobot;
179  std::string tcpNameLeft, tcpNameRight, markerNameLeft, markerNameRight;
180 
181  // visualization
182  bool showSegmentedResultImages;
183  CColorParameterSet* colorParameterSet;
184 
185  armarx::RobotStateComponentInterfacePrx robotStateComponent;
186  };
187 } // namespace visionx
visionx::HandMarkerLocalization::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localize one or both hand markers
Definition: HandMarkerLocalization.cpp:130
visionx::HandMarkerLocalization::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add a memory entity representing the hand marker in order to set its properties.
Definition: HandMarkerLocalization.cpp:116
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:431
visionx::HandMarkerLocalization::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: HandMarkerLocalization.cpp:58
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::HandMarkerLocalizationPropertyDefinitions::HandMarkerLocalizationPropertyDefinitions
HandMarkerLocalizationPropertyDefinitions(std::string prefix)
Definition: HandMarkerLocalization.h:43
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:432
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:429
visionx::HandMarkerLocalization
HandMarkerLocalization uses the CVisualTargetLocator of IVT in order to recognize and localize the ma...
Definition: HandMarkerLocalization.h:87
visionx::HandMarkerLocalization::getDefaultName
std::string getDefaultName() const override
Definition: HandMarkerLocalization.h:106
visionx::HandMarkerLocalization::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initialize stuff here?
Definition: HandMarkerLocalization.cpp:69
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
visionx::HandMarkerLocalizationPropertyDefinitions
Definition: HandMarkerLocalization.h:39
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::HandMarkerLocalization::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HandMarkerLocalization.h:96
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
visionx::HandMarkerLocalization::HandMarkerLocalization
HandMarkerLocalization()
Definition: HandMarkerLocalization.cpp:52
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
visionx::HandMarkerLocalization::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: HandMarkerLocalization.h:128
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:128
visionx::HandMarkerLocalization::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: HandMarkerLocalization.cpp:77