注: 此教程是针对Mac用户的
首先你需要一个Kinect以及那根坑爹的电源线。
For Processing:
下载Daniel Shiffman的openkinect library:
https://github.com/shiffman/libfreenect/raw/master/wrappers/java/processing/distribution/openkinect.zip把内容解压到你的 ~/Documents/Processing/libraries/ 里面 (~代表你的用户home folder)
用起来很简单:
//导入库
import org.openkinect.*;
import org.openkinect.processing.*;
Kinect kinect;
void setup() {
size (640, 480);
kinect = new Kinect(this); //创建kinect对象
kinect.start(); //建立连接
kinect.enableDepth(true); //要用代表距离的depth map的话就要enable这个
kinect.enableRGB(true); //这个enable的是RGB摄像头
}
之后在draw()里面可以调用一些命令:
void draw() {
kinect.tilt(20); //这个可以控制上下角度
image(kinect.getVideoImage(), 0, 0); //把RGB摄像头目前的图像画出来
image(kinect.getDepthImage(), 506, 378, 128, 96); //把depth map缩小了画在右下角
}
假如你想要使用原始的depth map数据, 用这个:
int[] depth = kinect.getRawDepth();
此方法返回的是代表整个depth map的int数列。每一个值代表了depth map里的一个像素。比如整个图像里第y排第x个像素的深度,就是depth[y*width+x]
用两个嵌套的for loop可以走遍整个depth map数列来进行各种像素操作。这个我们下次再讲。