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