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