@uents blog

Code wins arguments.

MacにEclipse+Processing+simpile-opennniを導入してKinectのCamera/Depth画像が取れるまでにやったこと

特に頑張らなくてもできました。思ったよりかんたんです。ほんとはEclipseはどうでもよかったんですが、ProcessingのデフォルトIDEが肌に合いそうになかったので…、使うことにしました。

詳細はそれぞれのリンク先等をご覧ください。

環境

Homebrewの導入

ターミナル上で、

$ ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
$ brew update

でOK。詳しくはhttps://github.com/mxcl/homebrew/wiki:titile=公式Wikiを参照。

OpenNI+SensorKinect+NITEの導入

デフォルトのインストーラを使うと変なディレクトリにライブラリが入りそうなので、下記のFormulaを使わせて頂きました。超便利です、ありがとうございます。

以下、上記に書いてある通りにやっていく。

libusbのインストール
$ brew install libusb --universal
Formulaの取得
$ cd /usr/local/Library/Formula
$ curl --insecure -O "https://raw.github.com/totakke/openni-formula/master/openni.rb"
$ curl --insecure -O "https://raw.github.com/totakke/openni-formula/master/sensor.rb"
$ curl --insecure -O "https://raw.github.com/totakke/openni-formula/master/nite.rb"
OpenNIのインストール
$ brew install openni
$ sudo mkdir -p /var/lib/ni
$ sudo niReg /usr/local/lib/libnimMockNodes.dylib
$ sudo niReg /usr/local/lib/libnimCodecs.dylib
$ sudo niReg /usr/local/lib/libnimRecorder.dylib
SensorKinectのインストール

Kinectを使う場合はSensorKinectを導入。(XtionだとSensorを導入、たぶん)

$ brew install sensor-kinect
$ sudo niReg /usr/local/lib/libXnDeviceSensorV2KM.dylib /usr/local/etc/primesense
$ sudo niReg /usr/local/lib/libXnDeviceFile.dylib /usr/local/etc/primesense
$ sudo mkdir -p /var/log/primesense/XnSensorServer
$ sudo chmod a+w /var/log/primesense/XnSensorServer
NITEのインストール
$ brew install nite
$ sudo niReg /usr/local/lib/libXnVFeatures_1_5_2.dylib /usr/local/etc/primesense/Features_1_5_2
$ sudo niReg /usr/local/lib/libXnVHandGenerator_1_5_2.dylib /usr/local/etc/primesense/Hands_1_5_2
$ sudo niLicense PrimeSense 0KOIk2JeIBYClPWVnMoRKn5cdY4=

Kinectをつないでサンプルプログラムを実行。あっさり動きました :)

Processingの導入

http://processing.org/download から取得して、適当なフォルダに展開。

simple-openniの導入

http://code.google.com/p/simple-openni/downloads/list から取得して、適当なフォルダに展開。
(zipを展開しただけで、インストールスクリプトは実行していません)

Eclipseの導入

http://www.eclipse.org/downloads から「Eclipse IDE for Java Developers」を取得してインストールすればいいと思います。

Eclipseの設定

ProcessingライブラリのImport

公式さんを参考に。

simpile-openniライブラリのImport

公式さんを参考に。

テストプログラムを実行

これも 公式さんのExample を参考にしながら、

import processing.core.*;
import SimpleOpenNI.*;

public class KinectApplet extends PApplet {
	SimpleOpenNI context;

	public void setup() {
		context = new SimpleOpenNI(this);
		
		// enable depthMap generation 
		context.enableDepth();
		  
		// enable camera image generation
		context.enableRGB();
		 
		background(200,0,0);
		size(context.depthWidth() + context.rgbWidth() + 10, context.rgbHeight()); 
	}
	
	public void draw() {
		// update the cam
		context.update();
		  
		// draw depthImageMap
		image(context.depthImage(),0,0);
		  
		// draw camera
		image(context.rgbImage(),context.depthWidth() + 10,0);
	}
}

Javaアプレットとして実行すると、

どーん、出ました! :)

Depth映像とCamera映像の高さがずれている気がするけど、おいおい調べて行こうかなと思います。