Ubuntu10.04でkinect

以下を参考にやってみる

必要なものを入れる
$ sudo aptitude install cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev doxygen graphviz
OpenNI
$ mkdir ~/local/src/kinect && cd ~/local/src/kinect
$ git clone git://github.com/OpenNI/OpenNI.git
$ cd OpenNI/Platform/Linux-x86/Build
$ make
$ sudo make install
KINECTドライバ
$ cd ~/local/src/kinect
$ git clone git://github.com/ros-pkg-git/Sensor.git
$ cd Sensor/Platform/Linux-x86/CreateRedist
$ ./RedistMaker
g++ -MD -MP -MT "./Release/XnDeviceSensorIO.d Release/XnDeviceSensorIO.o" -c -malign-double -fPIC -fvisibility=hidden -O2 -DNDEBUG -msse3 -I/usr/include/ni -I../../../../Include -I../../../../Source -I../../../../Source/XnCommon -DXN_DEVICE_EXPORTS -o Release/XnDeviceSensorIO.o ../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp: In member function ‘XnStatus XnSensorIO::OpenDevice(const XnChar*)’:
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:99: error: ‘xnUSBOpenDeviceByPath’ was not declared in this scope
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp: In function ‘XnStatus Enumerate(XnUInt16, XnUInt16, XnStringsHash&)’:
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:369: error: expected initializer before ‘*’ token
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:372: error: ‘astrDevicePaths’ was not declared in this scope
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:372: error: ‘xnUSBEnumerateDevices’ was not declared in this scope
../../../../Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:381: error: ‘xnUSBFreeDevicesList’ was not declared in this scope
make[1]: *** [Release/XnDeviceSensorIO.o] エラー 1
make[1]: ディレクトリ `/mnt/vg1/home/unpush/local/src/kinect/Sensor/Platform/Linux-x86/Build/XnDeviceSensorV2' から出ます
make: *** [XnDeviceSensorV2] エラー 2
make: ディレクトリ `/mnt/vg1/home/unpush/local/src/kinect/Sensor/Platform/Linux-x86/Build' から出ます

エラーになった。ググってみると、xnUSBOpenDeviceByPath was not declared でビルドできない人が他にも居るようだ。

Platform/Linux-x86/Build で make してみても同じ結果だった。


xnUSBOpenDeviceByPathでgrepしてみる

$ git grep xnUSBOpenDeviceByPath
Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp:   nRetVal = xnUSBOpenDeviceByPath(strPath, &m_pSensorHandle->USBDevice);

blameしてみる

$ git blame Source/XnDeviceSensorV2/XnDeviceSensorIO.cpp

xnUSBOpenDeviceByPathしてるのは以下の行だけで、コミットb006b664が問題っぽい。

b006b664 (ziv@openni.org   2011-01-01 18:46:18 +0200  99)   nRetVal = xnUSBOpenDeviceByPath(strPath, &m_pSensorHandle->USBDevice);

ログを見てみると b006b664 は ひとつ前の 97415bc でマージされていて、日付からしてもけっこう最近。

とりあえず b006b664 がマージされる以前に戻せばいいんじゃね?という安易な考えで突き進んでみる。

$ git checkout HEAD^
$ git log --oneline | grep b006b66
b006b66 * Audio streams are now supported. * Sensor Server now supports multiple sensors. * Server: a potential dead lock was solved. * GetStringProperty would always return XN_STATUS_ERROR.
$ git checkout HEAD^
$ git log --oneline | grep b006b66

b006b664 以前になった

$ git clean -dxf
$ ./RedistMaker

通った

$ cd ../Redist
$ sudo ./install.sh
creating config dir /usr/etc/primesense...OK
copying shared libraries...OK
copying executables...OK
registering module 'libXnDeviceSensorV2.so' with OpenNI...OK
registering module 'libXnDeviceFile.so' with OpenNI...OK
copying server config file...OK
setting uid of server...OK
creating server logs dir...OK
installing usb rules...OK

*** DONE ***
NITE

なぜかSDKが404。。。困った。

よくわからないが、openni.org からは落とせた

NITE-Bin-Ubuntu-x86-1.3.0.17.tar.bz2 をゲット(Ubuntu10.10となってるが)

$ tar xf NITE-Bin-Ubuntu-x86-1.3.0.17.tar.bz2
$ cd Nite-1.3.0.17
$ sudo ./install.bash

openni.org に use for freeなライセンスキーが書いてあるのでそれをコピペ

Please enter your PrimeSense license key: 0KOIk2JeIBYClPWVnMoRKn5cdY4=

インストールが終わったら、Data/ の xml を全て編集する

  • chmod u+w
  • License要素に上記と同じkeyを入れておく。
  • xRes="640" yRes="480"
サンプル

OpenNI/Platform/Linux-x86/Bin/Release と Nite-1.3.0.17/Samples/Bin にサンプルがある。

  • NiUserTracker


椅子まで認識しちゃってるみたいだけど、それでもボーントラッキングが出来てる。すごいなkinect

腕が交錯しても深度センサーな感じで分かる

これは楽しい入力デバイスだぞ!