libfreenect2 python
Kinect v2をUbuntuで動かせるライブラリ、libfreenect2を
Pythonから使えるようにする。
この記事の内容は失敗。
ちゃんと動くやつはこれ↓
libfreenect2 python (r9y9 版) - kubotti’s memo
手順メモ
cd ~/Documents mkdir pyfreenect2 cd pyfreenect2
pyfreenect2とpylibfreenect2があった。
remexre/pyfreenect2.git
は、Kinect2につながって1フレーム目は取れるけど、2フレーム目が取れない。
git clone https://github.com/remexre/pyfreenect2.git
TODO:libfreenect2 python (r9y9 版) 記事へのリンク
numpy
numpyが入ってなかった。
エラー
pip install numpy Traceback (most recent call last): File "/home/kubotad/.virtualenvs/ml1/bin/pip", line 11, in <module> sys.exit(main()) File "/home/kubotad/.virtualenvs/ml1/local/lib/python2.7/site-packages/pip/__init__.py", line 185, in main return command.main(cmd_args) File "/home/kubotad/.virtualenvs/ml1/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main text = '\n'.join(complete_log) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128)
sudo apt-get install python-numpy sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose sudo apt-get install python-scipy
エラー2
~/Documents/pyfreenect2/pyfreenect2$ sudo python setup.py install creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c pyfreenect2.cpp -o build/temp.linux-x86_64-2.7/pyfreenect2.o -fpermissive cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default] In file included from pyfreenect2.cpp:1:0: pyfreenect2.hpp:5:41: fatal error: libfreenect2/libfreenect2.hpp: そのようなファイルやディレクトリはありません #include <libfreenect2/libfreenect2.hpp> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
libfreenect2を/usr/localにインストールしてみる。
cd ~/libfreenect2/build cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/freenect2 make sudo make install
~/Documents/pyfreenect2/pyfreenect2$ sudo python setup.py install
→エラーに変化がなかった。
python setup.py config --with-includepath=/usr/local/freenect2/include
→そんなオプションない(--with-includepath)
export CPLUS_INCLUDE_PATH=/usr/local/freenect2/include
→エラーに変化がなかった。
diff setup.py.20160528 setup.py 15c15 < include_dirs=[numpy.get_include()], --- > include_dirs=[numpy.get_include(),"/usr/local/freenect2/include"],
→先に進んだ。
エラー3
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/pyfreenect2.o build/temp.linux-x86_64-2.7/src/Frame.o build/temp.linux-x86_64-2.7/src/FrameMap.o build/temp.linux-x86_64-2.7/src/Freenect2.o build/temp.linux-x86_64-2.7/src/Freenect2Device.o build/temp.linux-x86_64-2.7/src/Registration.o build/temp.linux-x86_64-2.7/src/SyncMultiFrameListener.o -lfreenect2 -o build/lib.linux-x86_64-2.7/_pyfreenect2.so /usr/bin/ld: -lfreenect2 が見つかりません collect2: error: ld returned 1 exit status error: command 'c++' failed with exit status 1
http://qiita.com/HirokiTakaba/items/0ec56590aee83aa371d4
ldconfig memo
http://stackoverflow.com/questions/9922949/how-to-print-the-ldlinker-search-path
ldconfig -v 2>/dev/null | grep -v ^$'\t'
symlink
cd /lib/x86_64-linux-gnu sudo ln -s /usr/local/freenect2/lib/libfreenect2.so.0.2.0 libfreenect2.so
でシンボリックリンクを作ったあと、
~/Documents/pyfreenect2/pyfreenect2$ sudo python setup.py install
でインストールがうまくいった。
OpenCV 2
/pyfreenect2$ python test.py Traceback (most recent call last): File "test.py", line 3, in <module> import cv2 ImportError: No module named cv2
opencvが入ってなかった。
Ubuntu 14.04 LTSにOpenCV2.4.11をインストール | ShumiLinux
【Ubuntu】Opencv2.4.11をUbuntuにインストールする - いつもの作業の備忘録
wget https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.13/opencv-2.4.13.zip cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON .. make sudo make install
30分くらいでOpenCV2インストール完了。
test.py
python test.py
を実行するとKinect2で撮った画像が見えた、けど、
1フレーム目しか取れない。