Permalink
Browse files

Expose depth smoothing mode register through API.

Signed-off-by: Rene Wagner <rwagner@informatik.uni-bremen.de>
  • Loading branch information...
1 parent 06e48e5 commit b92239e8b3052539ecb8904f717f9c20105b52b7 @renewagner committed Mar 26, 2012
Showing with 43 additions and 1 deletion.
  1. +14 −1 examples/glview.c
  2. +16 −0 include/libfreenect.h
  3. +13 −0 src/cameras.c
View
15 examples/glview.c
@@ -71,6 +71,9 @@ int freenect_angle = 0;
freenect_video_format requested_format = FREENECT_VIDEO_RGB;
freenect_video_format current_format = FREENECT_VIDEO_RGB;
+freenect_smoothing_mode requested_smoothing = FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED;
+freenect_smoothing_mode current_smoothing = FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED;
+
pthread_cond_t gl_frame_cond = PTHREAD_COND_INITIALIZER;
int got_rgb = 0;
int got_depth = 0;
@@ -178,6 +181,12 @@ void keyPressed(unsigned char key, int x, int y)
freenect_angle = -30;
}
}
+ if (key == 'm') {
+ if (requested_smoothing == FREENECT_SMOOTHING_DISABLED)
+ requested_smoothing = FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED;
+ else
+ requested_smoothing = FREENECT_SMOOTHING_DISABLED;
+ }
}
void ReSizeGLScene(int Width, int Height)
@@ -327,6 +336,10 @@ void *freenect_threadfunc(void *arg)
freenect_start_video(f_dev);
current_format = requested_format;
}
+ if (requested_smoothing != current_smoothing){
+ freenect_set_smoothing_mode(f_dev, requested_smoothing);
+ current_smoothing = requested_smoothing;
+ }
}
printf("\nshutting down streams...\n");
@@ -368,7 +381,7 @@ int main(int argc, char **argv)
return 1;
}
- freenect_set_log_level(f_ctx, FREENECT_LOG_SPEW);
+ freenect_set_log_level(f_ctx, FREENECT_LOG_INFO);
freenect_select_subdevices(f_ctx, (freenect_device_flags)(FREENECT_DEVICE_CAMERA));
int nr_devices = freenect_num_devices (f_ctx);
View
16 include/libfreenect.h
@@ -127,6 +127,12 @@ typedef struct {
int8_t is_valid; /**< If 0, this freenect_frame_mode is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid. */
} freenect_frame_mode;
+/// Enumeration of smoothing modes
+typedef enum {
+ FREENECT_SMOOTHING_DISABLED = 0,
+ FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED = 1,
+} freenect_smoothing_mode;
+
/// Enumeration of LED states
/// See http://openkinect.org/wiki/Protocol_Documentation#Setting_LED for more information.
typedef enum {
@@ -615,6 +621,16 @@ FREENECTAPI freenect_frame_mode freenect_find_depth_mode(freenect_resolution res
*/
FREENECTAPI int freenect_set_depth_mode(freenect_device* dev, const freenect_frame_mode mode);
+/**
+ * Enables or disables hole filling/depth smoothing. The depth stream
+ * must be active as this appears to be reset when it is started.
+ *
+ * @param enable Whether to enable hole filling/depth smoothing
+ *
+ * @return 0 on success, < 0 on error
+ */
+FREENECTAPI int freenect_set_smoothing_mode(freenect_device* dev, const freenect_smoothing_mode mode);
+
#ifdef __cplusplus
}
#endif
View
13 src/cameras.c
@@ -1338,6 +1338,19 @@ int freenect_set_depth_mode(freenect_device* dev, const freenect_frame_mode mode
dev->depth_resolution = res;
return 0;
}
+
+int freenect_set_smoothing_mode(freenect_device* dev, const freenect_smoothing_mode mode)
+{
+ switch(mode) {
+ case FREENECT_SMOOTHING_DISABLED:
+ return write_register(dev, 0x16, 0x00);
+ break;
+ case FREENECT_SMOOTHING_HOLE_FILLING_DEPTH_SMOOTHING_ENABLED:
+ return write_register(dev, 0x16, 0x01);
+ break;
+ }
+}
+
int freenect_set_depth_buffer(freenect_device *dev, void *buf)
{
return stream_setbuf(dev->parent, &dev->depth, buf);

0 comments on commit b92239e

Please sign in to comment.