Skip to content

Commit

Permalink
Merge branch 'dfsg' into debian
Browse files Browse the repository at this point in the history
* dfsg:
  Return int from freenect_get_ir_brightness() - fixes OpenKinect#433
  Add ability to control IR projector brightness - fixes OpenKinect#433
  Update CMakeLists.txt for v0.5.2
  Let CMake find OpenGL/GLUT automatically
  python: Fix version detection python: Use list comprehension so setup.py runs on python3 - fixes OpenKinect#429
  examples: Do not require all dependencies; skip building examples with missing dependencies win32: Compiles as pure C
  win32: Fix c_sync build
  win32: Fix compiler errors
  Add freenect-camtest example for headless testing - fixes OpenKinect#428
  Update README.md
  Fix compiler warning by anonymizing enum; touch up indentation
  Negotiate maximum USB packet length
  fixed environment variable for Darwin
  OpenNI2-FreenectDriver: Expose USB VID/PID to OpenNI - fixes OpenKinect#422
  Add support for near mode (K4W only)
  Adds zbuffer to the mapping of rgb to depth
  clear rgb pixels without depth data for map_rgb_to_depth
  add freenect_map_rgb_to_depth helper function (untested)
  • Loading branch information
yarikoptic committed Feb 13, 2015
2 parents a5d0336 + 5ee99bd commit e9d8a05
Show file tree
Hide file tree
Showing 28 changed files with 534 additions and 208 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include (SetupDirectories)

set (PROJECT_VER_MAJOR 0)
set (PROJECT_VER_MINOR 5)
set (PROJECT_VER_PATCH 0)
set (PROJECT_VER_PATCH 2)
set (PROJECT_VER
"${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
set (PROJECT_APIVER
Expand Down Expand Up @@ -108,14 +108,14 @@ set(C_CXX_FLAGS_DEFAULT "${C_FLAGS_WARNING} -O2")
# These defaults can be overriden by -DCMAKE_C_FLAGS=""
set(CMAKE_C_FLAGS "${C_CXX_FLAGS_DEFAULT} ${CMAKE_C_FLAGS}")
# C Configurations
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -DDEBUG=1")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -DDEBUG=1")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")

# These defaults can be overriden by -DCMAKE_CXX_FLAGS=""
set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS_DEFAULT} ${CMAKE_CXX_FLAGS}")
# C++ Configurations
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -DDEBUG=1")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -g")

Expand Down
1 change: 1 addition & 0 deletions OpenNI2-FreenectDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set_target_properties(FreenectDriver PROPERTIES
add_definitions(-DPROJECT_VER="${PROJECT_VER}")

include_directories(extern/OpenNI-Linux-x64-2.2.0.33/Include)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/wrappers/cpp)

target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB})
Expand Down
3 changes: 1 addition & 2 deletions OpenNI2-FreenectDriver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ OpenNI2-FreenectDriver

OpenNI2-FreenectDriver is a bridge to libfreenect implemented as an OpenNI2 driver.
It allows OpenNI2 to use Kinect hardware on Linux and OSX.
It was originally a [separate project](https://github.com/piedar/OpenNI2-FreenectDriver) but is now distributed with libfreenect.
OpenNI2-FreenectDriver is distributed under the [Apache 2](https://github.com/OpenKinect/libfreenect/blob/master/APACHE20) license.

Install
-------
1. Download and unpack [OpenNI](http://www.openni.org/openni-sdk/) 2.2.0.33 or higher.
1. Download and unpack [OpenNI](http://structure.io/openni) 2.2.0.33 or higher.
2. Go to the top libfreenect directory and build it with the OpenNI2 driver.

mkdir build
Expand Down
13 changes: 13 additions & 0 deletions OpenNI2-FreenectDriver/src/DeviceDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <map>
#include <string>
#include "Driver/OniDriverAPI.h"
#include "freenect_internal.h"
#include "libfreenect.hpp"
#include "DepthStream.hpp"
#include "ColorStream.hpp"
Expand Down Expand Up @@ -254,6 +255,18 @@ namespace FreenectDriver
devices[info] = NULL;
deviceConnected(&info);
deviceStateChanged(&info, 0);

freenect_device* dev;
if (freenect_open_device(m_ctx, &dev, i) == 0)
{
info.usbVendorId = dev->usb_cam.VID;
info.usbProductId = dev->usb_cam.PID;
freenect_close_device(dev);
}
else
{
WriteMessage("Unable to open device to query VID/PID");
}
}
return ONI_STATUS_OK;
}
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Continue with [Fetch & Build](#fetch-build).

## Linux

Remember to install the [udev rules](https://github.com/OpenKinect/libfreenect/tree/master/platform/linux/udev).
For a manual build, see [the wiki](http://openkinect.org/wiki/Getting_Started#Manual_Build_on_Linux).

### Ubuntu/Debian/Mint
Expand All @@ -83,12 +84,10 @@ The version packaged in Ubuntu may be very old.
To install newer packaged builds, see [the wiki](http://openkinect.org/wiki/Getting_Started#Ubuntu.2FDebian).
Continue with this section for a manual build.

sudo apt-get install git-core cmake pkg-config build-essential libusb-1.0-0-dev
sudo adduser $USER video
sudo adduser $USER plugdev # necessary?
sudo apt-get install git cmake build-essential libusb-1.0-0-dev

# only if you are building the examples:
sudo apt-get install libglut3-dev libxmu-dev libxi-dev
sudo apt-get install freeglut3-dev libxmu-dev libxi-dev

Continue with [Fetch & Build](#fetch-build).

Expand Down
111 changes: 45 additions & 66 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,58 @@
# Packages needed for examples
######################################################################################

# todo: use these throughout
file(GLOB SRC_STANDARD chunkview.c glview.c hiview.c regview.c)
file(GLOB SRC_AUDIO micview.c wavrecord.c)
file(GLOB SRC_SYNC glpclview.c regtest.c tiltdemo.c)
set (SRC_ALL ${SRC_STANDARD} ${SRC_AUDIO} ${SRC_SYNC})

if (WIN32)
set(THREADS_USE_PTHREADS_WIN32 true)
find_package(Threads REQUIRED)
include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
set_source_files_properties(${SRC_ALL} PROPERTIES LANGUAGE CXX)
endif()

add_executable(freenect-glview glview.c)
add_executable(freenect-regview regview.c)
add_executable(freenect-hiview hiview.c)
add_executable(freenect-chunkview chunkview.c)
# These examples have no external dependencies and should always build.
add_executable(freenect-camtest camtest.c)
add_executable(freenect-wavrecord wavrecord.c)
add_executable(freenect-micview micview.c)

if (BUILD_C_SYNC)
add_executable(freenect-glpclview glpclview.c)
add_executable(freenect-tiltdemo tiltdemo.c)
add_executable(freenect-regtest regtest.c)

add_dependencies(freenect-glpclview freenect-tiltdemo freenect-regtest
freenect_sync)
endif()

# We need to include libfreenect_sync.h for glpclview
include_directories (../wrappers/c_sync/)

# Mac just has everything already
if(APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-framework OpenGL -framework GLUT")
target_link_libraries(freenect-glview freenect)
target_link_libraries(freenect-regview freenect)
target_link_libraries(freenect-hiview freenect)
target_link_libraries(freenect-chunkview freenect)
target_link_libraries(freenect-wavrecord freenect)
target_link_libraries(freenect-micview freenect)
if (BUILD_C_SYNC)
target_link_libraries(freenect-glpclview freenect_sync)
target_link_libraries(freenect-tiltdemo freenect_sync)
target_link_libraries(freenect-regtest freenect_sync)
endif()
# Linux, not so much
else()

find_package(Threads REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)

include_directories(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} ${USB_INCLUDE_DIRS})
target_link_libraries(freenect-camtest freenect)
target_link_libraries(freenect-wavrecord freenect)
install(TARGETS freenect-camtest freenect-wavrecord
DESTINATION bin)

# All viewers need pthreads and GLUT.
set(THREADS_USE_PTHREADS_WIN32 true)
find_package(Threads)
find_package(OpenGL)
find_package(GLUT)

if (Threads_FOUND AND OPENGL_FOUND AND GLUT_FOUND)
include_directories(${THREADS_PTHREADS_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})

add_executable(freenect-glview glview.c)
add_executable(freenect-regview regview.c)
add_executable(freenect-hiview hiview.c)
add_executable(freenect-chunkview chunkview.c)
add_executable(freenect-micview micview.c)

target_link_libraries(freenect-glview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-regview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-hiview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-chunkview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-wavrecord freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-micview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
if (BUILD_C_SYNC)
target_link_libraries(freenect-glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-tiltdemo freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-regtest freenect_sync ${CMAKE_THREAD_LIBS_INIT})
endif()
endif()

install (TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-wavrecord freenect-micview
DESTINATION bin)
install(TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-micview
DESTINATION bin)
endif ()

# A few examples use c_sync.
if (BUILD_C_SYNC)
install (TARGETS freenect-glpclview freenect-tiltdemo
DESTINATION bin)
endif()
find_package(Threads REQUIRED)
include_directories(../wrappers/c_sync/)
include_directories(${THREADS_PTHREADS_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})

add_executable(freenect-regtest regtest.c)
add_executable(freenect-tiltdemo tiltdemo.c)

target_link_libraries(freenect-regtest freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
target_link_libraries(freenect-tiltdemo freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})

install(TARGETS freenect-regtest freenect-tiltdemo
DESTINATION bin)

if (OPENGL_FOUND AND GLUT_FOUND)
add_executable(freenect-glpclview glpclview.c)
target_link_libraries(freenect-glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
install(TARGETS freenect-glpclview
DESTINATION bin)
endif ()
endif ()
144 changes: 144 additions & 0 deletions examples/camtest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2010 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 <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "libfreenect.h"

#ifndef SIGQUIT // win32 compat
#define SIGQUIT SIGTERM
#endif


void depth_cb(freenect_device* dev, void* data, uint32_t timestamp)
{
printf("Received depth frame at %d\n", timestamp);
}

void video_cb(freenect_device* dev, void* data, uint32_t timestamp)
{
printf("Received video frame at %d\n", timestamp);
}

volatile bool running = true;
void signalHandler(int signal)
{
if (signal == SIGINT
|| signal == SIGTERM
|| signal == SIGQUIT)
{
running = false;
}
}

int main(int argc, char** argv)
{
// Handle signals gracefully.
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
signal(SIGQUIT, signalHandler);

// Initialize libfreenect.
freenect_context* fn_ctx;
int ret = freenect_init(&fn_ctx, NULL);
if (ret < 0)
return ret;

// Show debug messages and use camera only.
freenect_set_log_level(fn_ctx, FREENECT_LOG_DEBUG);
freenect_select_subdevices(fn_ctx, FREENECT_DEVICE_CAMERA);

// Find out how many devices are connected.
int num_devices = ret = freenect_num_devices(fn_ctx);
if (ret < 0)
return ret;
if (num_devices == 0)
{
printf("No device found!\n");
freenect_shutdown(fn_ctx);
return 1;
}

// Open the first device.
freenect_device* fn_dev;
ret = freenect_open_device(fn_ctx, &fn_dev, 0);
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}

// Set depth and video modes.
ret = freenect_set_depth_mode(fn_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_MM));
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}
ret = freenect_set_video_mode(fn_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}

// Set frame callbacks.
freenect_set_depth_callback(fn_dev, depth_cb);
freenect_set_video_callback(fn_dev, video_cb);

// Start depth and video.
ret = freenect_start_depth(fn_dev);
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}
ret = freenect_start_video(fn_dev);
if (ret < 0)
{
freenect_shutdown(fn_ctx);
return ret;
}

// Run until interruption or failure.
while (running && freenect_process_events(fn_ctx) >= 0)
{

}

printf("Shutting down\n");

// Stop everything and shutdown.
freenect_stop_depth(fn_dev);
freenect_stop_video(fn_dev);
freenect_close_device(fn_dev);
freenect_shutdown(fn_ctx);

printf("Done!\n");

return 0;
}
Loading

0 comments on commit e9d8a05

Please sign in to comment.