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
16 changes: 16 additions & 0 deletions examples/protonect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ 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(test_opengl_dump
src/test_opengl_dump.cpp
)

TARGET_LINK_LIBRARIES(test_opengl_dump
freenect2
)

ADD_EXECUTABLE(Protonect
Protonect.cpp
)
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
130 changes: 130 additions & 0 deletions examples/protonect/src/test_opengl_dump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2014 individual OpenKinect contributors. See the CONTRIB file
* for details.
*
* This code is licensed to you under the terms of the Apache License, version
* 2.0, or, at your option, the terms of the GNU General Public License,
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
* or the following URLs:
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/gpl-2.0.txt
*
* If you redistribute this file in source form, modified or unmodified, you
* may:
* 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
* In all cases you must keep the copyright notice intact and include a copy
* of the CONTRIB file.
*
* Binary distributions must follow the binary distribution requirements of
* either License.
*/

#include <iostream>
#include <fstream>

#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/depth_packet_processor.h>
#include <libfreenect2/packet_pipeline.h>
#include <libfreenect2/protocol/response.h>
#include <libfreenect2/threading.h>

static bool data_dumped = false;

class LIBFREENECT2_API DumpPacketProcessor : public libfreenect2::DepthPacketProcessor
{
public:
DumpPacketProcessor() {}

virtual void loadP0TablesFromCommandResponse(unsigned char* buffer, size_t buffer_length)
{
libfreenect2::protocol::P0TablesResponse* p0table = (libfreenect2::protocol::P0TablesResponse*)buffer;

if(buffer_length < sizeof(libfreenect2::protocol::P0TablesResponse))
{
std::cerr << "[CpuDepthPacketProcessor::loadP0TablesFromCommandResponse] P0Table response too short!" << std::endl;
return;
}

std::cerr << "[DumpPacketProcessor::loadP0TablesFromCommandResponse] Exporting p0 tables" << std::endl;
std::ofstream p00out("p00.bin", std::ios::out | std::ios::binary);
p00out.write(reinterpret_cast<char*>(p0table->p0table0), 512*424*sizeof(uint16_t));
p00out.close();

std::ofstream p01out("p01.bin", std::ios::out | std::ios::binary);
p01out.write(reinterpret_cast<char*>(p0table->p0table1), 512*424*sizeof(uint16_t));
p01out.close();

std::ofstream p02out("p02.bin", std::ios::out | std::ios::binary);
p02out.write(reinterpret_cast<char*>(p0table->p0table2), 512*424*sizeof(uint16_t));
p02out.close();
}

virtual void process(const libfreenect2::DepthPacket &packet)
{
if(!::data_dumped && (packet.sequence > 16))
{
std::cerr << "[DumpPacketProcessor::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();
::data_dumped = true;
}
}
};

class LIBFREENECT2_API DumpPacketPipeline : public libfreenect2::BasePacketPipeline
{
protected:
virtual libfreenect2::DepthPacketProcessor *createDepthPacketProcessor()
{
DumpPacketProcessor *depth_processor = new DumpPacketProcessor();
return depth_processor;
}

public:
DumpPacketPipeline()
{
initialize();
}
};

int main(int argc, char **argv)
{
std::string program_path(argv[0]);
size_t executable_name_idx = program_path.rfind("test_opengl");
std::string binpath = "./";

if(executable_name_idx != std::string::npos)
{
binpath = program_path.substr(0, executable_name_idx);
}

libfreenect2::Freenect2 freenect2;
libfreenect2::Freenect2Device *dev;
dev = freenect2.openDefaultDevice(new DumpPacketPipeline());

if(dev == 0)
{
std::cout << "no device connected or failure opening the default one!" << std::endl;
return -1;
}

dev->start();

while(!data_dumped)
{
std::cerr << ".";
libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100));
}
std::cerr << std::endl;

dev->stop();
dev->close();

return 0;
}