### Build and Install freenect-cppview Example Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/cpp/CMakeLists.txt Configures and builds the 'freenect-cppview' example executable if examples are enabled and dependencies like Threads, OpenGL, and GLUT are found. Links against the libfreenect library and other required components. ```cmake if (BUILD_EXAMPLES) set(THREADS_USE_PTHREADS_WIN32 true) find_package(Threads) find_package(OpenGL COMPONENTS OpenGL) find_package(GLUT) if (Threads_FOUND AND OpenGL_OpenGL_FOUND AND GLUT_FOUND) include(ChooseOpenGLTarget) include_directories(. ${THREADS_PTHREADS_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR}) add_executable(freenect-cppview cppview.cpp) target_compile_features(freenect-cppview PUBLIC cxx_std_11) target_link_libraries(freenect-cppview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) install(TARGETS freenect-cppview DESTINATION bin) if (OPENGL_GLU_FOUND) add_executable(freenect-cpp_pcview cpp_pc_view.cpp) target_compile_features(freenect-cpp_pcview PUBLIC cxx_std_11) target_link_libraries(freenect-cpp_pcview freenect "${OPENGL_TARGET}" OpenGL::GLU GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) install(TARGETS freenect-cpp_pcview DESTINATION bin) endif() endif() endif() ``` -------------------------------- ### Build C Sync Examples Source: https://github.com/openkinect/libfreenect/blob/master/examples/CMakeLists.txt Builds examples that use the C sync wrapper, such as `freenect-regtest` and `freenect-tiltdemo`. Requires the `freenect_sync` library and optionally OpenGL/GLUT for `freenect-glpclview`. These are installed to the bin directory. ```cmake # A few examples use c_sync. if (BUILD_C_SYNC) include_directories(../wrappers/c_sync/) add_executable(freenect-regtest regtest.c) add_executable(freenect-tiltdemo tiltdemo.c) target_link_libraries(freenect-regtest freenect_sync ${MATH_LIB}) target_link_libraries(freenect-tiltdemo freenect_sync ${MATH_LIB}) install(TARGETS freenect-regtest freenect-tiltdemo DESTINATION bin) if (OpenGL_OpenGL_FOUND AND GLUT_FOUND) include_directories(${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR}) add_executable(freenect-glpclview glpclview.c) include(ChooseOpenGLTarget) target_link_libraries(freenect-glpclview freenect_sync "${OPENGL_TARGET}" GLUT::GLUT ${MATH_LIB}) install(TARGETS freenect-glpclview DESTINATION bin) endif () endif () ``` -------------------------------- ### Build Basic Examples Source: https://github.com/openkinect/libfreenect/blob/master/examples/CMakeLists.txt Builds `freenect-camtest` and `freenect-wavrecord` which have no external dependencies beyond libfreenect. These are installed to the bin directory. ```cmake cmake_minimum_required(VERSION 3.10) # These examples have no external dependencies and should always build. add_executable(freenect-camtest camtest.c) add_executable(freenect-wavrecord wavrecord.c) target_link_libraries(freenect-camtest freenect) target_link_libraries(freenect-wavrecord freenect) install(TARGETS freenect-camtest freenect-wavrecord DESTINATION bin) ``` -------------------------------- ### Install Dependencies on Ubuntu/Debian/Mint Source: https://github.com/openkinect/libfreenect/blob/master/README.md Install necessary build tools and libraries for libfreenect on Ubuntu-based systems using apt-get. Include freeglut3-dev, libxmu-dev, and libxi-dev if building examples. ```bash sudo apt-get install git cmake build-essential libusb-1.0-0-dev ``` ```bash sudo apt-get install freeglut3-dev libxmu-dev libxi-dev ``` -------------------------------- ### Build Graphical Viewers Source: https://github.com/openkinect/libfreenect/blob/master/examples/CMakeLists.txt Builds graphical viewer examples like `freenect-glview`, `freenect-regview`, etc. Requires pthreads, OpenGL, and GLUT. These are installed to the bin directory. ```cmake # Most viewers need pthreads and GLUT. set(THREADS_USE_PTHREADS_WIN32 true) find_package(Threads) find_package(OpenGL COMPONENTS OpenGL) find_package(GLUT) if (Threads_FOUND AND OpenGL_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) include(ChooseOpenGLTarget) target_link_libraries(freenect-glview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) target_link_libraries(freenect-regview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) target_link_libraries(freenect-hiview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) target_link_libraries(freenect-chunkview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) target_link_libraries(freenect-micview freenect "${OPENGL_TARGET}" GLUT::GLUT ${CMAKE_THREAD_LIBS_INIT} ${MATH_LIB}) install(TARGETS freenect-glview freenect-regview freenect-hiview freenect-chunkview freenect-micview DESTINATION bin) endif () ``` -------------------------------- ### Install Header Files Source: https://github.com/openkinect/libfreenect/blob/master/src/CMakeLists.txt Installs the public libfreenect header files to the designated include directory. ```cmake install (FILES "../include/libfreenect.h" "../include/libfreenect_registration.h" "../include/libfreenect_audio.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Build libfreenect with All Wrappers and Examples Source: https://context7.com/openkinect/libfreenect/llms.txt Enable all build options including examples, Python 3 wrapper, computer vision support, and CPack DEB package generation using CMake flags. Compile the project with make. ```bash # Build with all wrappers and examples cmake .. \ -DBUILD_EXAMPLES=ON \ -DBUILD_PYTHON3=ON \ -DBUILD_CV=ON \ -DBUILD_CPACK_DEB=ON make ``` -------------------------------- ### Install Synchronous Libraries and Headers Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/c_sync/CMakeLists.txt Installs the built shared and static synchronous libraries, along with the header file, to their designated locations within the project's installation directory structure. ```cmake install (TARGETS freenect_sync DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}") install (TARGETS freenect_sync_static DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}") install (FILES "libfreenect_sync.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Install libfreenect Header Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/cpp/CMakeLists.txt Installs the main header file for the libfreenect library. Ensure the include directory is correctly set in your project. ```cmake cmake_minimum_required(VERSION 3.10) install(FILES libfreenect.hpp DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Configure and start depth and video capture Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/ruby/ffi-libfreenect/README.rdoc Sets the desired depth and video modes and starts the respective capture streams. Ensure the device is opened before calling these methods. ```ruby dev.depth_mode = Freenect.depth_mode(:medium, :depth_11bit) dev.video_mode = Freenect.video_mode(:medium, :rgb) dev.start_depth() dev.start_video() ``` -------------------------------- ### Install libfreenect and Configure Udev Rules Source: https://context7.com/openkinect/libfreenect/llms.txt Install the built libfreenect library and update the dynamic linker configuration. For Ubuntu/Debian systems, copy the udev rules to allow non-root access to the Kinect device. ```bash # Install sudo make install sudo ldconfig # Ubuntu/Debian: Install udev rules for non-root access sudo cp ../platform/linux/udev/51-kinect.rules /etc/udev/rules.d/ sudo udevadm control --reload-rules ``` -------------------------------- ### Install libfreenect on macOS with Homebrew Source: https://context7.com/openkinect/libfreenect/llms.txt Install libfreenect on macOS using the Homebrew package manager. ```bash # macOS with Homebrew brew install libfreenect ``` -------------------------------- ### Configure Audio Firmware Fetching Source: https://github.com/openkinect/libfreenect/blob/master/src/CMakeLists.txt Conditionally includes fwfetcher.py for redistributable packages or directly fetches audios.bin for local installs. Requires Python and CMake 3.12+. ```cmake IF(BUILD_REDIST_PACKAGE) # If this build is intended for a redistributable package, we can't include audios.bin, so we should include fwfetcher.py # and the package should run "python fwfetcher.py $INSTALL_PREFIX/share" as a postinst hook install (FILES "fwfetcher.py" DESTINATION "${CMAKE_INSTALL_PREFIX}/share") ELSE(BUILD_REDIST_PACKAGE) # If the install is local only, we can just run fwfetcher.py and install the audios.bin firmware to the system folder cmake_minimum_required(VERSION 3.12) find_package(Python REQUIRED COMPONENTS Interpreter) add_custom_target(firmware ALL COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py" "../audios.bin" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/fwfetcher.py") install (FILES "${CMAKE_CURRENT_BINARY_DIR}/../audios.bin" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libfreenect") ENDIF() ``` -------------------------------- ### Build and Install OpenCV Demo Application Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/opencv/CMakeLists.txt This CMake code defines an executable for a libfreenect OpenCV demo. It links against the necessary libfreenect libraries and OpenCV, then installs the executable to the bin directory. ```cmake add_executable(freenect-cvdemo cvdemo.cpp) target_link_libraries(freenect-cvdemo freenect freenect_sync freenect_cv ${OpenCV_LIBS}) install (TARGETS freenect-cvdemo DESTINATION bin) ``` -------------------------------- ### Install libfreenect via Homebrew Source: https://github.com/openkinect/libfreenect/blob/master/README.md Install libfreenect using the Homebrew package manager on macOS. For the latest development version, use the `--HEAD` flag. ```bash brew install libfreenect ``` ```bash brew install --HEAD libfreenect ``` -------------------------------- ### Start Depth Camera Streaming with Callback Source: https://context7.com/openkinect/libfreenect/llms.txt Configures the depth camera to stream data in millimeters and sets a callback function to process each new depth frame. Ensure the correct depth mode and callback are set before starting the stream. ```c #include "libfreenect.h" #include #include // Callback invoked when a new depth frame is available void depth_callback(freenect_device *dev, void *depth, uint32_t timestamp) { uint16_t *depth_data = (uint16_t*)depth; // Example: Get depth at center pixel (320, 240) int center_idx = 240 * 640 + 320; uint16_t center_depth = depth_data[center_idx]; // For FREENECT_DEPTH_MM format, value is in millimeters // FREENECT_DEPTH_MM_NO_VALUE (0) indicates no valid depth if (center_depth != FREENECT_DEPTH_MM_NO_VALUE) { printf("Center depth: %d mm\n", center_depth); } } int main() { freenect_context *ctx; freenect_device *dev; freenect_init(&ctx, NULL); freenect_select_subdevices(ctx, FREENECT_DEVICE_CAMERA); freenect_open_device(ctx, &dev, 0); // Set depth mode: millimeters at 640x480 freenect_frame_mode mode = freenect_find_depth_mode( FREENECT_RESOLUTION_MEDIUM, // 640x480 FREENECT_DEPTH_MM // Depth in millimeters ); // Alternative formats: // FREENECT_DEPTH_11BIT - Raw 11-bit values // FREENECT_DEPTH_REGISTERED - Aligned to RGB camera freenect_set_depth_mode(dev, mode); freenect_set_depth_callback(dev, depth_callback); freenect_start_depth(dev); while (freenect_process_events(ctx) >= 0) { // Continue processing... } freenect_stop_depth(dev); freenect_close_device(dev); freenect_shutdown(ctx); return 0; } ``` -------------------------------- ### Minimum RGB Streaming Init Sequence Source: https://github.com/openkinect/libfreenect/wiki/Init-Analysis This set of initializations is the minimum required to get the RGB camera streaming at 640x480 resolution. Skipping any of these can result in errors or corrupted data. ```text First xfer init 23 init 25 init 26 init 27 ``` -------------------------------- ### Capture and save a single video frame Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/ruby/ffi-libfreenect/README.rdoc Sets up a video callback to capture a single frame, save it as a PPM file, and then terminate the capture. This example writes the raw video data. ```ruby $snapshot_finished = nil STDERR.puts "Taking snapshot" dev.set_video_callback do |device, video, timestamp| if not $snapshot_finished fname = "%u.ppm" % timestamp STDERR.puts "Writing #{fname}" File.open(fname, "w") do |f| f.puts("P6 %d %d 255\n" % [ dev.video_mode.width, dev.video_mode.height ] ) f.write(video.read_string_length(dev.video_mode.bytes)) end $snapshot_finished = true end end until $snapshot_finished break if (ctx.process_events < 0) end ``` -------------------------------- ### Generate pkg-config File Source: https://github.com/openkinect/libfreenect/blob/master/src/CMakeLists.txt Configures and installs a pkg-config file for the shared library on UNIX systems, facilitating easier linking against libfreenect. ```cmake IF(UNIX) # Produce a pkg-config file for linking against the shared lib configure_file ("libfreenect.pc.in" "libfreenect.pc" @ONLY) install (FILES "${CMAKE_CURRENT_BINARY_DIR}/libfreenect.pc" DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}/pkgconfig") ENDIF() ``` -------------------------------- ### C++ Main Function for Kinect Interaction Source: https://context7.com/openkinect/libfreenect/llms.txt Demonstrates initializing the Freenect context, creating a custom Kinect device, configuring video and depth formats, starting data streams, controlling the motor and LED, and entering a loop to retrieve frames. Ensure device streams are stopped before exiting. ```cpp int main() { Freenect::Freenect freenect; std::cout << "Found " << freenect.deviceCount() << " device(s)\n"; // Create device with custom class MyKinectDevice& device = freenect.createDevice(0); // Configure and start streaming device.setVideoFormat(FREENECT_VIDEO_RGB); device.setDepthFormat(FREENECT_DEPTH_MM); device.startVideo(); device.startDepth(); // Control motor and LED device.setTiltDegrees(0.0); device.setLed(LED_GREEN); // Main loop std::vector rgb; std::vector depth; while (true) { if (device.getRGB(rgb)) { std::cout << "Got RGB frame\n"; } if (device.getDepth(depth)) { std::cout << "Got depth frame, center=" << depth[240*640+320] << "mm\n"; } } device.stopVideo(); device.stopDepth(); return 0; } ``` -------------------------------- ### CMakeLists.txt for OpenNI2-FreenectDriver Source: https://github.com/openkinect/libfreenect/blob/master/OpenNI2-FreenectDriver/CMakeLists.txt This CMakeLists.txt file configures the build process for the OpenNI2-FreenectDriver. It specifies library targets, source files, include paths, and installation rules. ```cmake cmake_minimum_required(VERSION 3.8.2) file(GLOB HEADERS src/*.hpp src/*.h) file(GLOB SOURCES src/*.cpp) add_library(FreenectDriver SHARED ${HEADERS} ${SOURCES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function") set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/OpenNI2-FreenectDriver) set_target_properties(FreenectDriver PROPERTIES VERSION ${PROJECT_VER} SOVERSION ${PROJECT_APIVER} OUTPUT_NAME FreenectDriver) 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_compile_features(FreenectDriver PUBLIC cxx_std_11 cxx_constexpr) target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB}) install (TARGETS FreenectDriver DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}/OpenNI2-FreenectDriver") ``` -------------------------------- ### RGB Camera Streaming with Callback Source: https://context7.com/openkinect/libfreenect/llms.txt Captures RGB video frames using a callback function. Sets the video mode, allocates a buffer, registers the callback, and starts streaming. ```c #include "libfreenect.h" #include #include uint8_t *rgb_buffer; // Callback invoked when a new video frame is available void video_callback(freenect_device *dev, void *rgb, uint32_t timestamp) { printf("Received video frame at timestamp %u\n", timestamp); // Process the RGB data (640x480x3 bytes for RGB format) // rgb points to the frame buffer } int main() { freenect_context *ctx; freenect_device *dev; freenect_init(&ctx, NULL); freenect_select_subdevices(ctx, FREENECT_DEVICE_CAMERA); freenect_open_device(ctx, &dev, 0); // Set video mode: FREENECT_VIDEO_RGB at 640x480 freenect_frame_mode mode = freenect_find_video_mode( FREENECT_RESOLUTION_MEDIUM, // 640x480 FREENECT_VIDEO_RGB // RGB format ); freenect_set_video_mode(dev, mode); // Allocate and set video buffer rgb_buffer = (uint8_t*)malloc(mode.bytes); freenect_set_video_buffer(dev, rgb_buffer); // Register callback and start streaming freenect_set_video_callback(dev, video_callback); freenect_start_video(dev); // Process events (blocks until events occur) while (freenect_process_events(ctx) >= 0) { // Continue processing... } freenect_stop_video(dev); freenect_close_device(dev); freenect_shutdown(ctx); free(rgb_buffer); return 0; } ``` -------------------------------- ### Synchronous Wrapper API - freenect_sync_get_video / freenect_sync_get_depth Source: https://context7.com/openkinect/libfreenect/llms.txt The synchronous API offers a simplified, blocking interface for accessing camera data. It handles internal threading, making it suitable for rapid prototyping. Functions include getting video and depth frames, setting device parameters like tilt and LED, and retrieving accelerometer data. ```APIDOC ## Synchronous Wrapper API - freenect_sync_get_video / freenect_sync_get_depth ### Description The synchronous API provides a simpler interface that handles threading internally. Ideal for quick prototypes and scripts. ### Method N/A (This is a function call within the library, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include "libfreenect.h" #include "libfreenect_sync.h" #include int main() { void *rgb_buffer, *depth_buffer; uint32_t rgb_timestamp, depth_timestamp; // Get RGB frame (blocks until frame is available) if (freenect_sync_get_video(&rgb_buffer, &rgb_timestamp, 0, FREENECT_VIDEO_RGB)) { printf("Error getting video\n"); return 1; } printf("Got RGB frame at timestamp %u\n", rgb_timestamp); // Get depth frame if (freenect_sync_get_depth(&depth_buffer, &depth_timestamp, 0, FREENECT_DEPTH_MM)) { printf("Error getting depth\n"); return 1; } printf("Got depth frame at timestamp %u\n", depth_timestamp); // Get with specific resolution if (freenect_sync_get_video_with_res(&rgb_buffer, &rgb_timestamp, 0, FREENECT_RESOLUTION_HIGH, // 1280x1024 FREENECT_VIDEO_RGB)) { printf("High-res not available\n"); } // Control motor/LED using sync API freenect_sync_set_tilt_degs(10, 0); // Tilt up 10 degrees freenect_sync_set_led(LED_GREEN, 0); // Set LED green // Get accelerometer state freenect_raw_tilt_state *state; freenect_sync_get_tilt_state(&state, 0); double x, y, z; freenect_get_mks_accel(state, &x, &y, &z); printf("Accel: %.2f, %.2f, %.2f\n", x, y, z); // Stop the sync runloop when done freenect_sync_stop(); return 0; } ``` ### Response #### Success Response (200) N/A (This is a function call, not an API endpoint with HTTP responses) #### Response Example N/A ``` -------------------------------- ### Basic libfreenect Build with CMake Source: https://context7.com/openkinect/libfreenect/llms.txt Clone the libfreenect repository, create a build directory, and use CMake to configure a basic build. Then, compile using make. ```bash # Clone and build git clone https://github.com/OpenKinect/libfreenect cd libfreenect mkdir build && cd build # Basic build cmake .. make ``` -------------------------------- ### Clone and Build libfreenect Source: https://github.com/openkinect/libfreenect/blob/master/README.md Clone the libfreenect repository, create a build directory, configure with CMake, and build using make. Use `cmake -L ..` to list all project options. ```bash git clone https://github.com/OpenKinect/libfreenect cd libfreenect mkdir build cd build cmake -L .. make ``` ```bash cmake --build . make ``` -------------------------------- ### Find JPEG Library Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/actionscript/CMakeLists.txt Locates the JPEG library, which is required for certain build configurations. Ensure JPEG is installed on your system. ```cmake find_package(JPEG REQUIRED) include_directories(${JPEG_INCLUDE_DIR}) add_library (as3_jpeg server/as3_jpeg.c) target_link_libraries (as3_jpeg ${JPEG_LIBRARIES}) ``` -------------------------------- ### freenect_init - Initialize Library Context Source: https://context7.com/openkinect/libfreenect/llms.txt Initializes a freenect context required for all device operations. The context manages USB communication and must be created before opening any devices. ```APIDOC ## freenect_init - Initialize Library Context ### Description Initializes a freenect context required for all device operations. The context manages USB communication and must be created before opening any devices. ### Method (Implicitly C function call) ### Endpoint N/A (Library function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include "libfreenect.h" #include int main() { freenect_context *ctx; // Initialize the library context if (freenect_init(&ctx, NULL) < 0) { printf("Failed to initialize freenect\n"); return 1; } // Set logging level for debugging freenect_set_log_level(ctx, FREENECT_LOG_DEBUG); // Check how many Kinect devices are connected int num_devices = freenect_num_devices(ctx); printf("Found %d Kinect device(s)\n", num_devices); // Clean up when done freenect_shutdown(ctx); return 0; } ``` ### Response #### Success Response (0) - **ctx** (freenect_context *) - Pointer to the initialized context. #### Response Example (See Request Example for context initialization and usage) ``` -------------------------------- ### Build OpenNI2 Driver Source: https://github.com/openkinect/libfreenect/blob/master/OpenNI2-FreenectDriver/README.md Build the libfreenect library with the OpenNI2 driver enabled. Ensure you are in the top libfreenect directory. ```bash mkdir build cd build cmake .. -DBUILD_OPENNI2_DRIVER=ON make ``` -------------------------------- ### Add freenect_network Library Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/actionscript/CMakeLists.txt Adds the freenect_network library, which is a source file for network-related functionalities. No specific setup is required beyond its inclusion. ```cmake add_library (freenect_network server/freenect_network.c) ``` -------------------------------- ### Configure libfreenect Build on Windows with CMake GUI Source: https://context7.com/openkinect/libfreenect/llms.txt On Windows, use the CMake GUI to configure the build. Specify the include directory and library path for libusb-1.0. ```bash # Windows: Use CMake GUI with libusb paths cmake .. -DLIBUSB_1_INCLUDE_DIR="C:\path\to\libusb\include" \ -DLIBUSB_1_LIBRARY="C:\path\to\libusb\libusb.lib" ``` -------------------------------- ### Initialize libfreenect and detect devices Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/ruby/ffi-libfreenect/README.rdoc Initializes the libfreenect context and retrieves the number of connected Kinect devices. Ensure a Kinect is connected before running. ```ruby require 'freenect' ctx = Freenect.init() devs = ctx.num_devices STDERR.puts "Number of Kinects detected: #{devs}" unless devs > 0 STDERR.puts "Error: no kinect detected" exit 1 end ``` -------------------------------- ### Configure OpenCV Interface Library Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/opencv/CMakeLists.txt Use this CMake code to find the OpenCV package and build a shared library for the libfreenect OpenCV interface. Ensure OpenCV is installed and discoverable by CMake. ```cmake find_package(OpenCV REQUIRED) add_library (freenect_cv SHARED libfreenect_cv.cpp) set_target_properties (freenect_cv PROPERTIES VERSION ${PROJECT_VER} SOVERSION ${PROJECT_APIVER}) include_directories (../c_sync) target_link_libraries (freenect_cv freenect_sync ${OpenCV_LIBS}) install (TARGETS freenect_cv DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}") install (FILES "libfreenect_cv.h" DESTINATION ${PROJECT_INCLUDE_INSTALL_DIR}) ``` -------------------------------- ### Synchronous API for Frame Acquisition and Control Source: https://context7.com/openkinect/libfreenect/llms.txt Provides a simple blocking API for getting video and depth frames, controlling the motor and LED, and reading accelerometer data. Include libfreenect.h and libfreenect_sync.h. Call freenect_sync_stop() when done. ```c #include "libfreenect.h" #include "libfreenect_sync.h" #include int main() { void *rgb_buffer, *depth_buffer; uint32_t rgb_timestamp, depth_timestamp; // Get RGB frame (blocks until frame is available) if (freenect_sync_get_video(&rgb_buffer, &rgb_timestamp, 0, FREENECT_VIDEO_RGB)) { printf("Error getting video\n"); return 1; } printf("Got RGB frame at timestamp %u\n", rgb_timestamp); // Get depth frame if (freenect_sync_get_depth(&depth_buffer, &depth_timestamp, 0, FREENECT_DEPTH_MM)) { printf("Error getting depth\n"); return 1; } printf("Got depth frame at timestamp %u\n", depth_timestamp); // Get with specific resolution if (freenect_sync_get_video_with_res(&rgb_buffer, &rgb_timestamp, 0, FREENECT_RESOLUTION_HIGH, // 1280x1024 FREENECT_VIDEO_RGB)) { printf("High-res not available\n"); } // Control motor/LED using sync API freenect_sync_set_tilt_degs(10, 0); // Tilt up 10 degrees freenect_sync_set_led(LED_GREEN, 0); // Set LED green // Get accelerometer state freenect_raw_tilt_state *state; freenect_sync_get_tilt_state(&state, 0); double x, y, z; freenect_get_mks_accel(state, &x, &y, &z); printf("Accel: %.2f, %.2f, %.2f\n", x, y, z); // Stop the sync runloop when done freenect_sync_stop(); return 0; } ``` -------------------------------- ### Build libfreenect with Python 3 Wrapper Source: https://github.com/openkinect/libfreenect/blob/master/README.md Enable the Python 3 wrapper during the CMake configuration step by setting `-DBUILD_PYTHON3=ON`. ```bash cmake .. -DBUILD_PYTHON3=ON make ``` -------------------------------- ### freenect_camera_to_world - Convert Pixel to 3D Coordinates Source: https://context7.com/openkinect/libfreenect/llms.txt This function converts 2D camera coordinates (x, y) along with a depth value into real-world 3D coordinates (world_x, world_y). It requires a valid freenect_device context. The example demonstrates its usage with sample pixel and depth values. ```APIDOC ## freenect_camera_to_world - Convert Pixel to 3D Coordinates ### Description Converts 2D camera coordinates plus depth value to real-world 3D coordinates. ### Method N/A (This is a function call within the library, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```c #include "libfreenect.h" #include "libfreenect_registration.h" #include int main() { freenect_context *ctx; freenect_device *dev; freenect_init(&ctx, NULL); freenect_select_subdevices(ctx, FREENECT_DEVICE_CAMERA); freenect_open_device(ctx, &dev, 0); // Camera pixel coordinates and depth int camera_x = 320; // Pixel X (0-639) int camera_y = 240; // Pixel Y (0-479) int depth_mm = 1500; // Depth in millimeters // Convert to world coordinates double world_x, world_y; freenect_camera_to_world(dev, camera_x, camera_y, depth_mm, &world_x, &world_y); printf("Camera (%d, %d) at %dmm -> World (%.2f, %.2f, %d) mm\n", camera_x, camera_y, depth_mm, world_x, world_y, depth_mm); // For depth-to-RGB registration, use FREENECT_DEPTH_REGISTERED mode freenect_frame_mode mode = freenect_find_depth_mode( FREENECT_RESOLUTION_MEDIUM, FREENECT_DEPTH_REGISTERED // Aligned to RGB camera ); freenect_set_depth_mode(dev, mode); freenect_close_device(dev); freenect_shutdown(ctx); return 0; } ``` ### Response #### Success Response (200) N/A (This is a function call, not an API endpoint with HTTP responses) #### Response Example N/A ``` -------------------------------- ### Open and control a Kinect device Source: https://github.com/openkinect/libfreenect/blob/master/wrappers/ruby/ffi-libfreenect/README.rdoc Opens a specific Kinect device and demonstrates control over its LED and tilt mechanisms. Requires a detected device to be available. ```ruby STDERR.puts "Selecting device 0" dev = ctx.open_device(0) dev.set_led(:red) # play with the led dev.set_tilt_degrees(30) # tilt up to max sleep 1 dev.set_tilt_degrees(-30) # tilt down to max sleep 1 dev.set_tilt_degrees(0.0) # tilt back to center sleep 1 dev.set_led(:green) # play with the led ``` -------------------------------- ### Minimal Kinect Init Sequence Source: https://github.com/openkinect/libfreenect/wiki/Init-Analysis This sequence is required for initializing the depth and RGB cameras. The inits for each camera must follow a specific order, though they can be interleaved. ```text 03,126f,12000300,0000 03,1278,06000200,0000 # RGB camera 03,127f,0c000000,0000 03,1281,0d000100,0000 03,1282,0e001e00,0000 03,1283,05000100,0000 ``` -------------------------------- ### Configure libusb Paths for Windows Build Source: https://github.com/openkinect/libfreenect/blob/master/README.md When building on Windows, provide the include and library paths for libusb to CMake if it cannot be found automatically. ```bash cmake .. -DLIBUSB_1_INCLUDE_DIR="C:\path\to\libusb\include" -DLIBUSB_1_LIBRARY="C:\path\to\libusb\libusb.lib" ``` -------------------------------- ### Minimum Depth Camera Streaming Init Sequence Source: https://github.com/openkinect/libfreenect/wiki/Init-Analysis The depth camera requires only two specific initialization commands (7 and 16) to stream data. Omitting or reordering these will prevent data streaming or cause errors. ```text inits 7 and 16 ``` -------------------------------- ### Motor Initialization Command Source: https://github.com/openkinect/libfreenect/wiki/Protocol-Documentation Send this command to initialize motor control. The expected response is 0x22. ```text Send: 0xC0, 0x10, 0x0000, 0x0000, 0x0001 Response: 0x22 ``` -------------------------------- ### Initialize libfreenect Context Source: https://context7.com/openkinect/libfreenect/llms.txt Initializes the freenect context, which is necessary for all device operations. Sets the logging level and checks for connected devices. ```c #include "libfreenect.h" #include int main() { freenect_context *ctx; // Initialize the library context if (freenect_init(&ctx, NULL) < 0) { printf("Failed to initialize freenect\n"); return 1; } // Set logging level for debugging freenect_set_log_level(ctx, FREENECT_LOG_DEBUG); // Check how many Kinect devices are connected int num_devices = freenect_num_devices(ctx); printf("Found %d Kinect device(s)\n", num_devices); // Clean up when done freenect_shutdown(ctx); return 0; } ``` -------------------------------- ### Build Distribution Packages with CPack Source: https://github.com/openkinect/libfreenect/blob/master/README.md Generate distribution packages (.deb, .rpm, .tgz) by enabling the respective CPack options in CMake and then running `cpack`. ```bash cmake .. -DBUILD_CPACK_DEB=ON -DBUILD_CPACK_RPM=ON -DBUILD_CPACK_TGZ=ON cpack ``` -------------------------------- ### Build Static Library Source: https://github.com/openkinect/libfreenect/blob/master/src/CMakeLists.txt Compiles a static version of the libfreenect library. Sets the output name to 'freenect' and ensures PIC flag for UNIX systems. ```cmake add_library (freenectstatic STATIC ${SRC}) set_target_properties (freenectstatic PROPERTIES OUTPUT_NAME freenect) IF(UNIX AND NOT APPLE) SET_TARGET_PROPERTIES (freenectstatic PROPERTIES COMPILE_FLAGS "-fPIC") ENDIF() install (TARGETS freenectstatic DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}") target_link_libraries (freenectstatic ${LIBUSB_1_LIBRARIES}) ```