diff --git a/CMakeLists.txt b/CMakeLists.txt index d44a65f0c..7b69b3b12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1) SET(PROJECT_VER_MAJOR 0) SET(PROJECT_VER_MINOR 1) -SET(PROJECT_VER_PATCH 0) +SET(PROJECT_VER_PATCH 1) SET(PROJECT_VER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}") SET(PROJECT_APIVER "${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}") diff --git a/CONTRIB b/CONTRIB index 075caa81f..ce7d43b32 100644 --- a/CONTRIB +++ b/CONTRIB @@ -1,11 +1,31 @@ -For a list of libfreenect2 authors, please see the Git history of the project, -such as with 'git log'. This file will contain a list of authors on release -snapshots of libfreenect2. - -THIS FILE IS NOT VALID FOR NON-GIT DISTRIBUTIONS. If you wish to redistribute -libfreenect source code outside of the Git infrastructure, you MUST either use -a release version or generate a complete CONTRIB file valid for the source Git -revision tree that you use for your distribution. Redistributions of libfreenect -source code without a valid CONTRIB file and without Git metadata are not -compliant with the license. - +Albert Hofkamp +Alistair +augmenta +Christian Kerl +Dave Coleman +Dorian Galvez-Lopez +Federico Spinelli +Florian Echtler +Francisco Facioni +Gabor Papp +Giacomo Dabisias +Henning Jungkurth +James Billingham +Joshua Blake +Lars Glud +Lingzhu Xiang +Ludique +Mario Wündsch +Matthias Goldhoorn +MrTatsch +P.E. Viau +Paul Reynolds +rahulraw +Rich Wareham +Ryan Gordon +Sergey Gusarov +Steffen Fuchs +Thiemo Wiedemeyer +vinouz +yuanmingze <3054502461@sina.com> +Zou Hanya diff --git a/README.md b/README.md index fb6ee701c..2bb2a9a79 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Driver for Kinect for Windows v2 (K4W2) devices (release and developer preview). Note: libfreenect2 does not do anything for either Kinect for Windows v1 or Kinect for Xbox 360 sensors. Use libfreenect1 for those sensors. +If you are using libfreenect2 in an academic context, please cite our work using the following DOI: [![DOI](https://zenodo.org/badge/20096/OpenKinect/libfreenect2.svg)](https://zenodo.org/badge/latestdoi/20096/OpenKinect/libfreenect2) + This driver supports: * RGB image transfer * IR and depth image transfer diff --git a/depends/install_libusb_vs2013.cmd b/depends/install_libusb_vs2013.cmd index 2e3db6142..2ea44cfba 100644 --- a/depends/install_libusb_vs2013.cmd +++ b/depends/install_libusb_vs2013.cmd @@ -6,9 +6,9 @@ rmdir /s /q libusb_src libusb git clone https://github.com/libusb/libusb.git libusb_src || exit /b cd libusb_src -git remote add joshblake https://github.com/JoshBlake/libusbx.git -git fetch joshblake || exit /b -git merge joshblake/winiso +git remote add xlz https://github.com/xlz/libusb.git +git fetch xlz || exit /b +git merge xlz/winiso set CONFIG=Release msbuild msvc\libusb_dll_2013.vcxproj /p:Platform=x64 /p:Configuration=%CONFIG% /target:Rebuild diff --git a/depends/install_libusb_vs2015.cmd b/depends/install_libusb_vs2015.cmd index b0d42843e..f3c2f2c78 100644 --- a/depends/install_libusb_vs2015.cmd +++ b/depends/install_libusb_vs2015.cmd @@ -6,9 +6,9 @@ rmdir /s /q libusb_src libusb git clone https://github.com/libusb/libusb.git libusb_src || exit /b cd libusb_src -git remote add joshblake https://github.com/JoshBlake/libusbx.git -git fetch joshblake || exit /b -git merge joshblake/winiso +git remote add xlz https://github.com/xlz/libusb.git +git fetch xlz || exit /b +git merge xlz/winiso set CONFIG=Release msbuild msvc\libusb_dll_2015.vcxproj /p:Platform=x64 /p:Configuration=%CONFIG% /target:Rebuild diff --git a/examples/Protonect.cpp b/examples/Protonect.cpp index 2b2dc1ed9..3f00d83b2 100644 --- a/examples/Protonect.cpp +++ b/examples/Protonect.cpp @@ -110,8 +110,9 @@ int main(int argc, char *argv[]) /// [main] { std::string program_path(argv[0]); + std::cerr << "Version: " << LIBFREENECT2_VERSION << std::endl; std::cerr << "Environment variables: LOGFILE=" << std::endl; - std::cerr << "Usage: " << program_path << " [gl | cl | cpu] [] [-noviewer]" << std::endl; + std::cerr << "Usage: " << program_path << " [gl | cl | cpu] [] [-noviewer] [-help] [-version]" << std::endl; std::cerr << "To pause and unpause: pkill -USR1 Protonect" << std::endl; size_t executable_name_idx = program_path.rfind("Protonect"); @@ -145,15 +146,7 @@ int main(int argc, char *argv[]) libfreenect2::PacketPipeline *pipeline = 0; /// [context] -/// [discovery] - if(freenect2.enumerateDevices() == 0) - { - std::cout << "no device connected!" << std::endl; - return -1; - } - - std::string serial = freenect2.getDefaultDeviceSerialNumber(); -/// [discovery] + std::string serial = ""; bool viewer_enabled = true; @@ -161,7 +154,12 @@ int main(int argc, char *argv[]) { const std::string arg(argv[argI]); - if(arg == "cpu") + if(arg == "-help" || arg == "--help" || arg == "-h" || arg == "-v" || arg == "--version" || arg == "-version") + { + // Just let the initial lines display at the beginning of main + return 0; + } + else if(arg == "cpu") { if(!pipeline) /// [pipeline] @@ -190,7 +188,7 @@ int main(int argc, char *argv[]) { serial = arg; } - else if(arg == "-noviewer") + else if(arg == "-noviewer" || arg == "--noviewer") { viewer_enabled = false; } @@ -200,6 +198,19 @@ int main(int argc, char *argv[]) } } +/// [discovery] + if(freenect2.enumerateDevices() == 0) + { + std::cout << "no device connected!" << std::endl; + return -1; + } + + if (serial == "") + { + serial = freenect2.getDefaultDeviceSerialNumber(); + } +/// [discovery] + if(pipeline) { /// [open] @@ -257,7 +268,11 @@ int main(int argc, char *argv[]) /// [loop start] while(!protonect_shutdown) { - listener.waitForNewFrame(frames); + if (!listener.waitForNewFrame(frames, 10*1000)) // 10 sconds + { + std::cout << "timeout!" << std::endl; + return -1; + } libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color]; libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir]; libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth]; diff --git a/examples/test_opengl_depth_packet_processor.cpp b/examples/test_opengl_depth_packet_processor.cpp deleted file mode 100644 index 609fce48f..000000000 --- a/examples/test_opengl_depth_packet_processor.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * 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. - */ - -/** @file test_opengl_depth_packet_processor.cpp Test program for the OpenGL depth packet processor. */ - -#include -#include - -#include -#include - -#include -#include -#include -#include - -void loadBufferFromFile(const std::string& filename, unsigned char *buffer, size_t n) -{ - std::ifstream in(filename.c_str()); - - in.read(reinterpret_cast(buffer), n); - if(in.gcount() != n) throw std::exception(); - - in.close(); -} - -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); -#ifdef __APPLE__ - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); -#endif - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - - glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); - - GLFWwindow* window = glfwCreateWindow(1200, 600, "OpenGL", 0, 0); // Windowed - - 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(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.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 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); - - glfwMakeContextCurrent(window); - glfwSwapBuffers(window); - //glfwSwapBuffers(window_background); - glfwPollEvents(); - } - - return 0; -} diff --git a/include/libfreenect2/config.h.in b/include/libfreenect2/config.h.in index f69d6a7a2..5be1bc957 100644 --- a/include/libfreenect2/config.h.in +++ b/include/libfreenect2/config.h.in @@ -27,6 +27,9 @@ #ifndef LIBFREENECT2_CONFIG_H #define LIBFREENECT2_CONFIG_H +#define LIBFREENECT2_VERSION "@PROJECT_VER@" +#define LIBFREENECT2_API_VERSION ((@PROJECT_VER_MAJOR@ << 16) | @PROJECT_VER_MINOR@) + #ifdef _MSC_VER #define LIBFREENECT2_PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) #else diff --git a/src/libfreenect2.cpp b/src/libfreenect2.cpp index 3ee6f1601..156f40376 100644 --- a/src/libfreenect2.cpp +++ b/src/libfreenect2.cpp @@ -751,7 +751,8 @@ bool Freenect2DeviceImpl::start() command_tx_.execute(SetModeEnabledWith0x00640064Command(nextCommandSeq()), result); command_tx_.execute(SetModeDisabledCommand(nextCommandSeq()), result); - for (uint32_t status = 0, last = 0; (status & 1) == 0; last = status) + int timeout = 50; // about 5 seconds (100ms x 50) + for (uint32_t status = 0, last = 0; (status & 1) == 0 && 0 < timeout; last = status, timeout--) { command_tx_.execute(ReadStatus0x090000Command(nextCommandSeq()), result); if ((size_t)result.length < sizeof(uint32_t)) @@ -762,6 +763,9 @@ bool Freenect2DeviceImpl::start() if ((status & 1) == 0) this_thread::sleep_for(chrono::milliseconds(100)); } + if (timeout == 0) { + LOG_DEBUG << "status 0x090000: timeout"; + } command_tx_.execute(InitStreamsCommand(nextCommandSeq()), result); @@ -858,7 +862,19 @@ bool Freenect2DeviceImpl::close() CommandTransaction::Result result; command_tx_.execute(SetModeEnabledWith0x00640064Command(nextCommandSeq()), result); command_tx_.execute(SetModeDisabledCommand(nextCommandSeq()), result); + /* This command actually reboots the device and makes it disappear for 3 seconds. + * Protonect can restart instantly without it. + */ +#ifdef __APPLE__ + /* Kinect will disappear on Mac OS X regardless during close(). + * Painstaking effort could not determine the root cause. + * See https://github.com/OpenKinect/libfreenect2/issues/539 + * + * Shut down Kinect explicitly on Mac and wait a fixed time. + */ command_tx_.execute(ShutdownCommand(nextCommandSeq()), result); + libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(4*1000)); +#endif if(pipeline_->getRgbPacketProcessor() != 0) pipeline_->getRgbPacketProcessor()->setFrameListener(0); diff --git a/src/resource.cpp b/src/resource.cpp index bf8ca0b40..3f01dcd7d 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -45,7 +45,7 @@ struct ResourceDescriptor #ifdef RESOURCES_INC #include "resources.inc.h" #else -static ResourceDescriptor resource_descriptors[] = {}; +static ResourceDescriptor resource_descriptors[] = {{NULL, NULL, 0}}; static int resource_descriptors_length = 0; #endif diff --git a/tools/generate_resources.cpp b/tools/generate_resources.cpp index b9a358d3c..30bd30518 100644 --- a/tools/generate_resources.cpp +++ b/tools/generate_resources.cpp @@ -90,6 +90,7 @@ int main(int argc, char **argv) cout << " { \"" << path << "\", resource" << (i - 2) << ", " << "sizeof(resource" << (i - 2) << ") }," << endl; } + cout << " {NULL, NULL, 0}," << endl; cout << "};" << endl; cout << "static int resource_descriptors_length = " << (argc - 2) << ";" << endl; diff --git a/tools/mkcontrib.py b/tools/mkcontrib.py new file mode 100644 index 000000000..430404a84 --- /dev/null +++ b/tools/mkcontrib.py @@ -0,0 +1,26 @@ +# 1. Visual inspection: python mkcontrib.py +# 2. If OK, python mkcontrib.py | grep -v ^# > CONTRIB + +from subprocess import Popen, PIPE +from collections import defaultdict, Counter + +p = Popen(["git","log","--no-merges","--format=%aN <%aE>"], stdout=PIPE).stdout +common_email = defaultdict(Counter) +common_name = defaultdict(Counter) +for line in p: + author, email = line.rstrip().split('<') + common_email[author].update([email]) + common_name[email].update([author]) + +for email in common_name: + names = common_name[email] + names = sorted(names, key=lambda x: (names[x], len(x)), reverse=True) + for name in names[1:]: + common_email[names[0]] += common_email[name] + del common_email[name] + print '# Less common or shorter name', name, 'is replaced by', names[0] + +for name in sorted(common_email): + for k in common_email[name].most_common()[1:]: + print '# Less common email <' + k[0] + ' is removed.' + print name + '<' + common_email[name].most_common(1)[0][0]