Skip to content

Commit 35b94a6

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

File tree

6 files changed

+130
-15
lines changed

6 files changed

+130
-15
lines changed

include/internal/libfreenect2/depth_packet_processor.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,36 @@ 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+
const float* getXTable();
196+
const float* getZTable();
197+
198+
const short* getLookupTable();
199+
200+
protected:
201+
unsigned char* p0table_;
202+
203+
float* xtable_;
204+
float* ztable_;
205+
206+
short* lut_;
207+
};
208+
179209
} /* namespace libfreenect2 */
180210
#endif /* DEPTH_PACKET_PROCESSOR_H_ */

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: 61 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,63 @@ void DepthPacketProcessor::setFrameListener(libfreenect2::FrameListener *listene
98100
listener_ = listener;
99101
}
100102

103+
DumpDepthPacketProcessor::DumpDepthPacketProcessor()
104+
: p0table_(NULL), xtable_(NULL), ztable_(NULL), lut_(NULL) {
105+
}
106+
107+
DumpDepthPacketProcessor::~DumpDepthPacketProcessor(){
108+
delete[] p0table_;
109+
delete[] xtable_;
110+
delete[] ztable_;
111+
delete[] lut_;
112+
}
113+
114+
void DumpDepthPacketProcessor::process(const DepthPacket &packet) {
115+
Frame* depth_frame = new Frame(1, 1, packet.buffer_length);
116+
117+
depth_frame->timestamp = packet.timestamp;
118+
depth_frame->sequence = packet.sequence;
119+
depth_frame->format = Frame::Raw;
120+
std::memcpy(depth_frame->data, packet.buffer, packet.buffer_length);
121+
122+
Frame* ir_frame = new Frame(1, 1, packet.buffer_length, depth_frame->data);
123+
ir_frame->timestamp = packet.timestamp;
124+
ir_frame->sequence = packet.sequence;
125+
ir_frame->data = packet.buffer;
126+
ir_frame->format = Frame::Raw;
127+
128+
if (!listener_->onNewFrame(Frame::Ir, ir_frame)) {
129+
delete ir_frame;
130+
}
131+
ir_frame = NULL;
132+
if (!listener_->onNewFrame(Frame::Depth, depth_frame)) {
133+
delete depth_frame;
134+
}
135+
depth_frame = NULL;
136+
}
137+
138+
const unsigned char* DumpDepthPacketProcessor::getP0Tables() { return p0table_; }
139+
140+
const float* DumpDepthPacketProcessor::getXTable() { return xtable_; }
141+
const float* DumpDepthPacketProcessor::getZTable() { return ztable_; }
142+
143+
const short* DumpDepthPacketProcessor::getLookupTable() { return lut_; }
144+
145+
void DumpDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length) {
146+
p0table_ = new unsigned char[buffer_length];
147+
std::memcpy(p0table_, buffer, buffer_length);
148+
}
149+
150+
void DumpDepthPacketProcessor::loadXZTables(const float *xtable, const float *ztable) {
151+
xtable_ = new float[TABLE_SIZE];
152+
std::memcpy(xtable_, xtable, TABLE_SIZE * sizeof(float));
153+
154+
ztable_ = new float[TABLE_SIZE];
155+
std::memcpy(ztable_, ztable, TABLE_SIZE * sizeof(float));
156+
}
157+
158+
void DumpDepthPacketProcessor::loadLookupTable(const short *lut) {
159+
lut_ = new short[LUT_SIZE];
160+
std::memcpy(lut_, lut, LUT_SIZE * sizeof(short));
161+
}
101162
} /* 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: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
#include <libfreenect2/rgb_packet_processor.h>
3030
#include <libfreenect2/async_packet_processor.h>
3131

32+
#include <cstring>
3233
#include <fstream>
34+
#include <sstream>
3335
#include <string>
3436

37+
3538
namespace libfreenect2
3639
{
3740

@@ -49,22 +52,25 @@ void RgbPacketProcessor::setFrameListener(libfreenect2::FrameListener *listener)
4952
listener_ = listener;
5053
}
5154

52-
DumpRgbPacketProcessor::DumpRgbPacketProcessor()
53-
{
54-
}
55-
56-
DumpRgbPacketProcessor::~DumpRgbPacketProcessor()
57-
{
58-
}
55+
DumpRgbPacketProcessor::DumpRgbPacketProcessor() {}
56+
DumpRgbPacketProcessor::~DumpRgbPacketProcessor() {}
5957

6058
void DumpRgbPacketProcessor::process(const RgbPacket &packet)
6159
{
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();
60+
Frame *frame = new Frame(1, 1, 1920*1080*4);
61+
frame->sequence = packet.sequence;
62+
frame->timestamp = packet.timestamp;
63+
frame->exposure = packet.exposure;
64+
frame->gain = packet.gain;
65+
frame->gamma = packet.gamma;
66+
frame->format = Frame::Raw;
67+
68+
std::memcpy(frame->data, packet.jpeg_buffer, packet.jpeg_buffer_length);
69+
70+
if (!listener_->onNewFrame(Frame::Color, frame)) {
71+
delete frame;
72+
}
73+
frame = NULL;
6874
}
6975

7076
} /* namespace libfreenect2 */

0 commit comments

Comments
 (0)