OpenNIImageProvider.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::Component
19 * @author David Gonzalez (david dot gonzalez at kit dot edu)
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
27// VisionXCore
29
30// STL
31#include <float.h>
32
33#include <map>
34#include <string>
35
36// OpenNI
37#include <OpenNI.h>
38
39namespace visionx
40{
42 {
43
44 public:
46 {
48 "VideoMode", ImageDimension(320, 240), "Image resolution")
49 .setCaseInsensitive(true)
50 .map("320x240", ImageDimension(320, 240))
51 .map("640x480", ImageDimension(640, 480));
52
54 "ImageType", eColoredPointsScan, "Image type: RGB, Points, Points with RGB")
55 .setCaseInsensitive(true)
56 //.map("ePointsScan", ePointsScan)
57 .map("ColoredPointsScan", eColoredPointsScan);
58
59 defineOptionalProperty<float>("FrameRate", 30.0f, "Frames per second")
60 .setMatchRegex("\\d+(.\\d*)?")
61 .setMin(15.0f)
62 .setMax(30.0f);
63
64 // Camera URI
65 /*verify this lexical-rule*/
66 defineOptionalProperty<std::string>("DeviceURI", "ANY", "The URI from OpenNI API")
67 .setCaseInsensitive(true);
68 }
69 };
70
71 /**
72 * OpenNI image provider captures 3D-points and/or color(s) images from a single device and
73 * supports the following image transmission formats:
74 *
75 * - RGB: 3, bytes per Pixel
76 * - PointsScan (X,Y,Z): 3, floats per Pixel
77 * - ColoredPointsScan, Geometrically registered (X,Y,Z,R,G,B): 3 floats + 3 bytes per Pixel
78 *
79 * \componentproperties
80 * \prop VisionX.OpenNIImageProvider.CameraURI: The particular camera URI tha wanst to be addressed.
81 If not set the first device on the USBus will be opened .
82 * \prop VisionX.OpenNIImageProvider.VideoMode: Defines the camera
83 * resolution.
84 * - 320x240 (default)
85 * - 640x480
86 * \prop VisionX.OpenNIImageProvider.ImageType: Specifies how image type is composed.
87 * Possible values:
88 * - rgb
89 * - PointsScan
90 * - ColoredPointsScan
91 * \prop VisionX.OpenNIImageProvider.FrameRate: Capture frame rate as
92 * float (default: 30fps)
93 */
94
96 {
97
98 public:
99 /*NEEDS TO BE UPDATED WITH THE RGB->RGBA Changes
100 static CByteImage* Display(const visionx::ColoredPoint3D* pColoredPoint3DBufferBase,const int Width, const int Height,const bool DisplayColor)
101 {
102 if( (!pColoredPoint3DBufferBase) || (Width<1) || (Height<1) )
103 {
104 return NULL;
105 }
106
107 CByteImage* pDisplayImage = new CByteImage(Width,Height,CByteImage::eRGB24);
108
109 visionx::RGB* pRGB = (visionx::RGB*)(pDisplayImage->pixels);
110
111 const visionx::ColoredPoint3D* pColoredPoint3DBuffer = pColoredPoint3DBufferBase;
112
113 const visionx::ColoredPoint3D* const pEndColoredPoint3DBuffer = pColoredPoint3DBufferBase + (Width * Height);
114
115 if(DisplayColor)
116 {
117 while(pColoredPoint3DBuffer < pEndColoredPoint3DBuffer)
118 {
119 *pRGB++ = pColoredPoint3DBuffer->m_Color;
120
121 ++pColoredPoint3DBuffer;
122 }
123 }
124 else
125 {
126 float MinimalDepth = FLT_MAX;
127
128 float MaximalDepth = -FLT_MAX;
129
130 while(pColoredPoint3DBuffer<pEndColoredPoint3DBuffer)
131 {
132 if(pColoredPoint3DBuffer->m_Point.m_Z)
133 {
134
135 if(pColoredPoint3DBuffer->m_Point.m_Z > MaximalDepth)
136 MaximalDepth = pColoredPoint3DBuffer->m_Point.m_Z;
137
138
139 if(pColoredPoint3DBuffer->m_Point.m_Z < MinimalDepth)
140 MinimalDepth = pColoredPoint3DBuffer->m_Point.m_Z;
141
142 }
143
144 ++pColoredPoint3DBuffer;
145 }
146
147 const float DepthRange = MaximalDepth - MinimalDepth;
148
149 if(DepthRange < FLT_EPSILON)
150 {
151 memset(pRGB,128,sizeof(visionx::RGB) * Width * Height);
152
153 return pDisplayImage;
154 }
155
156 const float ScalingFactor = 255.0f / DepthRange;
157
158 pColoredPoint3DBuffer = pColoredPoint3DBufferBase;
159
160 while(pColoredPoint3DBuffer<pEndColoredPoint3DBuffer)
161 {
162 if(pColoredPoint3DBuffer->m_Point.m_Z)
163 {
164
165 pRGB->m_R = pRGB->m_G = pRGB->m_B = 255 - int(((pColoredPoint3DBuffer->m_Point.m_Z - MinimalDepth) * ScalingFactor) + 0.5f);
166
167 }
168 else
169 {
170 pRGB->m_R = 255;
171
172 pRGB->m_G = pRGB->m_B = 0;
173 }
174
175 ++pRGB;
176
177 ++pColoredPoint3DBuffer;
178 }
179 }
180
181 return pDisplayImage;
182 }*/
183
184 /**
185 * @see visionx::ImageProviderBase::onInitImageProvider()
186 */
187 virtual void onInitCapturingImageProvider();
188
189 /**
190 * @see visionx::ImageProviderBase::onExitImageProvider()
191 */
192 virtual void onExitCapturingImageProvider();
193
194 /**
195 * @see visionx::ImageProviderBase::onStartCapture()
196 */
197 virtual void onStartCapture(float frameRate);
198
199 /**
200 * @see visionx::ImageProviderBase::onStopCapture()
201 */
202 virtual void onStopCapture();
203
204 /**
205 * @see visionx::ImageProviderBase::capture()
206 */
207 virtual bool capture(void** ppImageBuffers);
208
209 /*
210 void provideImages(CByteImage** images);
211
212
213 void provideImages(CFloatImage** images);
214 */
215
216 /**
217 * @see armarx::Component::getDefaultName()
218 */
219 virtual std::string
221 {
222 return "OpenNIImageProvider";
223 }
224
225 /**
226 * @see PropertyUser::createPropertyDefinitions()
227 */
234
235
236 protected:
237 /**
238 * Camera URI
239 */
240 std::string uri;
241
242 /**
243 * Video dimension data
244 */
245 visionx::ImageDimension videoDimension;
246
247 /**
248 * Capturing frame rate
249 */
251
252 /**
253 * Capturing image type
254 */
255 visionx::ImageType imageType;
256
257 /**
258 * Captured images
259 */
260 visionx::ColoredPoint3D* coloredPoint3DBuffer;
261
262 /**
263 * OpenNI Capture
264 */
265
267 {
268 float nx;
269 float ny;
270 };
271
273
274 openni::Device deviceOpenNI;
275
276 openni::VideoStream depthStreamOpenNI;
277
278 openni::VideoStream colorStreamOpenNI;
279
280 openni::VideoFrameRef frameOpenNI;
281
283
285
286 bool StartDevice(const char* pDeviceURI, const int Width, const int Height, const int Fps);
287
289
291
292 bool StopDevice();
293
295
296 bool CaptureColoredPoint();
297
298 bool DispatchDepthFrame();
299
300 bool DispatchColorFrame();
301
302 int EnsureFPS(const int FPS);
303 };
304} // namespace visionx
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
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)
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
OpenNI image provider captures 3D-points and/or color(s) images from a single device and supports the...
openni::VideoFrameRef frameOpenNI
float frameRate
Capturing frame rate.
openni::VideoStream depthStreamOpenNI
openni::VideoStream colorStreamOpenNI
visionx::ImageDimension videoDimension
Video dimension data.
visionx::ImageType imageType
Capturing image type.
NormalizedDepthCell * normalizedDepthCells
visionx::ColoredPoint3D * coloredPoint3DBuffer
Captured images.
bool StartDevice(const char *pDeviceURI, const int Width, const int Height, const int Fps)
virtual void onStartCapture(float frameRate)
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions()
virtual std::string getDefaultName() const
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.