Skip to content
This repository
Browse code

wrappers/cpp/libfreenect.hpp: Trivial changes to allow the resolution…

… parameters to be set.

Signed-off-by: Gabor Szarka <szarkagabor@coralworks.hu>
  • Loading branch information...
commit a283a0618261bd4e4324f1c70cc586da3f8be47c 1 parent 1a0ea42
Gábor Szarka gsx authored zarvox committed

Showing 1 changed file with 20 additions and 8 deletions. Show diff stats Hide diff stats

  1. +20 8 wrappers/cpp/libfreenect.hpp
28 wrappers/cpp/libfreenect.hpp
@@ -61,7 +61,9 @@ namespace Freenect {
61 61
62 62 class FreenectDevice : Noncopyable {
63 63 public:
64   - FreenectDevice(freenect_context *_ctx, int _index) {
  64 + FreenectDevice(freenect_context *_ctx, int _index)
  65 + : m_video_resolution(FREENECT_RESOLUTION_MEDIUM), m_depth_resolution(FREENECT_RESOLUTION_MEDIUM)
  66 + {
65 67 if(freenect_open_device(_ctx, &m_dev, _index) < 0) throw std::runtime_error("Cannot open Kinect");
66 68 freenect_set_user(m_dev, this);
67 69 freenect_set_video_mode(m_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
@@ -96,32 +98,40 @@ namespace Freenect {
96 98 FreenectTiltState getState() const {
97 99 return FreenectTiltState(freenect_get_tilt_state(m_dev));
98 100 }
99   - void setVideoFormat(freenect_video_format requested_format) {
100   - if (requested_format != m_video_format) {
  101 + void setVideoFormat(freenect_video_format requested_format, freenect_resolution requested_resolution = FREENECT_RESOLUTION_MEDIUM) {
  102 + if (requested_format != m_video_format || requested_resolution != m_video_resolution) {
101 103 freenect_stop_video(m_dev);
102   - freenect_frame_mode mode = freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, requested_format);
  104 + freenect_frame_mode mode = freenect_find_video_mode(requested_resolution, requested_format);
103 105 if (!mode.is_valid) throw std::runtime_error("Cannot set video format: invalid mode");
104 106 if (freenect_set_video_mode(m_dev, mode) < 0) throw std::runtime_error("Cannot set video format");
105 107 freenect_start_video(m_dev);
106 108 m_video_format = requested_format;
  109 + m_video_resolution = requested_resolution;
107 110 }
108 111 }
109 112 freenect_video_format getVideoFormat() {
110 113 return m_video_format;
111 114 }
112   - void setDepthFormat(freenect_depth_format requested_format) {
113   - if (requested_format != m_depth_format) {
  115 + freenect_resolution getVideoResolution() {
  116 + return m_video_resolution;
  117 + }
  118 + void setDepthFormat(freenect_depth_format requested_format, freenect_resolution requested_resolution = FREENECT_RESOLUTION_MEDIUM) {
  119 + if (requested_format != m_depth_format || requested_resolution != m_depth_resolution) {
114 120 freenect_stop_depth(m_dev);
115   - freenect_frame_mode mode = freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, requested_format);
  121 + freenect_frame_mode mode = freenect_find_depth_mode(requested_resolution, requested_format);
116 122 if (!mode.is_valid) throw std::runtime_error("Cannot set depth format: invalid mode");
117 123 if (freenect_set_depth_mode(m_dev, mode) < 0) throw std::runtime_error("Cannot set depth format");
118 124 freenect_start_depth(m_dev);
119 125 m_depth_format = requested_format;
  126 + m_depth_resolution = requested_resolution;
120 127 }
121 128 }
122 129 freenect_depth_format getDepthFormat() {
123 130 return m_depth_format;
124 131 }
  132 + freenect_resolution getDepthResolution() {
  133 + return m_depth_resolution;
  134 + }
125 135 // Do not call directly even in child
126 136 virtual void VideoCallback(void *video, uint32_t timestamp) = 0;
127 137 // Do not call directly even in child
@@ -136,7 +146,7 @@ namespace Freenect {
136 146 case FREENECT_VIDEO_IR_10BIT_PACKED:
137 147 case FREENECT_VIDEO_YUV_RGB:
138 148 case FREENECT_VIDEO_YUV_RAW:
139   - return freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, m_video_format).bytes;
  149 + return freenect_find_video_mode(m_video_resolution, m_video_format).bytes;
140 150 default:
141 151 return 0;
142 152 }
@@ -148,6 +158,8 @@ namespace Freenect {
148 158 freenect_device *m_dev;
149 159 freenect_video_format m_video_format;
150 160 freenect_depth_format m_depth_format;
  161 + freenect_resolution m_video_resolution;
  162 + freenect_resolution m_depth_resolution;
151 163 static void freenect_depth_callback(freenect_device *dev, void *depth, uint32_t timestamp) {
152 164 FreenectDevice* device = static_cast<FreenectDevice*>(freenect_get_user(dev));
153 165 device->DepthCallback(depth, timestamp);

0 comments on commit a283a06

Please sign in to comment.
Something went wrong with that request. Please try again.