BlobRecognition.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 * @license http://www.gnu.org/licenses/gpl-2.0.txt
18 * GNU General Public License
19 */
20 
21 #pragma once
22 
23 
24 #include <Eigen/Core>
25 
27 
29 
31 
32 #include <Color/ColorParameterSet.h>
33 #include <Visualizer/OpenGLVisualizer.h>
34 
35 class CByteImage;
36 class CGLContext;
37 class CObjectFinderStereo;
38 
39 namespace visionx
40 {
41  using CObjectFinderStereoPtr = std::shared_ptr<CObjectFinderStereo>;
42  using CColorParameterSetPtr = std::shared_ptr<CColorParameterSet>;
43 
45  {
46  static inline Eigen::Vector3f
47  stringToVector3f(std::string propertyValue)
48  {
49  Eigen::Vector3f vec;
50  sscanf(propertyValue.c_str(),
51  "%f, %f, %f",
52  &vec.data()[0],
53  &vec.data()[1],
54  &vec.data()[2]);
55  return vec;
56  }
57 
58  public:
61  {
62  defineOptionalProperty<std::string>(
63  "ColorParameterFile",
64  "VisionX/examples/colors.txt",
65  "The color parameter file configures the colors used for segmentable recognition "
66  "(usually colors.txt)");
67  defineOptionalProperty<float>(
68  "MinPixelsPerRegion",
69  200,
70  "Minimum number of pixels per region for detecting a uniformly colored object");
71  defineOptionalProperty<float>(
72  "MaxEpipolarDistance",
73  6,
74  "Maximum epipolar line distance allowed for a valid 3D recognition result");
75 
77  &stringToVector3f;
78 
79  defineOptionalProperty<Eigen::Vector3f>("MinPoint",
80  Eigen::Vector3f(-3000.0f, -3000.0f, 100.0f),
81  "min point for valid result bounding box")
82  .setFactory(f);
83  defineOptionalProperty<Eigen::Vector3f>("MaxPoint",
84  Eigen::Vector3f(3000.0f, 3000.0f, 3500.0f),
85  "max point for valid result bounding box")
86  .setFactory(f);
87 
88  defineOptionalProperty<std::string>("RobotStateComponentName",
89  "RobotStateComponent",
90  "The name of the RobotStateComponent.");
91  }
92  };
93 
94  /**
95  * BlobRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
96  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
97  * The object localization is invoked automatically by the working memory if the object has been requested there.
98  *
99  */
101  {
102  public:
103  /**
104  * @see PropertyUser::createPropertyDefinitions()
105  */
108  {
111  }
112 
113  void
114  reportStereoCalibrationChanged(const StereoCalibration& stereoCalibration,
115  bool x,
116  const std::string& referenceName,
117  const Ice::Current& c = Ice::emptyCurrent) override
118  {
120  stereoCalibration, x, referenceName, c);
121 
122  initRecognizer();
123  }
124 
125  /**
126  * @see Component::getDefaultName()
127  */
128  std::string
129  getDefaultName() const override
130  {
131  return "BlobRecognition";
132  }
133 
134  BlobRecognition();
135  ~BlobRecognition() override;
136 
137  protected:
138  /**
139  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
140  */
141  void
143  {
144 
145  offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
146  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
147  }
148 
149  /**
150  * Initializes the CSegmentableRecognition
151  *
152  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
153  */
154  void
156  {
157 
158  debugObserver = getTopic<armarx::DebugObserverInterfacePrx>(
159  getProperty<std::string>("DebugObserverName").getValue());
160  robotStateComponent = getProxy<armarx::RobotStateComponentInterfacePrx>(
161  getProperty<std::string>("RobotStateComponentName").getValue());
162 
163  localRobot = armarx::RemoteRobot::createLocalCloneFromFile(robotStateComponent);
164  }
165 
166  /**
167  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
168  */
169  void onExitObjectLocalizerProcessor() override;
170 
171  /**
172  * Initializes segmentable recognition
173  *
174  * @return success
175  */
176  bool initRecognizer() override;
177 
178  /**
179  * Add object class to segmentable object recognition.
180  *
181  * @param objectClassEntity entity containing all information available for the object class
182  * @param fileManager GridFileManager required to read files associated to prior knowledge from the database.
183  *
184  * @return success of adding this entity to the TexturedObjectDatabase
185  */
186  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity,
187  const memoryx::GridFileManagerPtr& fileManager) override;
188 
189  /**
190  * localizes segmentable object instances
191  *
192  * @param objectClassNames names of the class to localize
193  * @param cameraImages the two input images
194  * @param resultImages the two result images. are provided if result images are enabled.
195  *
196  * @return list of object instances
197  */
198  memoryx::ObjectLocalizationResultList
199  localizeObjectClasses(const std::vector<std::string>& objectClassNames,
200  CByteImage** cameraImages,
201  armarx::MetaInfoSizeBasePtr imageMetaInfo,
202  CByteImage** resultImages) override;
203 
204  private:
205  // calculates recognition certainty
206  float calculateRecognitionCertainty(const std::string& objectClassName,
207  const Object3DEntry& entry);
208 
209  CObjectFinderStereoPtr objectFinderStereo;
210  std::shared_ptr<CGLContext> contextGL;
211  std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
212 
213  // settings
214  float minPixelsPerRegion;
215  float maxEpipolarDistance;
216  CColorParameterSetPtr colorParameters;
217 
218  // remember colors of objects (not stored i`n IVT viewdatabase)
219  std::map<std::string, ObjectColor> objectColors;
220  std::map<ObjectColor, std::string> colorToObjectClass;
221 
222 
223  Vec3d validResultBoundingBoxMin, validResultBoundingBoxMax;
224 
225 
226  std::map<std::string, int> seq;
227 
228  armarx::DebugObserverInterfacePrx debugObserver;
229  armarx::RobotStateComponentInterfacePrx robotStateComponent;
230 
231  VirtualRobot::RobotPtr localRobot;
232  };
233 } // namespace visionx
RemoteRobot.h
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
visionx::BlobRecognition::reportStereoCalibrationChanged
void reportStereoCalibrationChanged(const StereoCalibration &stereoCalibration, bool x, const std::string &referenceName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: BlobRecognition.h:114
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::BlobRecognition::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initializes the CSegmentableRecognition.
Definition: BlobRecognition.h:155
armarx::RemoteRobot::createLocalCloneFromFile
static VirtualRobot::RobotPtr createLocalCloneFromFile(RobotStateComponentInterfacePrx robotStatePrx, VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eFull)
This is a convenience function for createLocalClone, which automatically gets the filename from the R...
Definition: RemoteRobot.cpp:512
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::BlobRecognition::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: BlobRecognition.cpp:62
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:432
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::BlobRecognition::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: BlobRecognition.h:107
visionx::BlobRecognitionPropertyDefinitions
Definition: BlobRecognition.h:44
visionx::BlobRecognition::getDefaultName
std::string getDefaultName() const override
Definition: BlobRecognition.h:129
visionx::BlobRecognition::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: BlobRecognition.h:142
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:429
visionx::BlobRecognition::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
Add object class to segmentable object recognition.
Definition: BlobRecognition.cpp:116
visionx::BlobRecognition::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes segmentable object instances
Definition: BlobRecognition.cpp:150
visionx::BlobRecognition::~BlobRecognition
~BlobRecognition() override
Definition: BlobRecognition.cpp:52
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
visionx::BlobRecognition::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: BlobRecognition.cpp:57
visionx::BlobRecognition::BlobRecognition
BlobRecognition()
Definition: BlobRecognition.cpp:48
visionx::CObjectFinderStereoPtr
std::shared_ptr< CObjectFinderStereo > CObjectFinderStereoPtr
Definition: BlobRecognition.h:41
visionx::BlobRecognitionPropertyDefinitions::BlobRecognitionPropertyDefinitions
BlobRecognitionPropertyDefinitions(std::string prefix)
Definition: BlobRecognition.h:59
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::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
visionx::BlobRecognition
BlobRecognition uses CSegmentableRecognition from IVT to recognize and localize single-colored object...
Definition: BlobRecognition.h:100
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
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:128