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 <TexturedRecognition/TexturedRecognition.h>
35 #include <TexturedRecognition/TexturedObjectDatabase.h>
36 
37 
39 
40 
41 #include <Eigen/Core>
42 
43 namespace visionx
44 {
45 
46 
49  {
50  static inline Eigen::Vector3f stringToVector3f(std::string propertyValue)
51  {
52  Eigen::Vector3f vec;
53  sscanf(propertyValue.c_str(), "%f, %f, %f", &vec.data()[0], &vec.data()[1], &vec.data()[2]);
54  return vec;
55  }
56  public:
59  {
60  defineOptionalProperty<float>("SIFTThreshold", 0.01, "A threshold for detecting SIFT descriptors in the image. Smaller value -> more features found");
61 
62  defineOptionalProperty<float>("QualityThreshold", 0.0001, "Set quality threshold for Harris interest point calculation. Smaller means more features. See CTexturedRecognition");
63  defineOptionalProperty<int>("nMinValidFeatures", 10, "minimum number of features in Houghspace. See CTexturedRecognition");
64  defineOptionalProperty<float>("MaxError", 3.3f, "maximum error after application of homography on valid features. See CTexturedRecognition");
65 
67 
68  defineOptionalProperty<Eigen::Vector3f>("MinPoint", Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f), "min point for valid result bounding box").setFactory(f);
69  defineOptionalProperty<Eigen::Vector3f>("MaxPoint", Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f), "max point for valid result bounding box").setFactory(f);
70 
71  defineOptionalProperty<int>("StereoCorrelationWindowSize", 19, "Correlation size for stereo matching");
72  defineOptionalProperty<float>("StereoCorrelationThreshold", 0.7f, "The threshold for the Zero Mean-Normalized Cross Correlation (ZNCC, range: 0.0 - 1.0).");
73  }
74  };
75 
76 
77  /**
78  * TexturedObjectRecognition uses CTexturedRecognition of IVTRecognition in order to recognize and localize objects.
79  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
80  * The object localization is invoked automatically by the working memory if the object has been requested there.
81  */
83  virtual public ObjectLocalizerProcessor
84  {
85  public:
86  /**
87  * @see PropertyUser::createPropertyDefinitions()
88  */
90  {
92  }
93 
94  /**
95  * @see Component::getDefaultName()
96  */
97  std::string getDefaultName() const override
98  {
99  return "TexturedObjectRecognition";
100  }
101 
102  void reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration, bool x, const std::string& referenceFrame, const Ice::Current& c = Ice::emptyCurrent) override
103  {
104  ObjectLocalizerProcessor::reportStereoCalibrationChanged(stereoCalibration, x, referenceFrame, c);
105 
106  texturedRecognition->GetObjectDatabase()->InitCameraParameters(getStereoCalibration(), true);
107  texturedRecognition->GetObjectDatabase()->SetCorrelationParameters(19, 400, 3500, 0.7f);
108  }
109 
110  protected:
111  /**
112  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
113  */
115  {
116 
117  offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
118  }
119 
120  /**
121  * Initializes the CTexturedRecognition
122  *
123  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
124  */
126  {
127  debugObserver = getTopic<armarx::DebugObserverInterfacePrx>(getProperty<std::string>("DebugObserverName").getValue());
128  }
129 
130  /**
131  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
132  */
134 
135  /**
136  * Initializes textured recognition
137  *
138  * @return success
139  */
140  bool initRecognizer() override;
141 
142  /**
143  * Add object class to textured object recognition.
144  *
145  * @param objectClassEntity entity containing all information available for the object class
146  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
147  *
148  * @return success of adding this entity to the TexturedObjectDatabase
149  */
150  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity, const memoryx::GridFileManagerPtr& fileManager) override;
151 
152  /**
153  * localizes textured object instances
154  *
155  * @param objectClassNames names of the class to localize
156  * @param cameraImages the two input images
157  * @param resultImages the two result images. are provided if result images are enabled.
158  *
159  * @return list of object instances
160  */
161  memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector<std::string>& objectClassNames, CByteImage** cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage** resultImages) override;
162 
163 
164  private:
165  // calculates recognition certainty
166  float calculateRecognitionCertainty(const std::string& objectClassName, const Object3DEntry& entry);
167  Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
168 
169  // textured recognition
170  CTexturedRecognition* texturedRecognition = nullptr;
171  int correlationWindowSize = 0;
172  float correlationThreshold = 0.0f;
173 
174  int seq;
175 
176 
177  armarx::DebugObserverInterfacePrx debugObserver;
178 
179 
180  };
181 }
182 
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:99
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:374
visionx::ObjectLocalizerProcessor::reportStereoCalibrationChanged
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ObjectLocalizerProcessor.h:272
DebugObserver.h
visionx::TexturedObjectRecognitionPropertyDefinitions::TexturedObjectRecognitionPropertyDefinitions
TexturedObjectRecognitionPropertyDefinitions(std::string prefix)
Definition: TexturedObjectRecognition.h:57
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::TexturedObjectRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initializes the CTexturedRecognition.
Definition: TexturedObjectRecognition.h:125
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::TexturedObjectRecognition::getDefaultName
std::string getDefaultName() const override
Definition: TexturedObjectRecognition.h:97
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:375
visionx::TexturedObjectRecognition::initRecognizer
bool initRecognizer() override
Initializes textured recognition.
Definition: TexturedObjectRecognition.cpp:50
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:372
visionx::TexturedObjectRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: TexturedObjectRecognition.h:114
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
visionx::TexturedObjectRecognition::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TexturedObjectRecognition.h:89
visionx::TexturedObjectRecognition::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: TexturedObjectRecognition.h:133
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
visionx::ObjectLocalizerProcessor::getStereoCalibration
CStereoCalibration * getStereoCalibration() const
Retrieve stereo calibration corresponding to image provider.
Definition: ObjectLocalizerProcessor.h:334
visionx::TexturedObjectRecognitionPropertyDefinitions
Definition: TexturedObjectRecognition.h:47
visionx::TexturedObjectRecognition::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to textured object recognition.
Definition: TexturedObjectRecognition.cpp:77
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::TexturedObjectRecognition
TexturedObjectRecognition uses CTexturedRecognition of IVTRecognition in order to recognize and local...
Definition: TexturedObjectRecognition.h:82
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:102
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::PropertyDefinition::PropertyFactoryFunction
std::function< PropertyType(std::string)> PropertyFactoryFunction
Definition: PropertyDefinition.h:114
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:107