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 
28 
29 
31 
32 // IVT
33 #include <Color/ColorParameterSet.h>
34 #include <SegmentableRecognition/SegmentableRecognition.h>
35 #include <Visualizer/OpenGLVisualizer.h>
36 #include <Eigen/Core>
37 
38 // global forward declarations
39 class CByteImage;
40 class CGLContext;
41 
42 namespace visionx
43 {
44 
45 
46 
47  // shared pointer type definitions
48  using CSegmentableRecognitionPtr = std::shared_ptr<CSegmentableRecognition>;
49  using CColorParameterSetPtr = std::shared_ptr<CColorParameterSet>;
50 
51  // properties of SegmentableObjectRecognition
54  {
55  static inline Eigen::Vector3f stringToVector3f(std::string propertyValue)
56  {
57  Eigen::Vector3f vec;
58  sscanf(propertyValue.c_str(), "%f, %f, %f", &vec.data()[0], &vec.data()[1], &vec.data()[2]);
59  return vec;
60  }
61  public:
64  {
65  defineOptionalProperty<std::string>("ColorParameterFile", "VisionX/examples/colors.txt", "The color parameter file configures the colors used for segmentable recognition (usually colors.txt)");
66  defineOptionalProperty<float>("MinPixelsPerRegion", 200, "Minimum number of pixels per region for detecting a uniformly colored object");
67  defineOptionalProperty<float>("MaxEpipolarDistance", 6, "Maximum epipolar line distance allowed for a valid 3D recognition result");
68 
69 
71 
72  defineOptionalProperty<Eigen::Vector3f>("MinPoint", Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f), "min point for valid result bounding box").setFactory(f);
73  defineOptionalProperty<Eigen::Vector3f>("MaxPoint", Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f), "max point for valid result bounding box").setFactory(f);
74 
75  defineOptionalProperty<float>("SizeRatioThreshold", 0.7f, "");
76  defineOptionalProperty<float>("CorrelationThreshold", 0.7f, "");
77  }
78  };
79 
80  /**
81  * SegmentableObjectRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
82  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
83  * The object localization is invoked automatically by the working memory if the object has been requested there.
84  *
85  */
87  virtual public ObjectLocalizerProcessor
88  {
89  public:
90  /**
91  * @see PropertyUser::createPropertyDefinitions()
92  */
94  {
96  }
97 
98  void reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration, bool x, const std::string& referenceName, const Ice::Current& c = Ice::emptyCurrent) override
99  {
100  ObjectLocalizerProcessor::reportStereoCalibrationChanged(stereoCalibration, x, referenceName, c);
101 
102  initRecognizer();
103  }
104 
105  /**
106  * @see Component::getDefaultName()
107  */
108  std::string getDefaultName() const override
109  {
110  return "SegmentableObjectRecognition";
111  }
112 
115 
116  protected:
117  /**
118  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
119  */
121  {
122 
123  offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
124  }
125 
126  /**
127  * Initializes the CSegmentableRecognition
128  *
129  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
130  */
132  {
133 
134  debugObserver = getTopic<armarx::DebugObserverInterfacePrx>(getProperty<std::string>("DebugObserverName").getValue());
135  }
136 
137  /**
138  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
139  */
140  void onExitObjectLocalizerProcessor() override;
141 
142  /**
143  * Initializes segmentable recognition
144  *
145  * @return success
146  */
147  bool initRecognizer() override;
148 
149  /**
150  * Add object class to segmentable object recognition.
151  *
152  * @param objectClassEntity entity containing all information available for the object class
153  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
154  *
155  * @return success of adding this entity to the TexturedObjectDatabase
156  */
157  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity, const memoryx::GridFileManagerPtr& fileManager) override;
158 
159  /**
160  * localizes segmentable object instances
161  *
162  * @param objectClassNames names of the class to localize
163  * @param cameraImages the two input images
164  * @param resultImages the two result images. are provided if result images are enabled.
165  *
166  * @return list of object instances
167  */
168  memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector<std::string>& objectClassNames, CByteImage** cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage** resultImages) override;
169 
170  private:
171  // calculates recognition certainty
172  float calculateRecognitionCertainty(const std::string& objectClassName, const Object3DEntry& entry);
173  void visualizeResults(const Object3DList& objectList, CByteImage** resultImages);
174 
175  // pointer to IVT segmentable recognition
176  CSegmentableRecognitionPtr segmentableRecognition;
177  std::shared_ptr<CGLContext> contextGL;
178  std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
179 
180  // settings
181  float minPixelsPerRegion;
182  float maxEpipolarDistance;
183  CColorParameterSetPtr colorParameters;
184 
185  // remember colors of objects (not stored in IVT viewdatabase)
186  std::map<std::string, ObjectColor> objectColors;
187 
188  Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
189 
190 
191  std::map<std::string, int> seq;
192 
193 
194  armarx::DebugObserverInterfacePrx debugObserver;
195 
196  };
197 }
visionx::SegmentableObjectRecognition
SegmentableObjectRecognition uses CSegmentableRecognition from IVT to recognize and localize single-c...
Definition: SegmentableObjectRecognition.h:86
visionx::CColorParameterSetPtr
std::shared_ptr< CColorParameterSet > CColorParameterSetPtr
Definition: BlobRecognition.h:44
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
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::SegmentableObjectRecognition::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SegmentableObjectRecognition.h:93
visionx::SegmentableObjectRecognition::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: SegmentableObjectRecognition.cpp:61
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:375
visionx::SegmentableObjectRecognition::~SegmentableObjectRecognition
~SegmentableObjectRecognition() override
Definition: SegmentableObjectRecognition.cpp:56
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::SegmentableObjectRecognitionPropertyDefinitions::SegmentableObjectRecognitionPropertyDefinitions
SegmentableObjectRecognitionPropertyDefinitions(std::string prefix)
Definition: SegmentableObjectRecognition.h:62
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:372
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
visionx::SegmentableObjectRecognition::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes segmentable object instances
Definition: SegmentableObjectRecognition.cpp:174
visionx::CSegmentableRecognitionPtr
std::shared_ptr< CSegmentableRecognition > CSegmentableRecognitionPtr
Definition: ColorMarkerObjectLocalizer.h:43
visionx::SegmentableObjectRecognition::getDefaultName
std::string getDefaultName() const override
Definition: SegmentableObjectRecognition.h:108
visionx::SegmentableObjectRecognition::SegmentableObjectRecognition
SegmentableObjectRecognition()
Definition: SegmentableObjectRecognition.cpp:52
visionx::SegmentableObjectRecognition::reportStereoCalibrationChanged
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool x, const std::string &referenceName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: SegmentableObjectRecognition.h:98
visionx::SegmentableObjectRecognitionPropertyDefinitions
Definition: SegmentableObjectRecognition.h:52
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
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::SegmentableObjectRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initializes the CSegmentableRecognition.
Definition: SegmentableObjectRecognition.h:131
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
visionx::SegmentableObjectRecognition::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: SegmentableObjectRecognition.cpp:66
armarx::PropertyDefinition::PropertyFactoryFunction
std::function< PropertyType(std::string)> PropertyFactoryFunction
Definition: PropertyDefinition.h:114
visionx::SegmentableObjectRecognition::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to segmentable object recognition.
Definition: SegmentableObjectRecognition.cpp:140
visionx::SegmentableObjectRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: SegmentableObjectRecognition.h:120
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:107