Skip to content

Commit bc8c8d5

Browse files
committed
Add a dump depth processor. Reactivate the RGB dump processor.
Add a dump pipeline.
1 parent 09d4df1 commit bc8c8d5

File tree

7 files changed

+135
-8
lines changed

7 files changed

+135
-8
lines changed

include/internal/libfreenect2/depth_packet_processor.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,40 @@ class OpenCLDepthPacketProcessor : public DepthPacketProcessor
175175
private:
176176
OpenCLDepthPacketProcessorImpl *impl_;
177177
};
178+
178179
#endif // LIBFREENECT2_WITH_OPENCL_SUPPORT
180+
181+
class DumpDepthPacketProcessor : public DepthPacketProcessor
182+
{
183+
public:
184+
DumpDepthPacketProcessor();
185+
virtual ~DumpDepthPacketProcessor();
186+
187+
virtual void process(const DepthPacket &packet);
188+
189+
virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length);
190+
virtual void loadXZTables(const float *xtable, const float *ztable);
191+
virtual void loadLookupTable(const short *lut);
192+
193+
const unsigned char* getP0Tables();
194+
195+
float* getXTable();
196+
float* getZTable();
197+
198+
short* getLookupTable();
199+
200+
protected:
201+
Frame* depth_frame;
202+
Frame* ir_frame;
203+
204+
unsigned char* p0table_;
205+
size_t p0table_length_;
206+
207+
float* xtable_;
208+
float* ztable_;
209+
210+
short* lut_;
211+
};
212+
179213
} /* namespace libfreenect2 */
180214
#endif /* DEPTH_PACKET_PROCESSOR_H_ */

include/internal/libfreenect2/rgb_packet_processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class DumpRgbPacketProcessor : public RgbPacketProcessor
7575
virtual ~DumpRgbPacketProcessor();
7676
protected:
7777
virtual void process(const libfreenect2::RgbPacket &packet);
78+
Frame *frame;
7879
};
7980

8081
class TurboJpegRgbPacketProcessorImpl;

include/libfreenect2/frame_listener.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ class LIBFREENECT2_API Frame
5858
BGRX,
5959
RGBX,
6060
Gray,
61-
Float
61+
Float,
62+
// Note that if format is 'raw' then 'bytes_per_pixel' actually contains the number of bytes
63+
Raw
6264
};
6365

6466
size_t width; ///< Length of a line (in pixels).
6567
size_t height; ///< Number of lines in the frame.
66-
size_t bytes_per_pixel; ///< Number of bytes in a pixel.
68+
size_t bytes_per_pixel; ///< Number of bytes in a pixel. If frame format is 'Raw' this is the buffer size.
6769
unsigned char* data; ///< Data of the frame (aligned). @see See Frame::Type for pixel format.
6870
uint32_t timestamp; ///< Unit: roughly or exactly 0.1 millisecond
6971
uint32_t sequence; ///< Increasing frame sequence number

include/libfreenect2/packet_pipeline.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class LIBFREENECT2_API PacketPipeline
6666
PacketPipelineComponents *comp_;
6767
};
6868

69+
class LIBFREENECT2_API DumpPacketPipeline: public PacketPipeline
70+
{
71+
public:
72+
DumpPacketPipeline();
73+
virtual ~DumpPacketPipeline();
74+
};
75+
6976
/** Pipeline with CPU depth processing. */
7077
class LIBFREENECT2_API CpuPacketPipeline : public PacketPipeline
7178
{

src/depth_packet_processor.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <libfreenect2/depth_packet_processor.h>
3030
#include <libfreenect2/async_packet_processor.h>
3131

32+
#include <cstring>
33+
3234
namespace libfreenect2
3335
{
3436

@@ -98,4 +100,64 @@ void DepthPacketProcessor::setFrameListener(libfreenect2::FrameListener *listene
98100
listener_ = listener;
99101
}
100102

103+
DumpDepthPacketProcessor::DumpDepthPacketProcessor() : depth_frame(new Frame(512, 424, 4)), ir_frame(new Frame(512, 424,4)) {
104+
}
105+
106+
DumpDepthPacketProcessor::~DumpDepthPacketProcessor(){
107+
delete depth_frame;
108+
delete ir_frame;
109+
delete[] p0table_;
110+
delete[] xtable_;
111+
delete[] ztable_;
112+
delete[] lut_;
113+
}
114+
115+
void DumpDepthPacketProcessor::process(const DepthPacket &packet) {
116+
ir_frame->height = 1;
117+
ir_frame->width = 1;
118+
ir_frame->bytes_per_pixel = packet.buffer_length;
119+
ir_frame->timestamp = packet.timestamp;
120+
ir_frame->sequence = packet.sequence;
121+
ir_frame->data = packet.buffer;
122+
123+
depth_frame->height = 1;
124+
depth_frame->width = 1;
125+
depth_frame->bytes_per_pixel = packet.buffer_length;
126+
depth_frame->timestamp = packet.timestamp;
127+
depth_frame->sequence = packet.sequence;
128+
depth_frame->data = packet.buffer;
129+
130+
if (listener_->onNewFrame(Frame::Ir, ir_frame)) {
131+
ir_frame = new Frame(512, 424,4);
132+
}
133+
if (listener_->onNewFrame(Frame::Depth, depth_frame)) {
134+
depth_frame = new Frame(512, 424, 4);
135+
}
136+
}
137+
138+
139+
const unsigned char* DumpDepthPacketProcessor::getP0Tables() { return p0table_; }
140+
141+
float* DumpDepthPacketProcessor::getXTable() { return xtable_; }
142+
float* DumpDepthPacketProcessor::getZTable() { return ztable_; }
143+
144+
short* DumpDepthPacketProcessor::getLookupTable() { return lut_; }
145+
146+
void DumpDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length) {
147+
p0table_ = new unsigned char[buffer_length];
148+
std::memcpy(p0table_, buffer, buffer_length);
149+
}
150+
151+
void DumpDepthPacketProcessor::loadXZTables(const float *xtable, const float *ztable) {
152+
xtable_ = new float[TABLE_SIZE];
153+
std::memcpy(xtable_, xtable, TABLE_SIZE * sizeof(float));
154+
155+
ztable_ = new float[TABLE_SIZE];
156+
std::memcpy(ztable_, ztable, TABLE_SIZE * sizeof(float));
157+
}
158+
159+
void DumpDepthPacketProcessor::loadLookupTable(const short *lut) {
160+
lut_ = new short[LUT_SIZE];
161+
std::memcpy(lut_, lut, LUT_SIZE * sizeof(short));
162+
}
101163
} /* namespace libfreenect2 */

src/packet_pipeline.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,13 @@ OpenCLPacketPipeline::OpenCLPacketPipeline(const int deviceId) : deviceId(device
129129
OpenCLPacketPipeline::~OpenCLPacketPipeline() { }
130130
#endif // LIBFREENECT2_WITH_OPENCL_SUPPORT
131131

132+
DumpPacketPipeline::DumpPacketPipeline()
133+
{
134+
RgbPacketProcessor *rgb = new DumpRgbPacketProcessor();
135+
DepthPacketProcessor *depth = new DumpDepthPacketProcessor();
136+
comp_->initialize(rgb, depth);
137+
}
138+
139+
DumpPacketPipeline::~DumpPacketPipeline() {}
140+
132141
} /* namespace libfreenect2 */

src/rgb_packet_processor.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#include <libfreenect2/async_packet_processor.h>
3131

3232
#include <fstream>
33+
#include <sstream>
3334
#include <string>
3435

36+
3537
namespace libfreenect2
3638
{
3739

@@ -50,21 +52,31 @@ void RgbPacketProcessor::setFrameListener(libfreenect2::FrameListener *listener)
5052
}
5153

5254
DumpRgbPacketProcessor::DumpRgbPacketProcessor()
55+
: frame(new Frame(1920, 1080, 4))
5356
{
5457
}
5558

5659
DumpRgbPacketProcessor::~DumpRgbPacketProcessor()
5760
{
61+
delete frame;
5862
}
5963

6064
void DumpRgbPacketProcessor::process(const RgbPacket &packet)
6165
{
62-
//std::stringstream name;
63-
//name << packet->sequence << "_" << packet->unknown0 << "_" << jpeg_buffer_length << ".jpeg";
64-
//
65-
//std::ofstream file(name.str().c_str());
66-
//file.write(reinterpret_cast<char *>(packet->jpeg_buffer), jpeg_buffer_length);
67-
//file.close();
66+
frame->sequence = packet.sequence;
67+
frame->timestamp = packet.timestamp;
68+
frame->width = 1;
69+
frame->height = 1;
70+
frame->bytes_per_pixel = packet.jpeg_buffer_length;
71+
frame->data = packet.jpeg_buffer;
72+
73+
frame->exposure = packet.exposure;
74+
frame->gain = packet.gain;
75+
frame->gamma = packet.gamma;
76+
77+
if (listener_->onNewFrame(Frame::Color, frame)) {
78+
frame = new Frame(1920, 1080, 4);
79+
}
6880
}
6981

7082
} /* namespace libfreenect2 */

0 commit comments

Comments
 (0)