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