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