SegmentableObjectRecognition.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* @author Kai Welke <welke at kit dot edu>
18* @copyright 2013 Humanoids Group, HIS, KIT
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25// VisionX
27
29
30// IVT
31#include <Eigen/Core>
32
33#include <Color/ColorParameterSet.h>
34#include <SegmentableRecognition/SegmentableRecognition.h>
35#include <Visualizer/OpenGLVisualizer.h>
36
37// global forward declarations
38class CByteImage;
39class CGLContext;
40
41namespace visionx
42{
43
44
45 // shared pointer type definitions
46 using CSegmentableRecognitionPtr = std::shared_ptr<CSegmentableRecognition>;
47 using CColorParameterSetPtr = std::shared_ptr<CColorParameterSet>;
48
49 // properties of SegmentableObjectRecognition
52 {
53 static inline Eigen::Vector3f
54 stringToVector3f(std::string propertyValue)
55 {
56 Eigen::Vector3f vec;
57 sscanf(propertyValue.c_str(),
58 "%f, %f, %f",
59 &vec.data()[0],
60 &vec.data()[1],
61 &vec.data()[2]);
62 return vec;
63 }
64
65 public:
68 {
70 "ColorParameterFile",
71 "VisionX/examples/colors.txt",
72 "The color parameter file configures the colors used for segmentable recognition "
73 "(usually colors.txt)");
75 "MinPixelsPerRegion",
76 200,
77 "Minimum number of pixels per region for detecting a uniformly colored object");
79 "MaxEpipolarDistance",
80 6,
81 "Maximum epipolar line distance allowed for a valid 3D recognition result");
82
83
85 &stringToVector3f;
86
88 Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
89 "min point for valid result bounding box")
90 .setFactory(f);
92 Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
93 "max point for valid result bounding box")
94 .setFactory(f);
95
96 defineOptionalProperty<float>("SizeRatioThreshold", 0.7f, "");
97 defineOptionalProperty<float>("CorrelationThreshold", 0.7f, "");
98 }
99 };
100
101 /**
102 * SegmentableObjectRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
103 * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
104 * The object localization is invoked automatically by the working memory if the object has been requested there.
105 *
106 */
108 {
109 public:
110 /**
111 * @see PropertyUser::createPropertyDefinitions()
112 */
119
120 void
121 reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration,
122 bool x,
123 const std::string& referenceName,
124 const Ice::Current& c = Ice::emptyCurrent) override
125 {
127 stereoCalibration, x, referenceName, c);
128
130 }
131
132 /**
133 * @see Component::getDefaultName()
134 */
135 std::string
136 getDefaultName() const override
137 {
138 return "SegmentableObjectRecognition";
139 }
140
143
144 protected:
145 /**
146 * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
147 */
148 void
150 {
151
152 offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
153 }
154
155 /**
156 * Initializes the CSegmentableRecognition
157 *
158 * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
159 */
160 void
162 {
163
165 getProperty<std::string>("DebugObserverName").getValue());
166 }
167
168 /**
169 * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
170 */
171 void onExitObjectLocalizerProcessor() override;
172
173 /**
174 * Initializes segmentable recognition
175 *
176 * @return success
177 */
178 bool initRecognizer() override;
179
180 /**
181 * Add object class to segmentable object recognition.
182 *
183 * @param objectClassEntity entity containing all information available for the object class
184 * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
185 *
186 * @return success of adding this entity to the TexturedObjectDatabase
187 */
188 bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
189 const memoryx::GridFileManagerPtr& fileManager) override;
190
191 /**
192 * localizes segmentable object instances
193 *
194 * @param objectClassNames names of the class to localize
195 * @param cameraImages the two input images
196 * @param resultImages the two result images. are provided if result images are enabled.
197 *
198 * @return list of object instances
199 */
200 memoryx::ObjectLocalizationResultList
201 localizeObjectClasses(const std::vector<std::string>& objectClassNames,
202 CByteImage** cameraImages,
203 armarx::MetaInfoSizeBasePtr imageMetaInfo,
204 CByteImage** resultImages) override;
205
206 private:
207 // calculates recognition certainty
208 float calculateRecognitionCertainty(const std::string& objectClassName,
209 const Object3DEntry& entry);
210 void visualizeResults(const Object3DList& objectList, CByteImage** resultImages);
211
212 // pointer to IVT segmentable recognition
213 CSegmentableRecognitionPtr segmentableRecognition;
214 std::shared_ptr<CGLContext> contextGL;
215 std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
216
217 // settings
218 float minPixelsPerRegion;
219 float maxEpipolarDistance;
220 CColorParameterSetPtr colorParameters;
221
222 // remember colors of objects (not stored in IVT viewdatabase)
223 std::map<std::string, ObjectColor> objectColors;
224
225 Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
226
227
228 std::map<std::string, int> seq;
229
230
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.
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
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame, const Ice::Current &c=Ice::emptyCurrent) override
armarx::MetaInfoSizeBasePtr imageMetaInfo
bool initRecognizer() override
Initializes segmentable recognition.
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
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to segmentable object recognition.
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::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< CSegmentableRecognition > CSegmentableRecognitionPtr
std::shared_ptr< CColorParameterSet > CColorParameterSetPtr