Skip to content

Commit d823f84

Browse files
author
Thiemo Wiedemeyer
committed
Changed jpeg processor to always output BGRX format.
Updated registration and removed handling of 3 byte color images. Updated protonect to display color image correct.
1 parent 3405757 commit d823f84

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

examples/protonect/Protonect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
142142
libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir];
143143
libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth];
144144

145-
cv::imshow("rgb", cv::Mat(rgb->height, rgb->width, CV_8UC3, rgb->data));
145+
cv::imshow("rgb", cv::Mat(rgb->height, rgb->width, CV_8UC4, rgb->data));
146146
cv::imshow("ir", cv::Mat(ir->height, ir->width, CV_32FC1, ir->data) / 20000.0f);
147147
cv::imshow("depth", cv::Mat(depth->height, depth->width, CV_32FC1, depth->data) / 4500.0f);
148148

examples/protonect/src/registration.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

examples/protonect/src/turbo_jpeg_rgb_packet_processor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class TurboJpegRgbPacketProcessorImpl
7373

7474
void newFrame()
7575
{
76-
frame = new Frame(1920, 1080, tjPixelSize[TJPF_BGR]);
76+
frame = new Frame(1920, 1080, tjPixelSize[TJPF_BGRX]);
7777
}
7878

7979
void startTiming()
@@ -115,7 +115,7 @@ void TurboJpegRgbPacketProcessor::process(const RgbPacket &packet)
115115
impl_->frame->timestamp = packet.timestamp;
116116
impl_->frame->sequence = packet.sequence;
117117

118-
int r = tjDecompress2(impl_->decompressor, packet.jpeg_buffer, packet.jpeg_buffer_length, impl_->frame->data, 1920, 1920 * tjPixelSize[TJPF_BGR], 1080, TJPF_BGR, 0);
118+
int r = tjDecompress2(impl_->decompressor, packet.jpeg_buffer, packet.jpeg_buffer_length, impl_->frame->data, 1920, 1920 * tjPixelSize[TJPF_BGRX], 1080, TJPF_BGRX, 0);
119119

120120
if(r == 0)
121121
{

0 commit comments

Comments
 (0)