SegmentableTemplateRecognition.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
26// VisionX
28
30
31// IVT
32#include <Eigen/Core>
33
34#include <Color/ColorParameterSet.h>
35#include <ObjectFinder/ObjectFinderStereo.h>
36#include <Visualizer/OpenGLVisualizer.h>
37
38// global forward declarations
39class CByteImage;
40class CGLContext;
41
42namespace visionx
43{
44 static const std::size_t SegmentableBitmapWidth = 64;
45 static const std::size_t SegmentableBitmapSize =
46 SegmentableBitmapWidth * SegmentableBitmapWidth;
47 // How much uint32_t do we need to store all the bits
48 static const std::size_t SegmentableBitmapUInt32Size = SegmentableBitmapSize / 32;
49
51 {
52 float rotationX;
53 float rotationY;
54 float rotationZ;
55 std::uint32_t bitmap[SegmentableBitmapUInt32Size];
56 };
57
59 {
60 char magic[4];
61 char name[256];
62 std::uint32_t templateCount;
64 };
65
67 {
68 std::unique_ptr<SegmentableTemplateHeader> data;
69 std::unique_ptr<CFloatMatrix> model;
70 ObjectColor color;
71 };
72
73 // properties of SegmentableTemplateRecognition
76 {
77 static inline Eigen::Vector3f
78 stringToVector3f(std::string propertyValue)
79 {
80 Eigen::Vector3f vec;
81 sscanf(propertyValue.c_str(),
82 "%f, %f, %f",
83 &vec.data()[0],
84 &vec.data()[1],
85 &vec.data()[2]);
86 return vec;
87 }
88
89 public:
92 {
94 "ColorParameterFile",
95 "VisionX/examples/cebit-colors.txt",
96 "The color parameter file configures the colors used for segmentable recognition "
97 "(usually colors.txt)");
99 "MinPixelsPerRegion",
100 6000,
101 "Minimum number of pixels per region for detecting a uniformly colored object");
103 "MaxEpipolarDistance",
104 12,
105 "Maximum epipolar line distance allowed for a valid 3D recognition result");
106
107 defineOptionalProperty<std::string>("TemplatePath", "VisionX/templates");
108
109
111 &stringToVector3f;
112
114 Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
115 "min point for valid result bounding box")
116 .setFactory(f);
118 Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
119 "max point for valid result bounding box")
120 .setFactory(f);
121
122 defineOptionalProperty<float>("TemplateMatchThreshold", 0.7f, "");
123 defineOptionalProperty<float>("SizeRatioThreshold", 0.7f, "");
124 defineOptionalProperty<float>("CorrelationThreshold", 0.7f, "");
125
126 defineOptionalProperty<bool>("SingleInstance", true, "");
127 }
128 };
129
130 /**
131 * SegmentableTemplateRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
132 * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
133 * The object localization is invoked automatically by the working memory if the object has been requested there.
134 *
135 */
137 {
138 public:
139 /**
140 * @see PropertyUser::createPropertyDefinitions()
141 */
148
149 void
150 reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration,
151 bool x,
152 const std::string& referenceName,
153 const Ice::Current& c = Ice::emptyCurrent) override
154 {
156 stereoCalibration, x, referenceName, c);
157
159 }
160
161 /**
162 * @see Component::getDefaultName()
163 */
164 std::string
165 getDefaultName() const override
166 {
167 return "SegmentableTemplateRecognition";
168 }
169
172
173 protected:
174 /**
175 * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
176 */
177 void onInitObjectLocalizerProcessor() override;
178
179 /**
180 * Initializes the CSegmentableRecognition
181 *
182 * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
183 */
184 void
186 {
187
189 getProperty<std::string>("DebugObserverName").getValue());
190 }
191
192 /**
193 * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
194 */
195 void onExitObjectLocalizerProcessor() override;
196
197 /**
198 * Initializes segmentable recognition
199 *
200 * @return success
201 */
202 bool initRecognizer() override;
203
204 /**
205 * Add object class to segmentable object recognition.
206 *
207 * @param objectClassEntity entity containing all information available for the object class
208 * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
209 *
210 * @return success of adding this entity to the TexturedObjectDatabase
211 */
212 bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
213 const memoryx::GridFileManagerPtr& fileManager) override;
214
215 /**
216 * localizes segmentable object instances
217 *
218 * @param objectClassNames names of the class to localize
219 * @param cameraImages the two input images
220 * @param resultImages the two result images. are provided if result images are enabled.
221 *
222 * @return list of object instances
223 */
224 memoryx::ObjectLocalizationResultList
225 localizeObjectClasses(const std::vector<std::string>& objectClassNames,
226 CByteImage** cameraImages,
227 armarx::MetaInfoSizeBasePtr imageMetaInfo,
228 CByteImage** resultImages) override;
229
230 private:
231 void visualizeResults(const Object3DList& objectList, CByteImage** resultImages);
232
233 float calculateRecognitionCertainty(const std::string& objectClassName,
234 const Object3DEntry& entry);
235
236 private:
237 std::shared_ptr<CGLContext> contextGL;
238 std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
239 std::shared_ptr<CObjectFinderStereo> m_pObjectFinderStereo;
240
241 // params
242 int paramMinPixelsPerRegion = 200;
243 float paramTemplateMatchThreshold = 0.7f;
244 float paramSizeRatioThreshold = 0.7f;
245 float paramCorrelationThreshold = 0.7f;
246 bool paramSingleInstance = true;
247
248 // settings
249 std::string templatePath;
250 float minPixelsPerRegion;
251 float maxEpipolarDistance;
252 CColorParameterSet colorParameters;
253 // Object name => template data
254 std::map<std::string, SegmentableTemplateEntry> database;
255
256 Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
257
258
259 std::map<std::string, int> seq;
260
261
263 };
264} // 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)
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::unique_ptr< SegmentableTemplateHeader > data
std::uint32_t bitmap[SegmentableBitmapUInt32Size]