Kinect stuff

Installing kinect and processing in the goal of communicating with blender
Install kinect for Windows SDK (I have the kinect 1)
Install last version of Processing
Install library OpenNI on processing
Install library oscP5 on processing
Run example code with OpenNI to check connection with kinect
Install blender add-on nodesOSC_240
Open blender
Tutorial for nodeOSC python communication 
More info on nodeOSC 
To be continued


Kinect connected to processing communication with python blender
Install library OpenNI on processing
Install library oscP5 on processing

Open Blender, 
Open python console
Run code
import bpy
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import ThreadingOSCUDPServer
from threading import Thread
import socket

# Function to handle incoming OSC messages
def osc_handler(address, *args):
# Parse and use the incoming data
x, y, z = args
print(f"Received OSC message: X={x}, Y={y}, Z={z}")
# Update Blender objects or perform other actions
# For example, move an empty object based on OSC data
bpy.data.objects['Cube'].location = (x, y, z)

# Get an available port dynamically
def get_available_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
sock.close()
return port

# Set up OSC server with a dynamic port
osc_port = get_available_port()
dispatcher = Dispatcher()
dispatcher.map("/kinect/position", osc_handler)
server = ThreadingOSCUDPServer(('127.0.0.1', osc_port), dispatcher)

# Start OSC server in a separate thread
server_thread = Thread(target=server.serve_forever)
server_thread.start()

print(f"OSC server is running on port {osc_port}.")

¬I didn't chose a specific port because my computer was being moody and didn't want to connect to any port. This is the way I managed to connect. If you want to chose any other port plz do.¬

You can open processing and run this code, replace port by port selected in python blender

import SimpleOpenNI.*;
import oscP5.*;
import netP5.*;

SimpleOpenNI context;
OscP5 oscP5;
NetAddress blenderAddress;

// Choose a port number that is not in use
int oscPort = 61912; // Change to an available port

void setup() {
size(640, 480, P2D);
context = new SimpleOpenNI(this);
if (context.isInit() == false) {
println("Can't init SimpleOpenNI, maybe the camera is not connected!");
exit();
return;
}

// mirror is by default enabled
context.setMirror(true);

// enable depthMap generation
context.enableDepth();

// enable ir generation
context.enableRGB();

// Set up OSC with a chosen port
oscP5 = new OscP5(this, oscPort);
blenderAddress = new NetAddress("127.0.0.1", oscPort);
}

void draw() {
// update the cam
context.update();

background(200, 0, 0);

// draw depthImageMap
image(context.depthImage(), 0, 0);

// draw irImageMap
image(context.rgbImage(), context.depthWidth() + 10, 0);

// Get depth data from a specific pixel (e.g., center of the image)
int depthX = context.depthWidth() / 2;
int depthY = context.depthHeight() / 2;

// Get depth map values
int[] depthValues = context.depthMap();
int depthIndex = depthX + depthY * context.depthWidth();
int depth = depthValues[depthIndex];

// Convert depth coordinates to real-world XYZ
PVector depthPoint = new PVector(depthX, depthY, depth);
PVector realWorldCoordinates = new PVector();
context.convertProjectiveToRealWorld(depthPoint, realWorldCoordinates);

float x = realWorldCoordinates.x;
float y = realWorldCoordinates.y;
float z = realWorldCoordinates.z;

// Send OSC message to Blender
OscMessage msg = new OscMessage("/kinect/position");
msg.add(x);
msg.add(y);
msg.add(z);
oscP5.send(msg, blenderAddress);
}

HTML Website Creator