From 6bf7b8e2893d7a5e731966bc6037174209ee244c Mon Sep 17 00:00:00 2001 From: Giacomo Dabisias Date: Thu, 22 Oct 2015 10:42:03 +0200 Subject: [PATCH 1/3] makes the map for storing the color offset for each depth pixel a function parameter in order to make the user decide the allocation policy --- include/libfreenect2/registration.h | 2 +- src/registration.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/libfreenect2/registration.h b/include/libfreenect2/registration.h index 453ba8903..c36e7abeb 100644 --- a/include/libfreenect2/registration.h +++ b/include/libfreenect2/registration.h @@ -47,7 +47,7 @@ class LIBFREENECT2_API Registration void apply(int dx, int dy, float dz, float& cx, float &cy) const; // undistort/register a whole image - void apply(const Frame* rgb, const Frame* depth, Frame* undistorted, Frame* registered, const bool enable_filter = true, Frame* bigdepth = 0) const; + void apply(const Frame* rgb, const Frame* depth, Frame* undistorted, Frame* registered, const bool enable_filter = true, Frame* bigdepth = 0, int* color_depth_map = 0) const; // compute point XYZ RGB from undistored and registered frames void getPointXYZRGB (const Frame* undistorted, const Frame* registered, int r, int c, float& x, float& y, float& z, float& rgb) const; diff --git a/src/registration.cpp b/src/registration.cpp index 7e4175456..4700b3586 100644 --- a/src/registration.cpp +++ b/src/registration.cpp @@ -100,9 +100,10 @@ void Registration::apply( int dx, int dy, float dz, float& cx, float &cy) const * @param [out] registered Image color image for the depth data (512x424). * @param enable_filter Use a depth buffer to remove pixels which are not visible to both cameras. * @param [out] bigdepth If not \c NULL, mapping of depth onto colors (1920x1082 'float' frame). + * @param [out] bigdepth If not \c NULL, map for storing the color offset for each depth pixel. * @note The \a bigdepth frame has a blank top and bottom row. */ -void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorted, Frame *registered, const bool enable_filter, Frame *bigdepth) const +void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorted, Frame *registered, const bool enable_filter, Frame *bigdepth, int *color_depth_map) const { // Check if all frames are valid and have the correct size if (!rgb || !depth || !undistorted || !registered || @@ -136,7 +137,7 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte float *p_filter_map = NULL; // map for storing the color offset for each depth pixel - int *depth_to_c_off = new int[size_depth]; + int *depth_to_c_off = color_depth_map ? color_depth_map : new int[size_depth]; int *map_c_off = depth_to_c_off; // initializing the depth_map with values outside of the Kinect2 range From 67a88e90451d112a326c9f7fa2df01f4a899e477 Mon Sep 17 00:00:00 2001 From: Giacomo Dabisias Date: Thu, 22 Oct 2015 11:03:19 +0200 Subject: [PATCH 2/3] fixes memory deallocation --- src/registration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registration.cpp b/src/registration.cpp index 4700b3586..9ea9867e1 100644 --- a/src/registration.cpp +++ b/src/registration.cpp @@ -248,7 +248,7 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte *registered_data = c_off < 0 ? 0 : *(rgb_data + c_off); } } - delete[] depth_to_c_off; + if (!color_depth_map) delete[] depth_to_c_off; } /** From 020088e70b77eda576a7a744977722b229972465 Mon Sep 17 00:00:00 2001 From: Giacomo Dabisias Date: Thu, 22 Oct 2015 11:36:04 +0200 Subject: [PATCH 3/3] fixes wrong function parameter comment --- src/registration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registration.cpp b/src/registration.cpp index 9ea9867e1..c89cb09c3 100644 --- a/src/registration.cpp +++ b/src/registration.cpp @@ -100,7 +100,7 @@ void Registration::apply( int dx, int dy, float dz, float& cx, float &cy) const * @param [out] registered Image color image for the depth data (512x424). * @param enable_filter Use a depth buffer to remove pixels which are not visible to both cameras. * @param [out] bigdepth If not \c NULL, mapping of depth onto colors (1920x1082 'float' frame). - * @param [out] bigdepth If not \c NULL, map for storing the color offset for each depth pixel. + * @param [out] color_depth_map If not \c NULL, map (512x424) for storing the color offset for each depth pixel. * @note The \a bigdepth frame has a blank top and bottom row. */ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorted, Frame *registered, const bool enable_filter, Frame *bigdepth, int *color_depth_map) const