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
36 class CByteImage;
37 class CGLContext;
38 
39 namespace 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  {
53  defineOptionalProperty<std::string>(
54  "ColorParameterFile",
55  "VisionX/examples/colors.txt",
56  "The color parameter file configures the colors used for segmentable recognition "
57  "(usually colors.txt)");
58  defineOptionalProperty<float>(
59  "MinPixelsPerRegion",
60  4,
61  "Minimum number of pixels per region for detecting a uniformly colored object");
62  defineOptionalProperty<float>(
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");
74  defineOptionalProperty<std::string>(
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  */
93  {
96  }
97 
98  /**
99  * @see Component::getDefaultName()
100  */
101  std::string
102  getDefaultName() const override
103  {
104  return "ColorMarkerObjectLocalizer";
105  }
106 
108  ~ColorMarkerObjectLocalizer() override;
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
visionx::CColorParameterSetPtr
std::shared_ptr< CColorParameterSet > CColorParameterSetPtr
Definition: BlobRecognition.h:42
visionx::ColorMarkerObjectLocalizer::onExitObjectLocalizerProcessor
void onExitObjectLocalizerProcessor() override
Definition: ColorMarkerObjectLocalizer.cpp:75
visionx::ObjectLocalizerProcessor::resultImages
CByteImage ** resultImages
Definition: ObjectLocalizerProcessor.h:431
visionx::ColorMarkerObjectLocalizer::onInitObjectLocalizerProcessor
void onInitObjectLocalizerProcessor() override
Definition: ColorMarkerObjectLocalizer.cpp:61
visionx::ColorMarkerObjectLocalizer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ColorMarkerObjectLocalizer.h:92
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ColorMarkerObjectLocalizerPropertyDefinitions::ColorMarkerObjectLocalizerPropertyDefinitions
ColorMarkerObjectLocalizerPropertyDefinitions(std::string prefix)
Definition: ColorMarkerObjectLocalizer.h:50
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::ColorMarkerObjectLocalizer::~ColorMarkerObjectLocalizer
~ColorMarkerObjectLocalizer() override
Definition: ColorMarkerObjectLocalizer.cpp:56
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:148
visionx::ObjectLocalizerProcessor::imageMetaInfo
armarx::MetaInfoSizeBasePtr imageMetaInfo
Definition: ObjectLocalizerProcessor.h:432
IceInternal::Handle
Definition: forward_declarations.h:8
ObjectLocalizerProcessor.h
visionx::ObjectLocalizerProcessor::cameraImages
CByteImage * cameraImages[2]
Definition: ObjectLocalizerProcessor.h:429
visionx::CSegmentableRecognitionPtr
std::shared_ptr< CSegmentableRecognition > CSegmentableRecognitionPtr
Definition: ColorMarkerObjectLocalizer.h:42
visionx::ColorMarkerObjectLocalizer::getDefaultName
std::string getDefaultName() const override
Definition: ColorMarkerObjectLocalizer.h:102
visionx::ColorMarkerObjectLocalizer::ColorMarkerObjectLocalizer
ColorMarkerObjectLocalizer()
Definition: ColorMarkerObjectLocalizer.cpp:52
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
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:636
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
visionx::ColorMarkerObjectLocalizer::initRecognizer
bool initRecognizer() override
Initializes segmentable recognition.
Definition: ColorMarkerObjectLocalizer.cpp:80
visionx::ColorMarkerObjectLocalizer
ColorMarkerObjectLocalizer uses CSegmentableRecognition from IVT to recognize and localize single-col...
Definition: ColorMarkerObjectLocalizer.h:85
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ObjectLocalizerProcessorPropertyDefinitions
Definition: ObjectLocalizerProcessor.h:78
visionx::ColorMarkerObjectLocalizerPropertyDefinitions
Definition: ColorMarkerObjectLocalizer.h:46
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:35
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
visionx::ObjectLocalizerProcessor
ObjectLocalizerProcessor.
Definition: ObjectLocalizerProcessor.h:128