Component.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::ArmarXObjects::Yolo
17 * @author Christian R. G. Dreher <c.dreher@kit.edu>
18 * @date 2019
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#pragma once
25
26
27// STD/STL
28#include <memory>
29#include <mutex>
30#include <string>
31#include <vector>
32
33// IVT
34#include <Image/ByteImage.h>
35
36// Darknet
37#include <darknet.h>
38
39// Ice
40#include <Ice/Current.h>
41#include <IceUtil/Time.h>
42
43// ArmarX
46
48#include <VisionX/interface/components/YoloComponentInterface.h>
49#include <VisionX/interface/components/YoloObjectListener.h>
50#include <VisionX/interface/core/ImageProviderInterface.h>
52
54{
55
56 class Component :
57 virtual public visionx::ImageProcessor,
58 virtual public ComponentInterface,
59 virtual public armarx::Logging
60 {
61
62 public:
63 static const std::string default_name;
64
65 private:
66 bool m_image_received;
67
68 std::mutex m_input_image_mutex;
69
70 std::string m_image_provider_id;
71 visionx::ImageProviderInfo m_image_provider_info;
72
73 IceUtil::Time m_timestamp_last_image;
74
75 ::CByteImage** m_input_image_buf;
76 CByteImageUPtr m_input_image;
77 CByteImageUPtr m_output_image;
78
80
81 visionx::ImageProviderInterfacePrx m_image_provider;
82 unsigned int m_image_provider_channel;
83
84 ObjectListener::ProxyType m_object_detection_listener;
85
86 IceUtil::Time m_minimum_loop_time;
87
88 /**
89 * @brief Darknet's network.
90 */
91 darknet::network m_network;
92
93 std::vector<std::string> m_darknet_classes;
94
95 public:
96 virtual ~Component() override;
97
98 /**
99 * @see visionx::ImageProcessor::onInitImageProcessor()
100 */
101 virtual void onInitImageProcessor() override;
102
103 /**
104 * @see visionx::ImageProcessor::onConnectImageProcessor()
105 */
106 virtual void onConnectImageProcessor() override;
107
108 /**
109 * @see visionx::ImageProcessor::onDisconnectImageProcessor()
110 */
111 virtual void onDisconnectImageProcessor() override;
112
113 /**
114 * @see visionx::ImageProcessor::onExitImageProcessor()
115 */
116 virtual void onExitImageProcessor() override;
117
118 /**
119 * @see armarx::ManagedIceObject::getDefaultName()
120 */
121 virtual std::string getDefaultName() const override;
122
123 /**
124 * @see visionx::ImageProcessor::process()
125 */
126 virtual void process() override;
127
128 /**
129 * @see PropertyUser::createPropertyDefinitions()
130 */
132
133 /**
134 * @brief Converts Darknet types to VisionX types.
135 * @param detections Array of detections.
136 * @param classes Available classes as strings in correct order.
137 * @return Converted Ice types as vector of DetectedObjects.
138 */
139 static std::vector<DetectedObject>
140 convertOutput(const std::vector<darknet::detection>& detections,
141 const std::vector<std::string>& classes);
142
143 /**
144 * @brief Renders the objects detectedObjects, belonging to one of a class defined in
145 * classes onto the outputImage (initialsed from inputImage).
146 * @param inputImage The base image output_image is initialised from.
147 * @param detectedObjects All detected objects to be rendered.
148 * @param classes List of all classes an object can belong to.
149 * @param outputImage Ouput variable of the resulting rendered image.
150 */
151 static void renderOutput(const ::CByteImage* inputImage,
152 const std::vector<DetectedObject>& detectedObjects,
153 ::CByteImage* outputImage);
154
155 /**
156 * @brief Restores the default parameter values.
157 */
158 virtual void restoreDefaults(const Ice::Current& = Ice::Current{}) override;
159
160 /**
161 * @brief Returns the currently set thresh parameter.
162 * @return Currently set thresh parameter.
163 */
164 virtual double getThresh(const Ice::Current&) override;
165
166 /**
167 * @brief Sets the new thresh parameter.
168 * @param thresh New thresh.
169 */
170 virtual void setThresh(double thresh, const Ice::Current&) override;
171
172 /**
173 * @brief Returns the currently set hierThresh parameter.
174 * @return Currently set hierThresh parameter.
175 */
176 virtual double getHierThresh(const Ice::Current&) override;
177
178 virtual float getFpsCap(const Ice::Current&) override;
179
180 /**
181 * @brief Sets the new hierThresh parameter.
182 * @param hier_thresh New hierThresh.
183 */
184 virtual void setHierThresh(double hier_thresh, const Ice::Current&) override;
185
186 /**
187 * @brief Returns the currently set nms parameter.
188 * @return Currently set nms parameter.
189 */
190 virtual double getNms(const Ice::Current&) override;
191
192 /**
193 * @brief Sets the new nms parameter.
194 * @param nms New nms.
195 */
196 virtual void setNms(double nms, const Ice::Current&) override;
197
198 virtual void setFpsCap(float fps_cap, const Ice::Current& = Ice::Current{}) override;
199
200 /**
201 * @brief Returns the list of all known classes.
202 * @return List of all known classes.
203 */
204 virtual std::vector<std::string> getClasses(const Ice::Current&) override;
205
206 private:
207 /**
208 * @brief Bootstraps Darknet.
209 *
210 * Initialises Darknet so it can quickly be accessed afterwards. Bootstrapping usually
211 * takes a while.
212 */
213 virtual void bootstrap_darknet();
214
215 /**
216 * @brief Run Darknet to detect objects in the current image.
217 */
218 virtual void run_object_detection_task();
219 };
220
221} // namespace visionx::yolo
222
223namespace visionx
224{
226}
Base Class for all Logging classes.
Definition Logging.h:240
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
static const std::string default_name
Definition Component.h:63
virtual double getNms(const Ice::Current &) override
Returns the currently set nms parameter.
virtual void onConnectImageProcessor() override
virtual void setThresh(double thresh, const Ice::Current &) override
Sets the new thresh parameter.
virtual void onExitImageProcessor() override
static void renderOutput(const ::CByteImage *inputImage, const std::vector< DetectedObject > &detectedObjects, ::CByteImage *outputImage)
Renders the objects detectedObjects, belonging to one of a class defined in classes onto the outputIm...
virtual void setHierThresh(double hier_thresh, const Ice::Current &) override
Sets the new hierThresh parameter.
virtual void setNms(double nms, const Ice::Current &) override
Sets the new nms parameter.
virtual void process() override
virtual float getFpsCap(const Ice::Current &) override
virtual ~Component() override
Definition Component.cpp:64
virtual void setFpsCap(float fps_cap, const Ice::Current &=Ice::Current{}) override
virtual void onInitImageProcessor() override
Definition Component.cpp:70
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
static std::vector< DetectedObject > convertOutput(const std::vector< darknet::detection > &detections, const std::vector< std::string > &classes)
Converts Darknet types to VisionX types.
virtual double getThresh(const Ice::Current &) override
Returns the currently set thresh parameter.
virtual void onDisconnectImageProcessor() override
virtual std::vector< std::string > getClasses(const Ice::Current &) override
Returns the list of all known classes.
virtual double getHierThresh(const Ice::Current &) override
Returns the currently set hierThresh parameter.
virtual std::string getDefaultName() const override
virtual void restoreDefaults(const Ice::Current &=Ice::Current{}) override
Restores the default parameter values.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.
visionx::yolo::Component Yolo
Definition Component.h:225
std::unique_ptr< CByteImage > CByteImageUPtr