Skip to content

Commit e9d8a05

Browse files
committed
Merge branch 'dfsg' into debian
* 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)
2 parents a5d0336 + 5ee99bd commit e9d8a05

28 files changed

Lines changed: 534 additions & 208 deletions

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ include (SetupDirectories)
4848

4949
set (PROJECT_VER_MAJOR 0)
5050
set (PROJECT_VER_MINOR 5)
51-
set (PROJECT_VER_PATCH 0)
51+
set (PROJECT_VER_PATCH 2)
5252
set (PROJECT_VER
5353
"${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
5454
set (PROJECT_APIVER
@@ -108,14 +108,14 @@ set(C_CXX_FLAGS_DEFAULT "${C_FLAGS_WARNING} -O2")
108108
# These defaults can be overriden by -DCMAKE_C_FLAGS=""
109109
set(CMAKE_C_FLAGS "${C_CXX_FLAGS_DEFAULT} ${CMAKE_C_FLAGS}")
110110
# C Configurations
111-
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -DDEBUG=1")
111+
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -O0 -g -DDEBUG=1")
112112
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}")
113113
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")
114114

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

OpenNI2-FreenectDriver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set_target_properties(FreenectDriver PROPERTIES
1717
add_definitions(-DPROJECT_VER="${PROJECT_VER}")
1818

1919
include_directories(extern/OpenNI-Linux-x64-2.2.0.33/Include)
20+
include_directories(${PROJECT_SOURCE_DIR}/src)
2021
include_directories(${PROJECT_SOURCE_DIR}/wrappers/cpp)
2122

2223
target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB})

OpenNI2-FreenectDriver/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ OpenNI2-FreenectDriver
33

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

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

1413
mkdir build

OpenNI2-FreenectDriver/src/DeviceDriver.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <map>
1818
#include <string>
1919
#include "Driver/OniDriverAPI.h"
20+
#include "freenect_internal.h"
2021
#include "libfreenect.hpp"
2122
#include "DepthStream.hpp"
2223
#include "ColorStream.hpp"
@@ -254,6 +255,18 @@ namespace FreenectDriver
254255
devices[info] = NULL;
255256
deviceConnected(&info);
256257
deviceStateChanged(&info, 0);
258+
259+
freenect_device* dev;
260+
if (freenect_open_device(m_ctx, &dev, i) == 0)
261+
{
262+
info.usbVendorId = dev->usb_cam.VID;
263+
info.usbProductId = dev->usb_cam.PID;
264+
freenect_close_device(dev);
265+
}
266+
else
267+
{
268+
WriteMessage("Unable to open device to query VID/PID");
269+
}
257270
}
258271
return ONI_STATUS_OK;
259272
}

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Continue with [Fetch & Build](#fetch-build).
7575

7676
## Linux
7777

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

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

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

9089
# only if you are building the examples:
91-
sudo apt-get install libglut3-dev libxmu-dev libxi-dev
90+
sudo apt-get install freeglut3-dev libxmu-dev libxi-dev
9291

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

examples/CMakeLists.txt

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,58 @@
22
# Packages needed for examples
33
######################################################################################
44

5-
# todo: use these throughout
6-
file(GLOB SRC_STANDARD chunkview.c glview.c hiview.c regview.c)
7-
file(GLOB SRC_AUDIO micview.c wavrecord.c)
8-
file(GLOB SRC_SYNC glpclview.c regtest.c tiltdemo.c)
9-
set (SRC_ALL ${SRC_STANDARD} ${SRC_AUDIO} ${SRC_SYNC})
10-
11-
if (WIN32)
12-
set(THREADS_USE_PTHREADS_WIN32 true)
13-
find_package(Threads REQUIRED)
14-
include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
15-
set_source_files_properties(${SRC_ALL} PROPERTIES LANGUAGE CXX)
16-
endif()
17-
18-
add_executable(freenect-glview glview.c)
19-
add_executable(freenect-regview regview.c)
20-
add_executable(freenect-hiview hiview.c)
21-
add_executable(freenect-chunkview chunkview.c)
5+
# These examples have no external dependencies and should always build.
6+
add_executable(freenect-camtest camtest.c)
227
add_executable(freenect-wavrecord wavrecord.c)
23-
add_executable(freenect-micview micview.c)
24-
25-
if (BUILD_C_SYNC)
26-
add_executable(freenect-glpclview glpclview.c)
27-
add_executable(freenect-tiltdemo tiltdemo.c)
28-
add_executable(freenect-regtest regtest.c)
29-
30-
add_dependencies(freenect-glpclview freenect-tiltdemo freenect-regtest
31-
freenect_sync)
32-
endif()
33-
34-
# We need to include libfreenect_sync.h for glpclview
35-
include_directories (../wrappers/c_sync/)
36-
37-
# Mac just has everything already
38-
if(APPLE)
39-
set(CMAKE_EXE_LINKER_FLAGS "-framework OpenGL -framework GLUT")
40-
target_link_libraries(freenect-glview freenect)
41-
target_link_libraries(freenect-regview freenect)
42-
target_link_libraries(freenect-hiview freenect)
43-
target_link_libraries(freenect-chunkview freenect)
44-
target_link_libraries(freenect-wavrecord freenect)
45-
target_link_libraries(freenect-micview freenect)
46-
if (BUILD_C_SYNC)
47-
target_link_libraries(freenect-glpclview freenect_sync)
48-
target_link_libraries(freenect-tiltdemo freenect_sync)
49-
target_link_libraries(freenect-regtest freenect_sync)
50-
endif()
51-
# Linux, not so much
52-
else()
53-
54-
find_package(Threads REQUIRED)
55-
find_package(OpenGL REQUIRED)
56-
find_package(GLUT REQUIRED)
57-
58-
include_directories(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} ${USB_INCLUDE_DIRS})
8+
target_link_libraries(freenect-camtest freenect)
9+
target_link_libraries(freenect-wavrecord freenect)
10+
install(TARGETS freenect-camtest freenect-wavrecord
11+
DESTINATION bin)
12+
13+
# All viewers need pthreads and GLUT.
14+
set(THREADS_USE_PTHREADS_WIN32 true)
15+
find_package(Threads)
16+
find_package(OpenGL)
17+
find_package(GLUT)
18+
19+
if (Threads_FOUND AND OPENGL_FOUND AND GLUT_FOUND)
20+
include_directories(${THREADS_PTHREADS_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})
21+
22+
add_executable(freenect-glview glview.c)
23+
add_executable(freenect-regview regview.c)
24+
add_executable(freenect-hiview hiview.c)
25+
add_executable(freenect-chunkview chunkview.c)
26+
add_executable(freenect-micview micview.c)
5927

6028
target_link_libraries(freenect-glview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6129
target_link_libraries(freenect-regview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6230
target_link_libraries(freenect-hiview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6331
target_link_libraries(freenect-chunkview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
64-
target_link_libraries(freenect-wavrecord freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
6532
target_link_libraries(freenect-micview freenect ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
66-
if (BUILD_C_SYNC)
67-
target_link_libraries(freenect-glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}
68-
${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
69-
target_link_libraries(freenect-tiltdemo freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
70-
target_link_libraries(freenect-regtest freenect_sync ${CMAKE_THREAD_LIBS_INIT})
71-
endif()
72-
endif()
7333

74-
install (TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-wavrecord freenect-micview
75-
DESTINATION bin)
34+
install(TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-micview
35+
DESTINATION bin)
36+
endif ()
7637

38+
# A few examples use c_sync.
7739
if (BUILD_C_SYNC)
78-
install (TARGETS freenect-glpclview freenect-tiltdemo
79-
DESTINATION bin)
80-
endif()
40+
find_package(Threads REQUIRED)
41+
include_directories(../wrappers/c_sync/)
42+
include_directories(${THREADS_PTHREADS_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})
43+
44+
add_executable(freenect-regtest regtest.c)
45+
add_executable(freenect-tiltdemo tiltdemo.c)
46+
47+
target_link_libraries(freenect-regtest freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
48+
target_link_libraries(freenect-tiltdemo freenect_sync ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
49+
50+
install(TARGETS freenect-regtest freenect-tiltdemo
51+
DESTINATION bin)
52+
53+
if (OPENGL_FOUND AND GLUT_FOUND)
54+
add_executable(freenect-glpclview glpclview.c)
55+
target_link_libraries(freenect-glpclview freenect_sync ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB})
56+
install(TARGETS freenect-glpclview
57+
DESTINATION bin)
58+
endif ()
59+
endif ()

examples/camtest.c

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* This file is part of the OpenKinect Project. http://www.openkinect.org
3+
*
4+
* Copyright (c) 2010 individual OpenKinect contributors. See the CONTRIB file
5+
* for details.
6+
*
7+
* This code is licensed to you under the terms of the Apache License, version
8+
* 2.0, or, at your option, the terms of the GNU General Public License,
9+
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10+
* or the following URLs:
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
* http://www.gnu.org/licenses/gpl-2.0.txt
13+
*
14+
* If you redistribute this file in source form, modified or unmodified, you
15+
* may:
16+
* 1) Leave this header intact and distribute it under the same terms,
17+
* accompanying it with the APACHE20 and GPL20 files, or
18+
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19+
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20+
* In all cases you must keep the copyright notice intact and include a copy
21+
* of the CONTRIB file.
22+
*
23+
* Binary distributions must follow the binary distribution requirements of
24+
* either License.
25+
*/
26+
#include <signal.h>
27+
#include <stdbool.h>
28+
#include <stdio.h>
29+
#include <string.h>
30+
#include "libfreenect.h"
31+
32+
#ifndef SIGQUIT // win32 compat
33+
#define SIGQUIT SIGTERM
34+
#endif
35+
36+
37+
void depth_cb(freenect_device* dev, void* data, uint32_t timestamp)
38+
{
39+
printf("Received depth frame at %d\n", timestamp);
40+
}
41+
42+
void video_cb(freenect_device* dev, void* data, uint32_t timestamp)
43+
{
44+
printf("Received video frame at %d\n", timestamp);
45+
}
46+
47+
volatile bool running = true;
48+
void signalHandler(int signal)
49+
{
50+
if (signal == SIGINT
51+
|| signal == SIGTERM
52+
|| signal == SIGQUIT)
53+
{
54+
running = false;
55+
}
56+
}
57+
58+
int main(int argc, char** argv)
59+
{
60+
// Handle signals gracefully.
61+
signal(SIGINT, signalHandler);
62+
signal(SIGTERM, signalHandler);
63+
signal(SIGQUIT, signalHandler);
64+
65+
// Initialize libfreenect.
66+
freenect_context* fn_ctx;
67+
int ret = freenect_init(&fn_ctx, NULL);
68+
if (ret < 0)
69+
return ret;
70+
71+
// Show debug messages and use camera only.
72+
freenect_set_log_level(fn_ctx, FREENECT_LOG_DEBUG);
73+
freenect_select_subdevices(fn_ctx, FREENECT_DEVICE_CAMERA);
74+
75+
// Find out how many devices are connected.
76+
int num_devices = ret = freenect_num_devices(fn_ctx);
77+
if (ret < 0)
78+
return ret;
79+
if (num_devices == 0)
80+
{
81+
printf("No device found!\n");
82+
freenect_shutdown(fn_ctx);
83+
return 1;
84+
}
85+
86+
// Open the first device.
87+
freenect_device* fn_dev;
88+
ret = freenect_open_device(fn_ctx, &fn_dev, 0);
89+
if (ret < 0)
90+
{
91+
freenect_shutdown(fn_ctx);
92+
return ret;
93+
}
94+
95+
// Set depth and video modes.
96+
ret = freenect_set_depth_mode(fn_dev, freenect_find_depth_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_MM));
97+
if (ret < 0)
98+
{
99+
freenect_shutdown(fn_ctx);
100+
return ret;
101+
}
102+
ret = freenect_set_video_mode(fn_dev, freenect_find_video_mode(FREENECT_RESOLUTION_MEDIUM, FREENECT_VIDEO_RGB));
103+
if (ret < 0)
104+
{
105+
freenect_shutdown(fn_ctx);
106+
return ret;
107+
}
108+
109+
// Set frame callbacks.
110+
freenect_set_depth_callback(fn_dev, depth_cb);
111+
freenect_set_video_callback(fn_dev, video_cb);
112+
113+
// Start depth and video.
114+
ret = freenect_start_depth(fn_dev);
115+
if (ret < 0)
116+
{
117+
freenect_shutdown(fn_ctx);
118+
return ret;
119+
}
120+
ret = freenect_start_video(fn_dev);
121+
if (ret < 0)
122+
{
123+
freenect_shutdown(fn_ctx);
124+
return ret;
125+
}
126+
127+
// Run until interruption or failure.
128+
while (running && freenect_process_events(fn_ctx) >= 0)
129+
{
130+
131+
}
132+
133+
printf("Shutting down\n");
134+
135+
// Stop everything and shutdown.
136+
freenect_stop_depth(fn_dev);
137+
freenect_stop_video(fn_dev);
138+
freenect_close_device(fn_dev);
139+
freenect_shutdown(fn_ctx);
140+
141+
printf("Done!\n");
142+
143+
return 0;
144+
}

0 commit comments

Comments
 (0)