TexturedObjectRecognition.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// forward declarations
31class CByteImage;
32
33
34#include <Eigen/Core>
35
37
38#include <TexturedRecognition/TexturedObjectDatabase.h>
39#include <TexturedRecognition/TexturedRecognition.h>
40
41namespace visionx
42{
43
44
47 {
48 static inline Eigen::Vector3f
49 stringToVector3f(std::string propertyValue)
50 {
51 Eigen::Vector3f vec;
52 sscanf(propertyValue.c_str(),
53 "%f, %f, %f",
54 &vec.data()[0],
55 &vec.data()[1],
56 &vec.data()[2]);
57 return vec;
58 }
59
60 public:
63 {
64 defineOptionalProperty<float>("SIFTThreshold",
65 0.01,
66 "A threshold for detecting SIFT descriptors in the "
67 "image. Smaller value -> more features found");
68
70 "QualityThreshold",
71 0.0001,
72 "Set quality threshold for Harris interest point calculation. Smaller means more "
73 "features. See CTexturedRecognition");
75 "nMinValidFeatures",
76 10,
77 "minimum number of features in Houghspace. See CTexturedRecognition");
79 3.3f,
80 "maximum error after application of homography on valid "
81 "features. See CTexturedRecognition");
82
84 &stringToVector3f;
85
87 Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
88 "min point for valid result bounding box")
89 .setFactory(f);
91 Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
92 "max point for valid result bounding box")
93 .setFactory(f);
94
96 "StereoCorrelationWindowSize", 19, "Correlation size for stereo matching");
97 defineOptionalProperty<float>("StereoCorrelationThreshold",
98 0.7f,
99 "The threshold for the Zero Mean-Normalized Cross "
100 "Correlation (ZNCC, range: 0.0 - 1.0).");
101 }
102 };
103
104 /**
105 * TexturedObjectRecognition uses CTexturedRecognition of IVTRecognition in order to recognize and localize objects.
106 * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
107 * The object localization is invoked automatically by the working memory if the object has been requested there.
108 */
110 {
111 public:
112 /**
113 * @see PropertyUser::createPropertyDefinitions()
114 */
121
122 /**
123 * @see Component::getDefaultName()
124 */
125 std::string
126 getDefaultName() const override
127 {
128 return "TexturedObjectRecognition";
129 }
130
131 void
132 reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration,
133 bool x,
134 const std::string& referenceFrame,
135 const Ice::Current& c = Ice::emptyCurrent) override
136 {
138 stereoCalibration, x, referenceFrame, c);
139
140 texturedRecognition->GetObjectDatabase()->InitCameraParameters(getStereoCalibration(),
141 true);
142 texturedRecognition->GetObjectDatabase()->SetCorrelationParameters(19, 400, 3500, 0.7f);
143 }
144
145 protected:
146 /**
147 * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
148 */
149 void
151 {
152
153 offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
154 }
155
156 /**
157 * Initializes the CTexturedRecognition
158 *
159 * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
160 */
161 void
163 {
165 getProperty<std::string>("DebugObserverName").getValue());
166 }
167
168 /**
169 * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
170 */
171 void
173 {
174 }
175
176 /**
177 * Initializes textured recognition
178 *
179 * @return success
180 */
181 bool initRecognizer() override;
182
183 /**
184 * Add object class to textured object recognition.
185 *
186 * @param objectClassEntity entity containing all information available for the object class
187 * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
188 *
189 * @return success of adding this entity to the TexturedObjectDatabase
190 */
191 bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
192 const memoryx::GridFileManagerPtr& fileManager) override;
193
194 /**
195 * localizes textured object instances
196 *
197 * @param objectClassNames names of the class to localize
198 * @param cameraImages the two input images
199 * @param resultImages the two result images. are provided if result images are enabled.
200 *
201 * @return list of object instances
202 */
203 memoryx::ObjectLocalizationResultList
204 localizeObjectClasses(const std::vector<std::string>& objectClassNames,
205 CByteImage** cameraImages,
206 armarx::MetaInfoSizeBasePtr imageMetaInfo,
207 CByteImage** resultImages) override;
208
209
210 private:
211 // calculates recognition certainty
212 float calculateRecognitionCertainty(const std::string& objectClassName,
213 const Object3DEntry& entry);
214 Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
215
216 // textured recognition
217 CTexturedRecognition* texturedRecognition = nullptr;
218 int correlationWindowSize = 0;
219 float correlationThreshold = 0.0f;
220
221 int seq;
222
223
225 };
226} // 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
CStereoCalibration * getStereoCalibration() const
Retrieve stereo calibration corresponding to image provider.
TexturedObjectRecognition uses CTexturedRecognition of IVTRecognition in order to recognize and local...
bool initRecognizer() override
Initializes textured recognition.
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes textured object instances
void onConnectObjectLocalizerProcessor() override
Initializes the CTexturedRecognition.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool x, const std::string &referenceFrame, 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 textured 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.