libfreenect2 python (r9y9 版)

r9y9/pylibfreenect2 を試してみることにした。

git clone https://github.com/r9y9/pylibfreenect2.git

r9y9/pylibfreenect2

remexre/pyfreenect2.gitのアンインストール

動きがイマイチだった、remexreさんが作ったpyfreenect2をアンインストール。

http://horse-brain.blogspot.jp/2012/04/python-setuppy-install.html

~/Documents/pyfreenect2/pyfreenect2_remexre$ sudo python setup.py install --record files.txt
[sudo] password for kubotad: 
running install
running bdist_egg
running egg_info
writing requirements to pyfreenect2.egg-info/requires.txt
writing pyfreenect2.egg-info/PKG-INFO
writing top-level names to pyfreenect2.egg-info/top_level.txt
writing dependency_links to pyfreenect2.egg-info/dependency_links.txt
reading manifest file 'pyfreenect2.egg-info/SOURCES.txt'
writing manifest file 'pyfreenect2.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/_pyfreenect2.so -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.7/pyfreenect2.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/pyfreenect2.py to pyfreenect2.pyc
creating stub loader for _pyfreenect2.so
byte-compiling build/bdist.linux-x86_64/egg/_pyfreenect2.py to _pyfreenect2.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pyfreenect2.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyfreenect2.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyfreenect2.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyfreenect2.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pyfreenect2.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/pyfreenect2-0.0.0-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pyfreenect2-0.0.0-py2.7-linux-x86_64.egg
Removing /usr/local/lib/python2.7/dist-packages/pyfreenect2-0.0.0-py2.7-linux-x86_64.egg
Copying pyfreenect2-0.0.0-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
pyfreenect2 0.0.0 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/pyfreenect2-0.0.0-py2.7-linux-x86_64.egg
Processing dependencies for pyfreenect2==0.0.0
Traceback (most recent call last):
  File "setup.py", line 21, in <module>
    install_requires=["numpy"])
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 73, in run
    self.do_egg_install()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 96, in do_egg_install
    cmd.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 381, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 597, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 648, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 694, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 633, in resolve
    requirements.extend(dist.requires(req.extras)[::-1])
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2291, in requires
    dm = self._dep_map
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2277, in _dep_map
    for extra,reqs in split_sections(self._get_metadata(name)):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2715, in split_sections
    for line in yield_lines(s):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1989, in yield_lines
    for ss in strs:
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2305, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1369, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1361, in get_metadata
    return self._get(self._fn(self.egg_info,name))
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1425, in _get
    return self.loader.get_data(path)
zipimport.ZipImportError: bad local file header in /usr/local/lib/python2.7/dist-packages/pyfreenect2-0.0.0-py2.7-linux-x86_64.egg

なんかエラーになったので、とりあえず、
/usr/local/lib/python2.7/dist-packages/pyfreenect2-0.0.0-py2.7-linux-x86_64.egg
を消した。

r9y9/pylibfreenect2 のインストール
sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 25, in <module>
    raise OSError("{}: is not found".format(libfreenect2_configh_path))
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freenect2/lib

→エラーに変化なし。


Symbolic Linkを作ったらエラーが変わった。

/usr/local/include$ sudo ln -s /usr/local/freenect2/include/libfreenect2 libfreenect2

/usr/local/lib$ sudo ln -s /usr/local/freenect2/lib/libfreenect2.so libfreenect2.so
$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 35, in <module>
    raise OSError("libfreenect2 library cannot be found")
OSError: libfreenect2 library cannot be found
$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 61, in <module>
    raise RuntimeError("Cython is required to generate C++ codes.")
RuntimeError: Cython is required to generate C++ codes.

Cythonのインストール。

sudo pip install Cython

pyfreenect2がインストールできた。

~/Documents/pyfreenect2/pylibfreenect2$ sudo python setup.py install


Installed /usr/local/lib/python2.7/dist-packages/enum34-1.1.6-py2.7.egg
Searching for numpy==1.8.2
Best match: numpy 1.8.2
numpy 1.8.2 is already the active version in easy-install.pth

Using /usr/lib/python2.7/dist-packages
Finished processing dependencies for pylibfreenect2==0.0.1-dev

ドキュメントにあったテストコードは何故か失敗する。

$ nosetests -v -w tests/
Failure: ImportError (No module named libfreenect2) ... ERROR

======================================================================
ERROR: Failure: ImportError (No module named libfreenect2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/loader.py", line 411, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/kubotad/Documents/pyfreenect2/pylibfreenect2/tests/test_libfreenect2.py", line 9, in <module>
    from pylibfreenect2 import Freenect2, SyncMultiFrameListener
  File "/home/kubotad/Documents/pyfreenect2/pylibfreenect2/pylibfreenect2/__init__.py", line 107, in <module>
    from .libfreenect2 import *
ImportError: No module named libfreenect2

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

https://github.com/r9y9/pylibfreenect2/blob/master/examples/multiframe_listener.py
のコードをPyCharmに貼り付けて実行したら、Kinect2の映像が見れた。
これで、Kinect2の深度データ付き映像 + Python機械学習 をする準備が整った。
ChainerかTensorFlowを使って、Deep Learningで何か学習させてみたい。