※この通り、作業を行うと必ずミスるのでこの投稿は参考にしないでください。(2014/09/09)
書き直した投稿
↓
ubuntu 14.04 LTS で Kinect v1 を動作させる(http://kyutech-triathlon.blogspot.jp/2014/09/ubuntu-1404-lts-kinect-v1.html)
最近、地味に運動ができていなかったので、Linuxで Kinect を動作させる方法を書きたいと思います。
パソコンに強い人は「なんだこの程度か」と思うかもしれません。
また、専門家がみたら「こいつ間違ってるじゃないか」と思うかもしれませんが、ご容赦ください。
とりあえず、作業開始からKinectから画像が送られてくるまでで私が行った手順を記載しておきます。
動作環境は Linux ubuntu 14.04 LTS
動かしたいものは Kinect for windows
です。
Step0 準備
以下のコマンドを打ち込みます。
sudo apt-get install git-core cmake freeglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev doxygen graphviz mono-complete --fix-missing
Step0 準備
以下のコマンドを打ち込みます。
sudo apt-get install git-core cmake freeglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev doxygen graphviz mono-complete --fix-missing
Step1
作業用ディレクトリを作成
mkdir
~/kinect
Step2
必要なファイルをダウンロード
1)
OpenNI (OpenNI-unstable)
・下記リンクに飛びます。
・branchはunstableのままでZipファイルをダウンロード
・ダウンロードしたファイルを展開
・展開したファイルを作業用ディレクトリkinectにコピー
2)
driver (SensorKinect-unstable)
・下記リンクに飛びます。
・branchはunstableのままでZipファイルをダウンロード
・ダウンロードしたファイルを展開
・展開したファイルを作業用ディレクトリkinectにコピー
3)
NiTE (NiTE-Linux-x86-2.2)
OpenNI公式のサービスが4月23日をもって終了したとかなんとかで、どこかからダウンロードしてくるということはできませんでした。
私は幸運なことにZipファイル(NiTE-Linux-x86-2.2.tar.zip)が入手できたので、これが手元にある体で話を続けます。
・zipファイルを展開
・展開したファイルを作業用ディレクトリにコピー
Step3
OpenNIのインストール
以下のコマンドを打ち込みます。
cd
~/kinect/OpenNI-unstable/Platform/Linux/CreateRedist
./RedistMaker
(Redistってのが~/kinect/OpenNI-unstable/Platform/Linux
の中に生成)
cd
~/kinect/OpenNI-unstable/Platform/Linux/Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.8.5
sudo
./install.sh
Step4
NiTEのインストール(不要かも)
以下のコマンドを打ち込みます。
cd
~/kinect/NiTE-Linux-x86-2.2
sudo
./install.sh
Step5
pclのインストール
下記URLを参照
以下のコマンドを打ち込みます。
sudo
add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo
apt-get update
sudo
apt-get install libpcl-all
Step5.5
ふて寝
インストールが終わったぜ、ひゃっほーい!ってなります。
以下のコマンドで
Kinectがつながっているかチェックできますので行ってみます。
NiViewer
結果として私はこの時点で動きませんでした。
Step6
OpenNIの関係するものを片っ端からインストール
下記URLを参考
1) 以下のコマンドを打ち込む
sudo
apt-get -yV install libopenni-dev
sudo
apt-get -yV install libopenni-java
sudo
apt-get -yV install libopenni-nite-dev
sudo
apt-get -yV install libopenni-sensor-primesense-dev
sudo
apt-get -yV install libopenni-sensor-primesense0
sudo
apt-get -yV install libopenni0
sudo
apt-get -yV install openni-dev
sudo
apt-get -yV install openni-doc
sudo
apt-get -yV install openni-sensor-primesense-bin
sudo
apt-get -yV install openni-utils
sudo
apt-get -yV install ps-engine
2) ubuntu
ソフトウェアセンターで「openni」と検索
新たに複数インストールして以下の12個にチェックをつけます。
Developer
documentation for OpenNI frameworks (openni-doc)
Microsoft
Kinect sensor modules for the OpenNI
framework (libopenni-sensor-primesense0)
Debug
and test utilities OpenNI framework (openni-utils)
Headers
for OpenNI 'Natural interaction' frameworks (libopenni-dev)
Microsoft
Kinect sensor modules for the OpenNI
frameworks (libopenni-sensor-primesense-dev)
Developer
documentation for OpenNI frameworks (openni2-doc)
Headers
for OpenNI 'Natural interaction' frameworks (libopenni2-dev)
Java
framework for sensor-based 'Natural Interaction' (libopenni-java)
Framework
for sensor-based 'Natural Interaction' (libopenni0)
OpenNI
module providing gesture and skeleton
tracking (primesense-nite-nonfree)
Debug
and test utilities OpenNI2 framework (openni2-utils)
Framework
for sensor-based 'Natural Interaction' (libopenni2-0)
Step7
Sensor Kinectのインストール
思い出したように
ダウンロードしてあったSensorKinect-unstable
のインストールを行います。
完全にインストールし終えたものだと思ってインストールし忘れていたのが、Kinectがつながらなかった最大の要因だったと考えられます。
以下のコマンドを打ち込みます。
cd
~/kinect/SensorKinect-unstable/Platform/Linux/CreateRedist
./RedistMaker
(Redistってのが~/kinect/SensorKinect-unstable/Platform/Linux
の中に生成)
cd ~/kinect/SensorKinect-unstable/Platform/Linux/Redist/Sensor-Bin-Linux-x64-v5.1.2.1
sudo
./install.sh
Step8
終わりと始まりの「NiViewer」
Kinectの接続を確認するため、再び以下のコマンドを実行します。
NiViewer
結果として動きました、ひゃっほーい
ということで、晴れてubuntuとKinectがつながります。
図1 歓喜の鮎川
Step9 pclのサンプルプログラムの実行
やっとKinectが使えるようになったので、pclの適当なサンプルからプログラムを走らせます。
エディタはemacsを使いました。
1)Kinectのテスト用のディレクトリを作り、そこに移動
mkdir ~/Documents/test_kinect
cd ~/Documents/test_kinect
2).cppのファイルを作成
emacs openni_viewer_simple.cpp
※openni_viewer_simple.cppの中身は以下のようにします。
#include <pcl/io/openni_grabber.h> #include <pcl/visualization/cloud_viewer.h> class SimpleOpenNIViewer { public: SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {} void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud) { if (!viewer.wasStopped()) viewer.showCloud (cloud); } void run () { pcl::Grabber* interface = new pcl::OpenNIGrabber(); boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f = boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1); interface->registerCallback (f); interface->start (); while (!viewer.wasStopped()) { boost::this_thread::sleep (boost::posix_time::seconds (1)); } interface->stop (); } pcl::visualization::CloudViewer viewer; }; int main () { SimpleOpenNIViewer v; v.run (); return 0; }
3)CMakeListsを作成
emacs CMakeLists.txt
※emacs CMakeLists.txtの中身は以下のようにします。
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(openni_viewer_simple)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (openni_viewer_simple openni_viewer_simple.cpp)
target_link_libraries (openni_viewer_simple ${PCL_LIBRARIES})
4)以下のコマンドを入力
cmake .
make
./openni_viewer_simple
図2 続・歓喜の鮎川
このような画像が出ます。
なんか楽しいですね。
参考サイト
http://pointclouds.org/documentation/tutorials/openni_grabber.php
0 件のコメント:
コメントを投稿