ColorMarkerObjectLocalizer.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 // IVT
29 #include <Color/ColorParameterSet.h>
30 #include <SegmentableRecognition/SegmentableRecognition.h>
31 #include <Visualizer/OpenGLVisualizer.h>
32 
33 
34 #include <VirtualRobot/VirtualRobot.h>
35 
36 // global forward declarations
37 class CByteImage;
38 class CGLContext;
39 
40 namespace visionx
41 {
42  // shared pointer type definitions
43  using CSegmentableRecognitionPtr = std::shared_ptr<CSegmentableRecognition>;
44  using CColorParameterSetPtr = std::shared_ptr<CColorParameterSet>;
45 
46  // properties of ColorMarkerObjectLocalizer
49  {
50  public:
53  {
54  defineOptionalProperty<std::string>("ColorParameterFile", "VisionX/examples/colors.txt", "The color parameter file configures the colors used for segmentable recognition (usually colors.txt)");
55  defineOptionalProperty<float>("MinPixelsPerRegion", 4, "Minimum number of pixels per region for detecting a uniformly colored object");
56  defineOptionalProperty<float>("MaxEpipolarDistance", 4, "Maximum epipolar line distance allowed for a valid 3D recognition result");
57  defineOptionalProperty<int>("NumObjectMarker", 4, "Number of markers");
58  defineOptionalProperty<int>("Hue", 4, "Hue value of object marker");
59  defineOptionalProperty<int>("HueTolerance", 4, "Hue tolerance value of object marker");
60  defineOptionalProperty<int>("MinSaturation", 0, "Minimum saturation");
61  defineOptionalProperty<int>("MaxSaturation", 255, "Maximum saturation");
62  defineOptionalProperty<int>("MinValue", 0, "Minimum value");
63  defineOptionalProperty<int>("MaxValue", 255, "Maximum value");
64  defineOptionalProperty<std::string>("MarkerColor", "Yellow3", "Marker Color");
65  defineOptionalProperty<std::string>("MarkeredObjectName", "MarkeredObject", "Name of the object");
66  }
67  };
68 
69  /**
70  * ColorMarkerObjectLocalizer uses CSegmentableRecognition from IVT to recognize and localize single-colored objects based on their color and shape.
71  * The object data is read from PriorKnowledge and CommonStorage via MemoryX.
72  * The object localization is invoked automatically by the working memory if the object has been requested there.
73  *
74  */
76  virtual public ObjectLocalizerProcessor
77  {
78  public:
79  /**
80  * @see PropertyUser::createPropertyDefinitions()
81  */
83  {
85  }
86 
87  /**
88  * @see Component::getDefaultName()
89  */
90  std::string getDefaultName() const override
91  {
92  return "ColorMarkerObjectLocalizer";
93  }
94 
96  ~ColorMarkerObjectLocalizer() override;
97 
98  protected:
99  /**
100  * @see ObjectLocalizerProcessor::onInitObjectLocalizerProcessor()
101  */
102  void onInitObjectLocalizerProcessor() override;
103 
104  /**
105  * Initializes the CSegmentableRecognition
106  *
107  * @see ObjectLocalizerProcessor::onConnectObjectLocalizerProcessor()
108  */
109  void onConnectObjectLocalizerProcessor() override;
110 
111  /**
112  * @see ObjectLocalizerProcessor::onExitObjectLocalizerProcessor()
113  */
114  void onExitObjectLocalizerProcessor() override;
115 
116  /**
117  * Initializes segmentable recognition
118  *
119  * @return success
120  */
121  bool initRecognizer() override;
122 
123  /**
124  * localizes object markers instances
125  *
126  * @param objectClassNames names of the class to localize
127  * @param cameraImages the two input images
128  * @param resultImages the two result images. are provided if result images are enabled.
129  *
130  * @return list of object instances
131  */
132  memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector<std::string>& objectClassNames, CByteImage** cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage** resultImages) override;
133  bool addObjectClass(const memoryx::EntityPtr& objectClassEntity, const memoryx::GridFileManagerPtr& fileManager) override;
134 
135  private:
136  // calculates recognition certainty
137  float calculateRecognitionCertainty(const std::string& objectClassName, const Object3DEntry& entry);
138  void visualizeResults(const Object3DList& objectList, CByteImage** resultImages);
139 
140  // pointer to IVT segmentable recognition
141  CSegmentableRecognitionPtr segmentableRecognition;
142  std::shared_ptr<CGLContext> contextGL;
143  std::shared_ptr<COpenGLVisualizer> m_pOpenGLVisualizer;
144 
145  // settings
146  float minPixelsPerRegion;
147  float maxEpipolarDistance;
148  unsigned int numObjectMarker;
149  int hue;
150  int hueTol;
151  int minS;
152  int maxS;
153  int minV;
154  int maxV;
155  std::string markeredObjectName;
156  CColorParameterSetPtr colorParameters;
157  ObjectColor objectMarkerColor;
158 
159  VirtualRobot::RobotPtr remoteRobot;
160 
161  // remember colors of objects (not stored in IVT viewdatabase)
162  std::map<std::string, ObjectColor> objectColors;
163  };
164 }
visionx::CColorParameterSetPtr
std::shared_ptr< CColorParameterSet > CColorParameterSetPtr
Definition: BlobRecognition.h:44
visionx::ColorMarkerObjectLocalizer::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: ColorMarkerObjectLocalizer.cpp:73
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:374
visionx::ColorMarkerObjectLocalizer::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: ColorMarkerObjectLocalizer.cpp:62
visionx::ColorMarkerObjectLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ColorMarkerObjectLocalizer.h:82
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ColorMarkerObjectLocalizerPropertyDefinitions::ColorMarkerObjectLocalizerPropertyDefinitions
ColorMarkerObjectLocalizerPropertyDefinitions(std::string prefix)
Definition: ColorMarkerObjectLocalizer.h:51
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::ColorMarkerObjectLocalizer::~ColorMarkerObjectLocalizer
~ColorMarkerObjectLocalizer() override
Definition: ColorMarkerObjectLocalizer.cpp:57
visionx::ColorMarkerObjectLocalizer::localizeObjectClasses
memoryx::ObjectLocalizationResultList localizeObjectClasses(const std::vector< std::string > &objectClassNames, CByteImage **cameraImages, armarx::MetaInfoSizeBasePtr imageMetaInfo, CByteImage **resultImages) override
localizes object markers instances
Definition: ColorMarkerObjectLocalizer.cpp:145
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:375
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:372
visionx::CSegmentableRecognitionPtr
std::shared_ptr< CSegmentableRecognition > CSegmentableRecognitionPtr
Definition: ColorMarkerObjectLocalizer.h:43
visionx::ColorMarkerObjectLocalizer::getDefaultName
std::string getDefaultName() const override
Definition: ColorMarkerObjectLocalizer.h:90
visionx::ColorMarkerObjectLocalizer::ColorMarkerObjectLocalizer
ColorMarkerObjectLocalizer()
Definition: ColorMarkerObjectLocalizer.cpp:53
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
visionx::ColorMarkerObjectLocalizer::addObjectClass
bool addObjectClass(const memoryx::EntityPtr &objectClassEntity, const memoryx::GridFileManagerPtr &fileManager) override
ObjectLocalizerProcessor interface: The addObjectClass method needs to be implemented by any ObjectLo...
Definition: ColorMarkerObjectLocalizer.cpp:604
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:32
visionx::ColorMarkerObjectLocalizer::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: ColorMarkerObjectLocalizer.cpp:78
visionx::ColorMarkerObjectLocalizer
ColorMarkerObjectLocalizer uses CSegmentableRecognition from IVT to recognize and localize single-col...
Definition: ColorMarkerObjectLocalizer.h:75
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
visionx::ColorMarkerObjectLocalizerPropertyDefinitions
Definition: ColorMarkerObjectLocalizer.h:47
visionx::ColorMarkerObjectLocalizer::onConnectObjectLocalizerProcessor
void onConnectObjectLocalizerProcessor() override
Initializes the CSegmentableRecognition.
Definition: ColorMarkerObjectLocalizer.cpp:67
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:107