Skip to content
Closed
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
8 changes: 8 additions & 0 deletions examples/protonect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ ADD_DEFINITIONS(-DRESOURCES_INC)
ADD_LIBRARY(freenect2 SHARED ${SOURCES})
TARGET_LINK_LIBRARIES(freenect2 ${LIBRARIES})

ADD_EXECUTABLE(test_opengl
src/test_opengl_depth_packet_processor.cpp
)

TARGET_LINK_LIBRARIES(test_opengl
freenect2
)

ADD_EXECUTABLE(Protonect
Protonect.cpp
)
Expand Down
20 changes: 19 additions & 1 deletion examples/protonect/Protonect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>
#include <libfreenect2/threading.h>
#include <libfreenect2/packet_pipeline.h>

bool protonect_shutdown = false;

Expand All @@ -53,9 +54,26 @@ int main(int argc, char *argv[])
binpath = program_path.substr(0, executable_name_idx);
}

bool dump_test_data = false;
for(int i = 1; i < argc; ++i)
{
std::string arg(argv[i]);
if(arg == "--dump")
{
dump_test_data = true;
}
}

libfreenect2::Freenect2 freenect2;
libfreenect2::Freenect2Device *dev = freenect2.openDefaultDevice();
libfreenect2::Freenect2Device *dev;
if(dump_test_data)
{
dev = freenect2.openDefaultDevice(new libfreenect2::CpuPacketPipeline(dump_test_data));
}
else
{
dev = freenect2.openDefaultDevice();
}

if(dev == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class CpuDepthPacketProcessorImpl;
class LIBFREENECT2_API CpuDepthPacketProcessor : public DepthPacketProcessor
{
public:
CpuDepthPacketProcessor();
CpuDepthPacketProcessor(bool dump_test_data = false);
virtual ~CpuDepthPacketProcessor();
virtual void setConfiguration(const libfreenect2::DepthPacketProcessor::Config &config);

Expand Down
3 changes: 2 additions & 1 deletion examples/protonect/include/libfreenect2/packet_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class LIBFREENECT2_API CpuPacketPipeline : public BasePacketPipeline
{
protected:
virtual DepthPacketProcessor *createDepthPacketProcessor();
bool dump_test_data_;
public:
CpuPacketPipeline();
CpuPacketPipeline(bool dump_test_data = false);
virtual ~CpuPacketPipeline();
};

Expand Down
37 changes: 34 additions & 3 deletions examples/protonect/src/cpu_depth_packet_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class CpuDepthPacketProcessorImpl
Frame *ir_frame, *depth_frame;

bool flip_ptables;
bool save_ptables;
bool save_raw_ir;

CpuDepthPacketProcessorImpl()
CpuDepthPacketProcessorImpl(bool dump_test_data)
{
newIrFrame();
newDepthFrame();
Expand All @@ -95,6 +97,8 @@ class CpuDepthPacketProcessorImpl
enable_edge_filter = true;

flip_ptables = true;
save_ptables = dump_test_data;
save_raw_ir = dump_test_data;
}

void startTiming()
Expand Down Expand Up @@ -601,8 +605,8 @@ class CpuDepthPacketProcessorImpl
}
};

CpuDepthPacketProcessor::CpuDepthPacketProcessor() :
impl_(new CpuDepthPacketProcessorImpl())
CpuDepthPacketProcessor::CpuDepthPacketProcessor(bool dump_test_data) :
impl_(new CpuDepthPacketProcessorImpl(dump_test_data))
{
}

Expand Down Expand Up @@ -632,6 +636,24 @@ void CpuDepthPacketProcessor::loadP0TablesFromCommandResponse(unsigned char* buf
return;
}

if(impl_->save_ptables)
{
cv::Mat(424, 512, CV_16UC1, p0table->p0table0).copyTo(impl_->p0_table0);
cv::Mat(424, 512, CV_16UC1, p0table->p0table1).copyTo(impl_->p0_table1);
cv::Mat(424, 512, CV_16UC1, p0table->p0table2).copyTo(impl_->p0_table2);
std::ofstream p00out("p00.bin", std::ios::out | std::ios::binary);
p00out.write(reinterpret_cast<char*>(impl_->p0_table0.data), impl_->p0_table0.total() * impl_->p0_table0.elemSize());
p00out.close();

std::ofstream p01out("p01.bin", std::ios::out | std::ios::binary);
p01out.write(reinterpret_cast<char*>(impl_->p0_table1.data), impl_->p0_table1.total() * impl_->p0_table1.elemSize());
p01out.close();

std::ofstream p02out("p02.bin", std::ios::out | std::ios::binary);
p02out.write(reinterpret_cast<char*>(impl_->p0_table2.data), impl_->p0_table2.total() * impl_->p0_table2.elemSize());
p02out.close();
}

if(impl_->flip_ptables)
{
cv::flip(cv::Mat(424, 512, CV_16UC1, p0table->p0table0), impl_->p0_table0, 0);
Expand Down Expand Up @@ -739,6 +761,15 @@ void CpuDepthPacketProcessor::process(const DepthPacket &packet)
{
if(listener_ == 0) return;

if(impl_->save_raw_ir && (packet.sequence > 100))
{
std::cerr << "[CpuDepthPacketProcessor::process] Exporting depth packet " << packet.sequence << std::endl;
std::ofstream rawIrOut("rawir.bin", std::ios::out | std::ios::binary);
rawIrOut.write(reinterpret_cast<char*>(packet.buffer), packet.buffer_length);
rawIrOut.close();
impl_->save_raw_ir = false;
}

impl_->startTiming();

cv::Mat m = cv::Mat::zeros(424, 512, CV_32FC(9)), m_filtered = cv::Mat::zeros(424, 512, CV_32FC(9)), m_max_edge_test = cv::Mat::ones(424, 512, CV_8UC1);
Expand Down
6 changes: 3 additions & 3 deletions examples/protonect/src/packet_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ DepthPacketProcessor *BasePacketPipeline::getDepthPacketProcessor() const
return depth_processor_;
}

CpuPacketPipeline::CpuPacketPipeline()
CpuPacketPipeline::CpuPacketPipeline(bool dump_test_data) : dump_test_data_( dump_test_data )
{
initialize();
}
Expand All @@ -88,11 +88,11 @@ CpuPacketPipeline::~CpuPacketPipeline() { }

DepthPacketProcessor *CpuPacketPipeline::createDepthPacketProcessor()
{
CpuDepthPacketProcessor *depth_processor = new CpuDepthPacketProcessor();
CpuDepthPacketProcessor *depth_processor = new CpuDepthPacketProcessor(dump_test_data_);
depth_processor->load11To16LutFromFile("11to16.bin");
depth_processor->loadXTableFromFile("xTable.bin");
depth_processor->loadZTableFromFile("zTable.bin");

return depth_processor;
}

Expand Down
9 changes: 6 additions & 3 deletions examples/protonect/src/test_opengl_depth_packet_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ int main(int argc, char **argv) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
Expand All @@ -74,15 +77,15 @@ int main(int argc, char **argv) {
libfreenect2::OpenGLDepthPacketProcessor processor(window, true);
processor.setConfiguration(cfg);
processor.setFrameListener(&fl);
processor.loadP0TablesFromFiles((binpath + "../p00.bin").c_str(), (binpath + "../p01.bin").c_str(), (binpath + "../p02.bin").c_str());
processor.loadP0TablesFromFiles((binpath + "p00.bin").c_str(), (binpath + "p01.bin").c_str(), (binpath + "p02.bin").c_str());
processor.load11To16LutFromFile("");
processor.loadXTableFromFile("");
processor.loadZTableFromFile("");

libfreenect2::CpuDepthPacketProcessor ref_processor;
ref_processor.setConfiguration(cfg);
ref_processor.setFrameListener(&fl);
ref_processor.loadP0TablesFromFiles((binpath + "../p00.bin").c_str(), (binpath + "../p01.bin").c_str(), (binpath + "../p02.bin").c_str());
ref_processor.loadP0TablesFromFiles((binpath + "p00.bin").c_str(), (binpath + "p01.bin").c_str(), (binpath + "p02.bin").c_str());
ref_processor.load11To16LutFromFile("");
ref_processor.loadXTableFromFile("");
ref_processor.loadZTableFromFile("");
Expand All @@ -93,7 +96,7 @@ int main(int argc, char **argv) {
p.buffer_length = 352*424*10*2;
p.buffer = new unsigned char[p.buffer_length];

loadBufferFromFile(binpath + "../rawir/rawir_4599.bin", p.buffer, p.buffer_length);
loadBufferFromFile(binpath + "rawir.bin", p.buffer, p.buffer_length);

libfreenect2::Frame *ir, *depth;
cv::Mat cpu_ir, cpu_depth, ogl_ir, ogl_depth;
Expand Down