Skip to content

Commit b8aaef1

Browse files
committed
Merge pull request #379 from xlz/remove-hardcode
Generate depth tables with camera parameters
2 parents 6e446e6 + aa35cb4 commit b8aaef1

11 files changed

+209
-276
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ SET(LIBRARIES
126126
${LIBFREENECT2_THREADING_LIBRARIES}
127127
)
128128

129-
SET(RESOURCES
130-
data/11to16.bin
131-
data/xTable.bin
132-
data/zTable.bin
133-
)
134-
135129
IF(ENABLE_OPENGL)
136130
FIND_PACKAGE(GLFW3)
137131
FIND_PACKAGE(OpenGL)

data/11to16.bin

-4 KB
Binary file not shown.

data/xTable.bin

-848 KB
Binary file not shown.

data/zTable.bin

-848 KB
Binary file not shown.

include/libfreenect2/depth_packet_processor.h

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class LIBFREENECT2_API DepthPacketProcessor : public BaseDepthPacketProcessor
110110
virtual void setConfiguration(const libfreenect2::DepthPacketProcessor::Config &config);
111111

112112
virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length) = 0;
113+
114+
static const size_t TABLE_SIZE = 512*424;
115+
static const size_t LUT_SIZE = 2048;
116+
virtual void loadXZTables(const float *xtable, const float *ztable) = 0;
117+
virtual void loadLookupTable(const short *lut) = 0;
118+
113119
protected:
114120
libfreenect2::DepthPacketProcessor::Config config_;
115121
libfreenect2::FrameListener *listener_;
@@ -128,17 +134,8 @@ class LIBFREENECT2_API OpenGLDepthPacketProcessor : public DepthPacketProcessor
128134

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

131-
void loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename);
132-
133-
/**
134-
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
135-
* just load them from a memory dump - although they probably vary per camera
136-
*/
137-
void loadXTableFromFile(const char* filename);
138-
139-
void loadZTableFromFile(const char* filename);
140-
141-
void load11To16LutFromFile(const char* filename);
137+
virtual void loadXZTables(const float *xtable, const float *ztable);
138+
virtual void loadLookupTable(const short *lut);
142139

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

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

162-
void loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename);
163-
164-
/**
165-
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
166-
* just load them from a memory dump - although they probably vary per camera
167-
*/
168-
void loadXTableFromFile(const char* filename);
169-
170-
void loadZTableFromFile(const char* filename);
171-
172-
void load11To16LutFromFile(const char* filename);
159+
virtual void loadXZTables(const float *xtable, const float *ztable);
160+
virtual void loadLookupTable(const short *lut);
173161

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

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

192-
/**
193-
* GUESS: the x and z table follow some polynomial, until we know the exact polynom formula and its coefficients
194-
* just load them from a memory dump - although they probably vary per camera
195-
*/
196-
void loadXTableFromFile(const char* filename);
197-
198-
void loadZTableFromFile(const char* filename);
199-
200-
void load11To16LutFromFile(const char* filename);
180+
virtual void loadXZTables(const float *xtable, const float *ztable);
181+
virtual void loadLookupTable(const short *lut);
201182

202183
virtual void process(const DepthPacket &packet);
203184
private:

include/libfreenect2/libfreenect2.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class LIBFREENECT2_API Freenect2Device
8989

9090
virtual Freenect2Device::ColorCameraParams getColorCameraParams() = 0;
9191
virtual Freenect2Device::IrCameraParams getIrCameraParams() = 0;
92-
92+
virtual void setColorCameraParams(const Freenect2Device::ColorCameraParams &params) = 0;
93+
virtual void setIrCameraParams(const Freenect2Device::IrCameraParams &params) = 0;
9394

9495
virtual void setColorFrameListener(libfreenect2::FrameListener* rgb_frame_listener) = 0;
9596
virtual void setIrAndDepthFrameListener(libfreenect2::FrameListener* ir_frame_listener) = 0;

src/cpu_depth_packet_processor.cpp

Lines changed: 5 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,6 @@ void flipHorizontal(const Mat<ScalarT> &in, Mat<ScalarT>& out)
261261
namespace libfreenect2
262262
{
263263

264-
/**
265-
* Load a buffer from data of a file.
266-
* @param filename Name of the file to load.
267-
* @param buffer Start of the buffer to load.
268-
* @param n Size of the buffer to load.
269-
* @return Whether loading succeeded.
270-
*/
271-
bool loadBufferFromFile2(const std::string& filename, unsigned char *buffer, size_t n)
272-
{
273-
bool success;
274-
std::ifstream in(filename.c_str());
275-
276-
in.read(reinterpret_cast<char*>(buffer), n);
277-
success = in.gcount() == n;
278-
279-
in.close();
280-
281-
return success;
282-
}
283-
284264
inline int bfi(int width, int offset, int src2, int src3)
285265
{
286266
int bitmask = (((1 << width)-1) << offset) & 0xffffffff;
@@ -897,111 +877,18 @@ void CpuDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buf
897877
impl_->fillTrigTable(impl_->p0_table2, impl_->trig_table2);
898878
}
899879

900-
/**
901-
* Load p0 tables.
902-
* @param p0_filename Filename of the first p0 table.
903-
* @param p1_filename Filename of the second p0 table.
904-
* @param p2_filename Filename of the third p0 table.
905-
*/
906-
void CpuDepthPacketProcessor::loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename)
907-
{
908-
Mat<uint16_t> p0_table0(424, 512);
909-
if(!loadBufferFromFile2(p0_filename, p0_table0.buffer(), p0_table0.sizeInBytes()))
910-
{
911-
LOG_ERROR << "Loading p0table 0 from '" << p0_filename << "' failed!";
912-
}
913-
914-
Mat<uint16_t> p0_table1(424, 512);
915-
if(!loadBufferFromFile2(p1_filename, p0_table1.buffer(), p0_table1.sizeInBytes()))
916-
{
917-
LOG_ERROR << "Loading p0table 1 from '" << p1_filename << "' failed!";
918-
}
919-
920-
Mat<uint16_t> p0_table2(424, 512);
921-
if(!loadBufferFromFile2(p2_filename, p0_table2.buffer(), p0_table2.sizeInBytes()))
922-
{
923-
LOG_ERROR << "Loading p0table 2 from '" << p2_filename << "' failed!";
924-
}
925-
926-
if(impl_->flip_ptables)
927-
{
928-
flipHorizontal(p0_table0, impl_->p0_table0);
929-
flipHorizontal(p0_table1, impl_->p0_table1);
930-
flipHorizontal(p0_table2, impl_->p0_table2);
931-
932-
impl_->fillTrigTable(impl_->p0_table0, impl_->trig_table0);
933-
impl_->fillTrigTable(impl_->p0_table1, impl_->trig_table1);
934-
impl_->fillTrigTable(impl_->p0_table2, impl_->trig_table2);
935-
}
936-
else
937-
{
938-
impl_->fillTrigTable(p0_table0, impl_->trig_table0);
939-
impl_->fillTrigTable(p0_table1, impl_->trig_table1);
940-
impl_->fillTrigTable(p0_table2, impl_->trig_table2);
941-
}
942-
}
943-
944-
/**
945-
* Load the X table from the resources.
946-
* @param filename Name of the file to load.
947-
* @note Filename is not actually used!
948-
*/
949-
void CpuDepthPacketProcessor::loadXTableFromFile(const char* filename)
880+
void CpuDepthPacketProcessor::loadXZTables(const float *xtable, const float *ztable)
950881
{
951882
impl_->x_table.create(424, 512);
952-
const unsigned char *data;
953-
size_t length;
954-
955-
if(loadResource("xTable.bin", &data, &length))
956-
{
957-
std::copy(data, data + length, impl_->x_table.buffer());
958-
}
959-
else
960-
{
961-
LOG_ERROR << "Loading xtable from resource 'xTable.bin' failed!";
962-
}
963-
}
883+
std::copy(xtable, xtable + TABLE_SIZE, impl_->x_table.ptr(0,0));
964884

965-
/**
966-
* Load the Z table from the resources.
967-
* @param filename Name of the file to load.
968-
* @note Filename is not actually used!
969-
*/
970-
void CpuDepthPacketProcessor::loadZTableFromFile(const char* filename)
971-
{
972885
impl_->z_table.create(424, 512);
973-
974-
const unsigned char *data;
975-
size_t length;
976-
977-
if(loadResource("zTable.bin", &data, &length))
978-
{
979-
std::copy(data, data + length, impl_->z_table.buffer());
980-
}
981-
else
982-
{
983-
LOG_ERROR << "Loading ztable from resource 'zTable.bin' failed!";
984-
}
886+
std::copy(ztable, ztable + TABLE_SIZE, impl_->z_table.ptr(0,0));
985887
}
986888

987-
/**
988-
* Load the lookup table from 11 to 16 from the resources.
989-
* @param filename Name of the file to load.
990-
* @note Filename is not actually used!
991-
*/
992-
void CpuDepthPacketProcessor::load11To16LutFromFile(const char* filename)
889+
void CpuDepthPacketProcessor::loadLookupTable(const short *lut)
993890
{
994-
const unsigned char *data;
995-
size_t length;
996-
997-
if(loadResource("11to16.bin", &data, &length))
998-
{
999-
std::copy(data, data + length, reinterpret_cast<unsigned char*>(impl_->lut11to16));
1000-
}
1001-
else
1002-
{
1003-
LOG_ERROR << "Loading 11to16 lut from resource '11to16.bin' failed!";
1004-
}
891+
std::copy(lut, lut + LUT_SIZE, impl_->lut11to16);
1005892
}
1006893

1007894
/**

0 commit comments

Comments
 (0)