Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ SET(LIBRARIES
${LIBFREENECT2_THREADING_LIBRARIES}
)

SET(RESOURCES
data/11to16.bin
data/xTable.bin
data/zTable.bin
)

IF(ENABLE_OPENGL)
FIND_PACKAGE(GLFW3)
FIND_PACKAGE(OpenGL)
Expand Down
Binary file removed data/11to16.bin
Binary file not shown.
Binary file removed data/xTable.bin
Binary file not shown.
Binary file removed data/zTable.bin
Binary file not shown.
43 changes: 12 additions & 31 deletions include/libfreenect2/depth_packet_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class LIBFREENECT2_API DepthPacketProcessor : public BaseDepthPacketProcessor
virtual void setConfiguration(const libfreenect2::DepthPacketProcessor::Config &config);

virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length) = 0;

static const size_t TABLE_SIZE = 512*424;
static const size_t LUT_SIZE = 2048;
virtual void loadXZTables(const float *xtable, const float *ztable) = 0;
virtual void loadLookupTable(const short *lut) = 0;

protected:
libfreenect2::DepthPacketProcessor::Config config_;
libfreenect2::FrameListener *listener_;
Expand All @@ -128,17 +134,8 @@ class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor

virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length);

void loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename);

/**
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
* just load them from a memory dump - although they probably vary per camera
*/
void loadXTableFromFile(const char* filename);

void loadZTableFromFile(const char* filename);

void load11To16LutFromFile(const char* filename);
virtual void loadXZTables(const float *xtable, const float *ztable);
virtual void loadLookupTable(const short *lut);

virtual void process(const DepthPacket &packet);
private:
Expand All @@ -159,17 +156,8 @@ class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor

virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length);

void loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename);

/**
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
* just load them from a memory dump - although they probably vary per camera
*/
void loadXTableFromFile(const char* filename);

void loadZTableFromFile(const char* filename);

void load11To16LutFromFile(const char* filename);
virtual void loadXZTables(const float *xtable, const float *ztable);
virtual void loadLookupTable(const short *lut);

virtual void process(const DepthPacket &packet);
private:
Expand All @@ -189,15 +177,8 @@ class LIBFREENECT2_API OpenCLDepthPacketProcessor : public DepthPacketProcessor

virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length);

/**
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
* just load them from a memory dump - although they probably vary per camera
*/
void loadXTableFromFile(const char* filename);

void loadZTableFromFile(const char* filename);

void load11To16LutFromFile(const char* filename);
virtual void loadXZTables(const float *xtable, const float *ztable);
virtual void loadLookupTable(const short *lut);

virtual void process(const DepthPacket &packet);
private:
Expand Down
3 changes: 2 additions & 1 deletion include/libfreenect2/libfreenect2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class LIBFREENECT2_API Freenect2Device

virtual Freenect2Device::ColorCameraParams getColorCameraParams() = 0;
virtual Freenect2Device::IrCameraParams getIrCameraParams() = 0;

virtual void setColorCameraParams(const Freenect2Device::ColorCameraParams &params) = 0;
virtual void setIrCameraParams(const Freenect2Device::IrCameraParams &params) = 0;

virtual void setColorFrameListener(libfreenect2::FrameListener* rgb_frame_listener) = 0;
virtual void setIrAndDepthFrameListener(libfreenect2::FrameListener* ir_frame_listener) = 0;
Expand Down
123 changes: 5 additions & 118 deletions src/cpu_depth_packet_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,6 @@ void flipHorizontal(const Mat<ScalarT> &in, Mat<ScalarT>& out)
namespace libfreenect2
{

/**
* Load a buffer from data of a file.
* @param filename Name of the file to load.
* @param buffer Start of the buffer to load.
* @param n Size of the buffer to load.
* @return Whether loading succeeded.
*/
bool loadBufferFromFile2(const std::string& filename, unsigned char *buffer, size_t n)
{
bool success;
std::ifstream in(filename.c_str());

in.read(reinterpret_cast<char*>(buffer), n);
success = in.gcount() == n;

in.close();

return success;
}

inline int bfi(int width, int offset, int src2, int src3)
{
int bitmask = (((1 << width)-1) << offset) & 0xffffffff;
Expand Down Expand Up @@ -897,111 +877,18 @@ void CpuDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buf
impl_->fillTrigTable(impl_->p0_table2, impl_->trig_table2);
}

/**
* Load p0 tables.
* @param p0_filename Filename of the first p0 table.
* @param p1_filename Filename of the second p0 table.
* @param p2_filename Filename of the third p0 table.
*/
void CpuDepthPacketProcessor::loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename)
{
Mat<uint16_t> p0_table0(424, 512);
if(!loadBufferFromFile2(p0_filename, p0_table0.buffer(), p0_table0.sizeInBytes()))
{
LOG_ERROR << "Loading p0table 0 from '" << p0_filename << "' failed!";
}

Mat<uint16_t> p0_table1(424, 512);
if(!loadBufferFromFile2(p1_filename, p0_table1.buffer(), p0_table1.sizeInBytes()))
{
LOG_ERROR << "Loading p0table 1 from '" << p1_filename << "' failed!";
}

Mat<uint16_t> p0_table2(424, 512);
if(!loadBufferFromFile2(p2_filename, p0_table2.buffer(), p0_table2.sizeInBytes()))
{
LOG_ERROR << "Loading p0table 2 from '" << p2_filename << "' failed!";
}

if(impl_->flip_ptables)
{
flipHorizontal(p0_table0, impl_->p0_table0);
flipHorizontal(p0_table1, impl_->p0_table1);
flipHorizontal(p0_table2, impl_->p0_table2);

impl_->fillTrigTable(impl_->p0_table0, impl_->trig_table0);
impl_->fillTrigTable(impl_->p0_table1, impl_->trig_table1);
impl_->fillTrigTable(impl_->p0_table2, impl_->trig_table2);
}
else
{
impl_->fillTrigTable(p0_table0, impl_->trig_table0);
impl_->fillTrigTable(p0_table1, impl_->trig_table1);
impl_->fillTrigTable(p0_table2, impl_->trig_table2);
}
}

/**
* Load the X table from the resources.
* @param filename Name of the file to load.
* @note Filename is not actually used!
*/
void CpuDepthPacketProcessor::loadXTableFromFile(const char* filename)
void CpuDepthPacketProcessor::loadXZTables(const float *xtable, const float *ztable)
{
impl_->x_table.create(424, 512);
const unsigned char *data;
size_t length;

if(loadResource("xTable.bin", &data, &length))
{
std::copy(data, data + length, impl_->x_table.buffer());
}
else
{
LOG_ERROR << "Loading xtable from resource 'xTable.bin' failed!";
}
}
std::copy(xtable, xtable + TABLE_SIZE, impl_->x_table.ptr(0,0));

/**
* Load the Z table from the resources.
* @param filename Name of the file to load.
* @note Filename is not actually used!
*/
void CpuDepthPacketProcessor::loadZTableFromFile(const char* filename)
{
impl_->z_table.create(424, 512);

const unsigned char *data;
size_t length;

if(loadResource("zTable.bin", &data, &length))
{
std::copy(data, data + length, impl_->z_table.buffer());
}
else
{
LOG_ERROR << "Loading ztable from resource 'zTable.bin' failed!";
}
std::copy(ztable, ztable + TABLE_SIZE, impl_->z_table.ptr(0,0));
}

/**
* Load the lookup table from 11 to 16 from the resources.
* @param filename Name of the file to load.
* @note Filename is not actually used!
*/
void CpuDepthPacketProcessor::load11To16LutFromFile(const char* filename)
void CpuDepthPacketProcessor::loadLookupTable(const short *lut)
{
const unsigned char *data;
size_t length;

if(loadResource("11to16.bin", &data, &length))
{
std::copy(data, data + length, reinterpret_cast<unsigned char*>(impl_->lut11to16));
}
else
{
LOG_ERROR << "Loading 11to16 lut from resource '11to16.bin' failed!";
}
std::copy(lut, lut + LUT_SIZE, impl_->lut11to16);
}

/**
Expand Down
Loading