@@ -88,15 +88,16 @@ 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 && rgb-> bytes_per_pixel != 4 ) ||
91+ rgb->width != 1920 || rgb->height != 1080 || 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 ||
9494 registered->width != 512 || registered->height != 424 || registered->bytes_per_pixel != 4 )
9595 return ;
9696
9797 const float *depth_data = (float *)depth->data ;
98+ const unsigned int *rgb_data = (unsigned int *)rgb->data ;
9899 float *undistorted_data = (float *)undistorted->data ;
99- unsigned char *registered_data = registered->data ;
100+ unsigned int *registered_data = ( unsigned int *) registered->data ;
100101 const int *map_dist = distort_map;
101102 const float *map_x = depth_to_color_map_x;
102103 const int *map_yi = depth_to_color_map_yi;
@@ -193,32 +194,32 @@ void Registration::apply(const Frame *rgb, const Frame *depth, Frame *undistorte
193194
194195 if (enable_filter){
195196 // run through all registered color pixels and set them based on filter results
196- for (int i = 0 ; i < size_depth; ++i, ++map_c_off, ++undistorted_data, registered_data += registered-> bytes_per_pixel ){
197+ for (int i = 0 ; i < size_depth; ++i, ++map_c_off, ++undistorted_data, ++registered_data ){
197198 const int c_off = *map_c_off;
198199
199200 // check if offset is out of image
200201 if (c_off < 0 ){
201- *( int *) registered_data = 0 ;
202+ *registered_data = 0 ;
202203 continue ;
203204 }
204205
205206 const float min_z = p_filter_map[c_off];
206207 const float z = *undistorted_data;
207208
208- // check for allowed depth noise and make sure the alpha channel is not set because it could belong to the next pixel for 3 byte images.
209- *( unsigned int *) registered_data = (z - min_z) / z > filter_tolerance ? 0 : (*( unsigned int *)(rgb-> data + c_off * rgb-> bytes_per_pixel )) & 0x00FFFFFF ;
209+ // check for allowed depth noise
210+ *registered_data = (z - min_z) / z > filter_tolerance ? 0 : *(rgb_data + c_off) ;
210211 }
211212
212- // delete the temporary maps
213213 delete[] filter_map;
214214 }
215215 else
216216 {
217- for (int i = 0 ; i < size_depth; ++i, ++map_c_off, registered_data += registered->bytes_per_pixel ){
217+ // run through all registered color pixels and set them based on c_off
218+ for (int i = 0 ; i < size_depth; ++i, ++map_c_off, ++registered_data){
218219 const int c_off = *map_c_off;
219220
220- // check if offset is out of image and make sure the alpha channel is not set because it could belong to the next pixel for 3 byte images.
221- *( unsigned int *) registered_data = c_off < 0 ? 0 : (*( unsigned int *)(rgb-> data + c_off * rgb-> bytes_per_pixel )) & 0x00FFFFFF ;
221+ // check if offset is out of image
222+ *registered_data = c_off < 0 ? 0 : *(rgb_data + c_off) ;
222223 }
223224 }
224225 delete[] depth_to_c_off;
0 commit comments