sudo apt update
sudo apt upgrade
sudo apt install git
Il suffit de cloner le repository. Tous les fichiers seront alors copiés dans un sous-répertoire libfreenect2 du répertoire courant : pensez à créer l'arborescence qui vous convient pour accueillir cette bibliothèque (Dans mon cas, le répertoire Kinect à la racine du profil).
mkdir ~/Kinect && cd ~/Kinect
git clone https://github.com/OpenKinect/libfreenect2.git
sudo apt install build-essential cmake pkg-config libusb-1.0-0-dev libturbojpeg libjpeg-turbo8-dev libglfw3-dev
Le package peut dès lors être fabriqué
cd libfreenect2
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/Kinect/libfreenect2
make
make install
cd bin
sudo ./Protonect
Si tout s'est correctement passé (Kinect correctement branché et succès de la compilation), une fenêtre de ce type devrait apparaître :
sudo apt install libsdl2-net-dev
Modifier le fichier libfreenect2/CMakeLists.txt
#include "SDL_net.h"
// Initialisation d'une connexion vers localhost:3000
IPaddress ip;
TCPsocket sd;
if (SDLNet_Init() < 0)
{
fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
if (SDLNet_ResolveHost(&ip, "127.0.0.1", 3000) < 0)
{
fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
if (!(sd = SDLNet_TCP_Open(&ip)))
{
fprintf(stderr, "SDLNet_TCP_Open: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
// Intégré dans la boucle principale
int len = depth->width * depth->height * depth->bytes_per_pixel;
if (SDLNet_TCP_Send(sd, (void *) depth->data, len) < len)
{
fprintf(stderr, "SDLNet_TCP_Send: %s\n", SDLNet_GetError());
exit(EXIT_FAILURE);
}
D'autres transformations sont possibles, comme la suppression du viewer et du paramétrage pour gérer l'activation des capteurs (RGB, profondeur)
Ce qui donne ce fichier Protonect.cpp
cd ~/Kinect/libfreenect2/
rm -rf build/*
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/Kinect/libfreenect2
make
make install
sudo apt install default-jdk
Dans mon contexte, ce package correspond à java8-openjdk.
N'importe quel environnement de développement peut faire l'affaire. Ubuntu propose un package Eclipse qui tire les dépendances Java
sudo apt install eclipse-platform
Le package est par contre assez ancien (3.8). L'installation avec l'installer Eclipse permet de profiter des dernières versions de l'IDE.
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class TestServer extends Thread {
public final static int SERVER_PORT = 3000;
public void run() {
ServerSocket ss = null;
Socket s;
try {
ss = new ServerSocket(SERVER_PORT);
s = ss.accept();
InputStream is = s.getInputStream();
while (true) {
is.read();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try { ss.close(); } catch (Exception e2) {}
}
}
public static void main(String[] args) {
new TestServer().start();
}
}
Téléchargement de TestServer.java
$ sudo ./Protonect
Version: 0.2.0
Environment variables: LOGFILE=
Usage: ./Protonect [-gpu=] [gl | cl | clkde | cuda | cudakde | cpu] []
[-noviewer] [-norgb | -nodepth] [-help] [-version]
[-frames ]
To pause and unpause: pkill -USR1 Protonect
[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 16 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @9:3 with serial 019312533747
[Info] [Freenect2Impl] found 1 devices
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
[Info] [Freenect2DeviceImpl] starting...
[Debug] [Freenect2DeviceImpl] status 0x090000: 9763
[Debug] [Freenect2DeviceImpl] status 0x090000: 9763
[Info] [Freenect2DeviceImpl] submitting depth transfers...
[Info] [Freenect2DeviceImpl] started
device serial: 019312533747
device firmware: 4.0.3916.0
[Debug] [DepthPacketStreamParser] not all subsequences received 0
[Debug] [DepthPacketStreamParser] skipping depth packet
[Debug] [DepthPacketStreamParser] skipping depth packet
[Info] [DepthPacketStreamParser] 9 packets were lost
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.7989ms -> ~53.1946Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.1562ms -> ~55.0775Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.306ms -> ~54.627Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.0493ms -> ~55.4039Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.091ms -> ~55.276Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.0869ms -> ~55.2887Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.2348ms -> ~54.8403Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.4291ms -> ~54.2621Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.2912ms -> ~54.6712Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.0582ms -> ~55.3764Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.1175ms -> ~55.1951Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.1787ms -> ~55.0095Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.1537ms -> ~55.0851Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.1901ms -> ~54.975Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 18.08ms -> ~55.3098Hz
[...]
La fréquence de rafraîchissement dépend des capacités de la machine (Ici, 55Hz pour une machine ancienne [Thuban/Oland Pro]).