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
31 class CByteImage;
32 
33 
34 #include <Eigen/Core>
35 
37 
38 #include <TexturedRecognition/TexturedObjectDatabase.h>
39 #include <TexturedRecognition/TexturedRecognition.h>
40 
41 namespace 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 
69  defineOptionalProperty<float>(
70  "QualityThreshold",
71  0.0001,
72  "Set quality threshold for Harris interest point calculation. Smaller means more "
73  "features. See CTexturedRecognition");
74  defineOptionalProperty<int>(
75  "nMinValidFeatures",
76  10,
77  "minimum number of features in Houghspace. See CTexturedRecognition");
78  defineOptionalProperty<float>("MaxError",
79  3.3f,
80  "maximum error after application of homography on valid "
81  "features. See CTexturedRecognition");
82 
84  &stringToVector3f;
85 
86  defineOptionalProperty<Eigen::Vector3f>("MinPoint",
87  Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
88  "min point for valid result bounding box")
89  .setFactory(f);
90  defineOptionalProperty<Eigen::Vector3f>("MaxPoint",
91  Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
92  "max point for valid result bounding box")
93  .setFactory(f);
94 
95  defineOptionalProperty<int>(
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  */
117  {
120  }
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  {
164  debugObserver = getTopic<armarx::DebugObserverInterfacePrx>(
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 
224  armarx::DebugObserverInterfacePrx debugObserver;
225  };
226 } // namespace visionx
visionx::TexturedObjectRecognition::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes textured object instances
Definition: TexturedObjectRecognition.cpp:108
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:431
visionx::ObjectLocalizerProcessor::reportStereoCalibrationChanged
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizerProcessor.h:319
DebugObserver.h
visionx::TexturedObjectRecognitionPropertyDefinitions::TexturedObjectRecognitionPropertyDefinitions
TexturedObjectRecognitionPropertyDefinitions(std::string prefix)
Definition: TexturedObjectRecognition.h:61
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::TexturedObjectRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initializes the CTexturedRecognition.
Definition: TexturedObjectRecognition.h:162
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::TexturedObjectRecognition::getDefaultName
std::string getDefaultName() const override
Definition: TexturedObjectRecognition.h:126
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:432
visionx::TexturedObjectRecognition::initRecognizer
bool initRecognizer() override
Initializes textured recognition.
Definition: TexturedObjectRecognition.cpp:51
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:429
visionx::TexturedObjectRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: TexturedObjectRecognition.h:150
visionx::TexturedObjectRecognition::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TexturedObjectRecognition.h:116
visionx::TexturedObjectRecognition::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: TexturedObjectRecognition.h:172
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
visionx::ObjectLocalizerProcessor::getStereoCalibration
CStereoCalibration * getStereoCalibration() const
Retrieve stereo calibration corresponding to image provider.
Definition: ObjectLocalizerProcessor.h:391
visionx::TexturedObjectRecognitionPropertyDefinitions
Definition: TexturedObjectRecognition.h:45
visionx::TexturedObjectRecognition::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to textured object recognition.
Definition: TexturedObjectRecognition.cpp:82
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::TexturedObjectRecognition
TexturedObjectRecognition uses CTexturedRecognition of IVTRecognition in order to recognize and local...
Definition: TexturedObjectRecognition.h:109
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
visionx::TexturedObjectRecognition::reportStereoCalibrationChanged
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool x, const std::string &referenceFrame, const Ice::Current &c=Ice::emptyCurrent) override
Definition: TexturedObjectRecognition.h:132
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::PropertyDefinition::PropertyFactoryFunction
std::function< PropertyType(std::string)> PropertyFactoryFunction
Definition: PropertyDefinition.h:123
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:128