Skip to content

Commit

Permalink
Expose depth smoothing mode register through API.
Browse files Browse the repository at this point in the history
Signed-off-by: Rene Wagner <rwagner@informatik.uni-bremen.de>
  • Loading branch information
renewagner committed Mar 26, 2012
1 parent 06e48e5 commit b92239e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
15 changes: 14 additions & 1 deletion examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions include/libfreenect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/cameras.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b92239e

Please sign in to comment.