Description
Im kinda new to coding (and github), so i apologize if this isnt the right place for this since its not really an issue. I just want to share some beginner freindly steps that worked for me. Here it is.
Below is a step‐by‐step walkthrough of the installation process based on the guide you posted. I’ll explain where you should type each command (mostly in a terminal, and in specific directories as noted) and how to set up the Python bindings for libfreenect2 on Ubuntu 20.04 (which I assume is what you meant by “Ubuntu 20.45”). You’ll be working from the command line (open a terminal using Ctrl+Alt+T) throughout these steps.
1. Prepare Your Environment
Before you start, make sure you have the necessary development tools and dependencies installed. In your terminal you can install them by running:
sudo apt-get update
sudo apt-get install build-essential cmake pkg-config libusb-1.0-0-dev libturbojpeg0-dev libglfw3-dev
These commands are run in your terminal (any directory is fine since they install system-wide packages).
2. Clone the libfreenect2 Repository
Decide on a working directory where you’d like to keep the source code (for example, your home directory). Then, in your terminal type:
cd ~
git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2
Here, you’re cloning the repository and then changing your directory into the cloned folder.
3. (Ubuntu 14.04–Specific Steps – Skip on Ubuntu 20.04)
The guide mentions running a script to download upgraded Debian packages for Ubuntu 14.04. Since you’re on Ubuntu 20.04, you can skip the step:
cd depends; ./download_debs_trusty.sh
4. Build libfreenect2
Now, you need to compile the library. Still inside the libfreenect2
directory, create a new directory called build
and change into it:
mkdir build && cd build
The “..
” in later commands refers to the parent directory (which is the root of the libfreenect2 source).
Now run CMake to configure the build. This command tells CMake to set the installation prefix (where the library will be installed) to a folder in your home directory:
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
Then compile and install:
make
make install
All these commands are run inside the build
directory of the libfreenect2 folder.
5. Set Up udev Rules for Device Access
To allow non-root access to the Kinect device, copy the udev rules file:
sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
After running this, unplug and replug your Kinect device so the new rules take effect.
This command is run from your current directory (inside build
), since the path “../platform/linux/udev/90-kinect2.rules
” is relative to the build folder.
6. Test the Installation
Now you can run the test program provided by libfreenect2:
./bin/Protonect
This command is run in the build
directory, where the binary was built.
If everything is working, you should see output from the Kinect streams.
7. Setting Up the Python Version (Python Bindings)
The core libfreenect2 library is written in C/C++, but there are community-supported Python bindings available (often referred to as “freenect2-python”). Here’s how to get started:
-
Ensure libfreenect2 is Installed:
The Python binding needs to locate libfreenect2. To help with that, add the following environment variables so thatpkg-config
can find your installation:export PKG_CONFIG_PATH=$HOME/freenect2/lib/pkgconfig export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/freenect2/lib
It’s a good idea to add these lines to your
~/.bashrc
so they load automatically when you open a new terminal. -
Install the Python Bindings:
There is an experimental Python interface available. For example, you can use a community package (often called “freenect2” or “pyfreenect2”). One common method is:pip install --user freenect2
If that package isn’t available or doesn’t work as expected, you may need to clone a repository such as pyfreenect2 and follow its build instructions.
-
Test the Python Interface:
Create a simple Python script (e.g.,test_freenect2.py
) with the following content:from freenect2 import Device, FrameType import numpy as np from PIL import Image # Open the default Kinect device device = Device() # Start the device using a context manager so it stops automatically with device.running(): # Wait for an IR frame for type_, frame in device: if type_ is FrameType.Ir: break # Convert the frame to a numpy array and process it (normalize, etc.) ir_image = frame.to_array() ir_image = np.sqrt(ir_image / ir_image.max()) # simple gamma correction # Save the image Image.fromarray((ir_image * 255).astype(np.uint8)).save('output.jpg') print("IR image saved as output.jpg")
Run this script in your terminal:
python3 test_freenect2.py
If everything is set up correctly, the script should capture an IR frame from your Kinect and save it as
output.jpg
.
Summary
- Terminal Commands: All commands (from installing packages to building the library) are typed into a terminal.
- Directories:
- Clone: Run
git clone
in your chosen working directory (e.g., your home folder). - Build: Inside the
libfreenect2
folder, create and enter abuild
directory and run CMake and make there. - udev Rules: Run the copy command from within the
build
folder so that the relative path toplatform/linux/udev/90-kinect2.rules
is correct.
- Clone: Run
- Python Bindings: After installing libfreenect2, set the environment variables (or add them to your
.bashrc
) so that your Python binding can locate the library. Then install the Python package (via pip or from source) and run a test script.
By following these steps in your terminal, you should have a working libfreenect2 setup with a Python interface on Ubuntu 20.04. If you run into any issues (like missing files or compilation errors), double-check that you’re in the correct directory and that all dependencies are properly installed.