void OpenGLDepthPacketProcessor::loadP0TablesFromFiles(const char* p0_filename, const char* p1_filename, const char* p2_filename) { ChangeCurrentOpenGLContext ctx(impl_->opengl_context_ptr); impl_->p0table[0].allocate(512, 424); if(loadBufferFromFile(p0_filename, impl_->p0table[0].data, impl_->p0table[0].size)) { impl_->p0table[0].upload(); } else { LOG_ERROR << "Loading p0table 0 from '" << p0_filename << "' failed!"; } impl_->p0table[1].allocate(512, 424); if(loadBufferFromFile(p1_filename, impl_->p0table[1].data, impl_->p0table[1].size)) { impl_->p0table[1].upload(); } else { LOG_ERROR << "Loading p0table 1 from '" << p1_filename << "' failed!"; } impl_->p0table[2].allocate(512, 424); if(loadBufferFromFile(p2_filename, impl_->p0table[2].data, impl_->p0table[2].size)) { impl_->p0table[2].upload(); } else { LOG_ERROR << "Loading p0table 2 from '" << p2_filename << "' failed!"; } }
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); } glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); GLFWwindow* window = glfwCreateWindow(1200, 600, "OpenGL", 0, 0); // Windowed libfreenect2::OpenGLContext opengl_ctx(window); libfreenect2::SyncMultiFrameListener fl(libfreenect2::Frame::Ir | libfreenect2::Frame::Depth); libfreenect2::FrameMap frames; libfreenect2::DepthPacketProcessor::Config cfg; cfg.EnableBilateralFilter = false; cfg.EnableEdgeAwareFilter = false; libfreenect2::OpenGLDepthPacketProcessor processor(opengl_ctx.glfw_ctx); processor.setConfiguration(cfg); processor.setFrameListener(&fl); 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.load11To16LutFromFile(""); ref_processor.loadXTableFromFile(""); ref_processor.loadZTableFromFile(""); libfreenect2::AsyncPacketProcessor<libfreenect2::DepthPacket> async(&processor); libfreenect2::DepthPacket p; 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); libfreenect2::Frame *ir, *depth; cv::Mat cpu_ir, cpu_depth, ogl_ir, ogl_depth; ref_processor.process(p); fl.waitForNewFrame(frames); ir = frames[libfreenect2::Frame::Ir]; depth = frames[libfreenect2::Frame::Depth]; cv::Mat(ir->height, ir->width, CV_32FC1, ir->data).copyTo(cpu_ir); cv::Mat(depth->height, depth->width, CV_32FC1, depth->data).copyTo(cpu_depth); fl.release(frames); processor.process(p); fl.waitForNewFrame(frames); ir = frames[libfreenect2::Frame::Ir]; depth = frames[libfreenect2::Frame::Depth]; cv::Mat(ir->height, ir->width, CV_32FC1, ir->data).copyTo(ogl_ir); cv::Mat(depth->height, depth->width, CV_32FC1, depth->data).copyTo(ogl_depth); fl.release(frames); cv::Mat diff_ir = cv::abs(cpu_ir - ogl_ir); cv::Mat diff_depth = cv::abs(cpu_depth - ogl_depth); cv::imshow("cpu_ir", cpu_ir / 65535.0f); cv::imshow("cpu_depth", cpu_depth / 4500.0f); cv::imshow("diff_ir", diff_ir); cv::imshow("diff_depth", diff_depth); cv::waitKey(0); double mi, ma; cv::minMaxIdx(diff_depth, &mi, &ma); std::cout << "depth difference min: " << mi << " max: " << ma << std::endl; while(!glfwWindowShouldClose(window)) { if(async.ready()) async.process(p); //processor.process(p); opengl_ctx.makeCurrent(); glfwSwapBuffers(opengl_ctx.glfw_ctx); //glfwSwapBuffers(window_background); glfwPollEvents(); } return 0; }
//LOAD //load the buffer from a file bool edk::AudioBuffer::loadBufferFromFile(const char* name){ return loadBufferFromFile((edk::char8*) name); }