Skip to content

Commit 05d73e0

Browse files
author
Thiemo Wiedemeyer
committed
registration code can now handle 3 byte and 4 byte color images.
1 parent d3d3477 commit 05d73e0

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

examples/protonect/src/registration.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
8888
{
8989
// Check if all frames are valid and have the correct size
9090
if (!undistorted || !rgb || !registered ||
91-
rgb->width != 1920 || rgb->height != 1080 || rgb->bytes_per_pixel != 3 ||
91+
rgb->width != 1920 || rgb->height != 1080 || (rgb->bytes_per_pixel != 3 && rgb->bytes_per_pixel != 4) ||
9292
depth->width != 512 || depth->height != 424 || depth->bytes_per_pixel != 4 ||
9393
undistorted->width != 512 || undistorted->height != 424 || undistorted->bytes_per_pixel != 4 ||
94-
registered->width != 512 || registered->height != 424 || registered->bytes_per_pixel != 3)
94+
registered->width != 512 || registered->height != 424 || (registered->bytes_per_pixel != 3 && registered->bytes_per_pixel != 5))
9595
return;
9696

9797
const float *depth_data = (float*)depth->data;
@@ -185,14 +185,12 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
185185
map_c_off = depth_to_c_off;
186186

187187
// run through all registered color pixels and set them based on filter results
188-
for(int i = 0; i < size_depth; ++i, ++registered_data, ++map_c_off, ++undistorted_data){
188+
for(int i = 0; i < size_depth; ++i, registered_data += registered->bytes_per_pixel, ++map_c_off, ++undistorted_data){
189189
const int c_off = *map_c_off;
190190

191191
// check if offset is out of image
192192
if(c_off < 0){
193-
*registered_data = 0;
194-
*++registered_data = 0;
195-
*++registered_data = 0;
193+
*(int*)registered_data = 0;
196194
continue;
197195
}
198196

@@ -201,17 +199,13 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
201199

202200
// check for allowed depth noise
203201
if((z - min_z) / z > filter_tolerance) {
204-
*registered_data = 0;
205-
*++registered_data = 0;
206-
*++registered_data = 0;
202+
*(int*)registered_data = 0;
207203
continue;
208204
}
209205

210206
// Setting RGB or registered image
211-
const unsigned char *rgb_data = rgb->data + c_off * 3;
212-
*registered_data = *rgb_data;
213-
*++registered_data = *++rgb_data;
214-
*++registered_data = *++rgb_data;
207+
const int *rgb_data = (int*)(rgb->data + c_off * rgb->bytes_per_pixel);
208+
*(int*)registered_data = *rgb_data;
215209
}
216210

217211
// delete the temporary maps

0 commit comments

Comments
 (0)