ColorStream.cpp
Go to the documentation of this file.
1 #include <string>
2 #include "ColorStream.hpp"
3 
4 using namespace FreenectDriver;
5 
6 
8 {
11  pDevice->startVideo();
12 }
13 
14 // Add video modes here as you implement them
16 {
18  // pixelFormat, resolutionX, resolutionY, fps freenect_video_format, freenect_resolution
19  modes[makeOniVideoMode(ONI_PIXEL_FORMAT_RGB888, 640, 480, 30)] = std::pair<freenect_video_format, freenect_resolution>(FREENECT_VIDEO_RGB, FREENECT_RESOLUTION_MEDIUM);
20 
21 
22  return modes;
23 
24  /* working format possiblities
25  FREENECT_VIDEO_RGB
26  FREENECT_VIDEO_YUV_RGB
27  FREENECT_VIDEO_YUV_RAW
28  */
29 }
30 
32 {
34  FreenectVideoModeMap::const_iterator matched_mode_iter = supported_video_modes.find(requested_mode);
35  if (matched_mode_iter == supported_video_modes.end())
37 
38  freenect_video_format format = matched_mode_iter->second.first;
39  freenect_resolution resolution = matched_mode_iter->second.second;
40 
41  try { device->setVideoFormat(format, resolution); }
42  catch (std::runtime_error e)
43  {
44  LogError("Format " + to_string(format) + " and resolution " + to_string(resolution) + " combination not supported by libfreenect");
46  }
47  video_mode = requested_mode;
48  return ONI_STATUS_OK;
49 }
50 
51 void ColorStream::populateFrame(void* data, OniFrame* frame) const
52 {
53  frame->sensorType = sensor_type;
54  frame->stride = video_mode.resolutionX * 3;
55  frame->cropOriginX = 0;
56  frame->cropOriginY = 0;
57  frame->croppingEnabled = false;
58 
59  // copy stream buffer from freenect
60  switch (video_mode.pixelFormat)
61  {
62  default:
63  LogError("Pixel format " + to_string(video_mode.pixelFormat) + " not supported by populateFrame()");
64  return;
65 
67  uint8_t* source = static_cast<uint8_t*>(data);
68  uint8_t* target = static_cast<uint8_t*>(frame->data);
69  std::copy(source, source + frame->dataSize, target);
70  return;
71  }
72 }
73 
74 /* color video modes reference
75 
76 FREENECT_VIDEO_RGB = 0, //< Decompressed RGB mode (demosaicing done by libfreenect)
77 FREENECT_VIDEO_BAYER = 1, //< Bayer compressed mode (raw information from camera)
78 FREENECT_VIDEO_YUV_RGB = 5, //< YUV RGB mode
79 FREENECT_VIDEO_YUV_RAW = 6, //< YUV Raw mode
80 
81 ONI_PIXEL_FORMAT_RGB888 = 200,
82 ONI_PIXEL_FORMAT_YUV422 = 201,
83 ONI_PIXEL_FORMAT_JPEG = 204,
84 */
int dataSize
Definition: OniCTypes.h:97
static void LogError(std::string error)
Definition: Utility.hpp:66
freenect_video_format
Definition: libfreenect.h:86
int stride
Definition: OniCTypes.h:112
ColorStream(Freenect::FreenectDevice *pDevice)
Definition: ColorStream.cpp:7
static FreenectVideoModeMap getSupportedVideoModes()
Definition: ColorStream.cpp:15
int cropOriginX
Definition: OniCTypes.h:109
unsigned char uint8_t
int frame
Definition: regview.c:72
void populateFrame(void *data, OniFrame *frame) const
Definition: ColorStream.cpp:51
string target
Definition: fwfetcher.py:543
void setVideoFormat(freenect_video_format requested_format, freenect_resolution requested_resolution=FREENECT_RESOLUTION_MEDIUM)
OniBool croppingEnabled
Definition: OniCTypes.h:108
int cropOriginY
Definition: OniCTypes.h:110
std::map< OniVideoMode, std::pair< freenect_video_format, freenect_resolution > > FreenectVideoModeMap
Definition: ColorStream.hpp:21
OniSensorType sensorType
Definition: OniCTypes.h:100
Freenect::FreenectDevice * device
Definition: VideoStream.hpp:20
OniStatus setVideoMode(OniVideoMode requested_mode)
Definition: ColorStream.cpp:31
void * data
Definition: OniCTypes.h:98
int resolutionX
Definition: OniCTypes.h:62
OniPixelFormat pixelFormat
Definition: OniCTypes.h:61
static freenect_frame_mode supported_video_modes[video_mode_count]
Definition: cameras.c:42
static const OniSensorType sensor_type
Definition: ColorStream.hpp:22
freenect_resolution
Definition: libfreenect.h:77
static OniVideoMode makeOniVideoMode(OniPixelFormat pixel_format, int resolution_x, int resolution_y, int frames_per_second)
Definition: Utility.hpp:10
static std::string to_string(const T &n)
Definition: Utility.hpp:48
OniStatus
Definition: OniCEnums.h:25


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38