BlobRecognition.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::Component
17* @license http://www.gnu.org/licenses/gpl-2.0.txt
18* GNU General Public License
19*/
20
21#pragma once
22
23
24#include <Eigen/Core>
25
27
29
31
32#include <Color/ColorParameterSet.h>
33#include <Visualizer/OpenGLVisualizer.h>
34
35class CByteImage;
36class CGLContext;
37class CObjectFinderStereo;
38
39namespace visionx
40{
41 using CObjectFinderStereoPtr = std::shared_ptr<CObjectFinderStereo>;
42 using CColorParameterSetPtr = std::shared_ptr<CColorParameterSet>;
43
45 {
46 static inline Eigen::Vector3f
47 stringToVector3f(std::string propertyValue)
48 {
49 Eigen::Vector3f vec;
50 sscanf(propertyValue.c_str(),
51 "%f, %f, %f",
52 &vec.data()[0],
53 &vec.data()[1],
54 &vec.data()[2]);
55 return vec;
56 }
57
58 public:
61 {
63 "ColorParameterFile",
64 "VisionX/examples/colors.txt",
65 "The color parameter file configures the colors used for segmentable recognition "
66 "(usually colors.txt)");
68 "MinPixelsPerRegion",
69 200,
70 "Minimum number of pixels per region for detecting a uniformly colored object");
72 "MaxEpipolarDistance",
73 6,
74 "Maximum epipolar line distance allowed for a valid 3D recognition result");
75
77 &stringToVector3f;
78
80 Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
81 "min point for valid result bounding box")
82 .setFactory(f);
84 Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
85 "max point for valid result bounding box")
86 .setFactory(f);
87
88 defineOptionalProperty<std::string>("RobotStateComponentName",
89 "RobotStateComponent",
90 "The name of the RobotStateComponent.");
91 }
92 };
93
94 /**
95 * BlobRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
96 * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
97 * The object localization is invoked automatically by the working memory if the object has been requested there.
98 *
99 */
101 {
102 public:
103 /**
104 * @see PropertyUser::createPropertyDefinitions()
105 */
112
113 void
114 reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration,
115 bool x,
116 const std::string& referenceName,
117 const Ice::Current& c = Ice::emptyCurrent) override
118 {
120 stereoCalibration, x, referenceName, c);
121
123 }
124
125 /**
126 * @see Component::getDefaultName()
127 */
128 std::string
129 getDefaultName() const override
130 {
131 return "BlobRecognition";
132 }
133
135 ~BlobRecognition() override;
136
137 protected:
138 /**
139 * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
140 */
141 void
143 {
144
145 offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
146 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
147 }
148
149 /**
150 * Initializes the CSegmentableRecognition
151 *
152 * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
153 */
154 void
156 {
157
159 getProperty<std::string>("DebugObserverName").getValue());
161 getProperty<std::string>("RobotStateComponentName").getValue());
162
163 localRobot = armarx::RemoteRobot::createLocalCloneFromFile(robotStateComponent);
164 }
165
166 /**
167 * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
168 */
169 void onExitObjectLocalizerProcessor() override;
170
171 /**
172 * Initializes segmentable recognition
173 *
174 * @return success
175 */
176 bool initRecognizer() override;
177
178 /**
179 * Add object class to segmentable object recognition.
180 *
181 * @param objectClassEntity entity containing all information available for the object class
182 * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
183 *
184 * @return success of adding this entity to the TexturedObjectDatabase
185 */
186 bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
187 const memoryx::GridFileManagerPtr& fileManager) override;
188
189 /**
190 * localizes segmentable object instances
191 *
192 * @param objectClassNames names of the class to localize
193 * @param cameraImages the two input images
194 * @param resultImages the two result images. are provided if result images are enabled.
195 *
196 * @return list of object instances
197 */
198 memoryx::ObjectLocalizationResultList
199 localizeObjectClasses(const std::vector<std::string>& objectClassNames,
200 CByteImage** cameraImages,
201 armarx::MetaInfoSizeBasePtr imageMetaInfo,
202 CByteImage** resultImages) override;
203
204 private:
205 // calculates recognition certainty
206 float calculateRecognitionCertainty(const std::string& objectClassName,
207 const Object3DEntry& entry);
208
209 CObjectFinderStereoPtr objectFinderStereo;
210 std::shared_ptr<CGLContext> contextGL;
211 std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
212
213 // settings
214 float minPixelsPerRegion;
215 float maxEpipolarDistance;
216 CColorParameterSetPtr colorParameters;
217
218 // remember colors of objects (not stored i`n IVT viewdatabase)
219 std::map<std::string, ObjectColor> objectColors;
220 std::map<ObjectColor, std::string> colorToObjectClass;
221
222
223 Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
224
225
226 std::map<std::string, int> seq;
227
229 armarx::RobotStateComponentInterfacePrx robotStateComponent;
230
231 VirtualRobot::RobotPtr localRobot;
232 };
233} // namespace visionx
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
std::function< PropertyType(std::string)> PropertyFactoryFunction
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
bool initRecognizer() override
Initializes segmentable recognition.
void onExitObjectLocalizerProcessor() override
void onInitObjectLocalizerProcessor() override
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes segmentable object instances
void onConnectObjectLocalizerProcessor() override
Initializes the CSegmentableRecognition.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool x, const std::string &referenceName, const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to segmentable object recognition.
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame, const Ice::Current &c=Ice::emptyCurrent) override
armarx::MetaInfoSizeBasePtr imageMetaInfo
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface > RobotStateComponentInterfacePrx
IceInternal::Handle< Entity > EntityPtr
Typedef of EntityPtr as IceInternal::Handle<Entity> for convenience.
Definition Entity.h:45
std::shared_ptr< GridFileManager > GridFileManagerPtr
ArmarX headers.
std::shared_ptr< CObjectFinderStereo > CObjectFinderStereoPtr
std::shared_ptr< CColorParameterSet > CColorParameterSetPtr