First Release of OpenNI Python Binding

934 views
Skip to first unread message

gamix

unread,
Jan 20, 2011, 8:14:42 AM1/20/11
to OpenNI
Hello Everyone!
I released a preliminary version of my Python Bindings for OpenNI on
Google Code:

https://code.google.com/p/onipy/

This early version provides only limited support for OpenNI’s image
and depth generators, but is a well-defined starting point to get more
useful functionality added quickly. Please get started by looking at
the REAME file and try to build the code by following the
instructions. I would love to get some feedback on how easy/difficult
is to build the library.
Unfortunately I only managed to test the current version on Windows,
but if you use this platform you should be able to get up and running
quickly using the provided Visual studio project. I plan to release a
Mac version for XCode soon.
Once you build the library, make sure to check out the python sample
to get a feeling for how to use the binding. When you run the script
you should see this output

OpenNI Python Wrapper version 0.3 alpha [debug]
Copyright (C) 2011 Gabriele Nataneli (gamix)
RUNNING UNIT TEST: unitTestBasicInitialization
Initializing OpenNI..
OpenNI was initialized successfully
Shutting down OpenNI..
COMPLETED UNIT TEST: unitTestBasicInitialization

For more interesting examples, you should install the Python Imaging
Library (PIL) and the OpenCV Python binding, and enable the other unit
tests in the main function of the script.
Feel free to look at C++ source code and contribute if you like this
sort of things ;-)
Cheers,
-Gamix

wayfarer_boy

unread,
Jan 21, 2011, 4:37:38 AM1/21/11
to OpenNI
Thanks Gamix. Great start, but as I don't have Windows or Visual
Studio I'm not sure I can build a Linux version yet (I'm not very
experienced in C++, and even worse at setting up a build environment
from scratch!) Perhaps someone in the group could offer instructions
for building on Linux?

jeff bryner

unread,
Jan 23, 2011, 7:00:24 PM1/23/11
to OpenNI
Nice!

Here's a linux setup.py file that worked for me:

#setup.py
from distutils.core import setup
from distutils.extension import Extension
import os.path
import sys
if sys.platform == "win32" :
include_dirs = ["C:/Boost/include/boost-1_41","."]
libraries=["boost_python-mgw"]
library_dirs=['C:/Boost/lib']
else :
include_dirs = ["/usr/include/boost-1_41",".","/usr/lib","/usr/
include/ni","/usr/include"]
libraries=["boost_python","OpenNI"]
library_dirs=["/usr/lib","/usr/include/ni","/usr/include"]

#files = ["test.cpp","itest.cpp"]
files = ['OpenNIContextWrapper.cpp', 'OpenNIDepthGeneratorWrapper.cpp',
\
'OpenNIImageGeneratorWrapper.cpp','OpenNIImageMetaDataWrapper.cpp',
\
'conversionHelpers.cpp','PythonOutputStream.cpp','wrapper.cpp']
gccargs=["-export-dynamic"]
setup(name="onipy",
ext_modules=[
Extension("onipy",files,
library_dirs=library_dirs,
libraries=libraries,
include_dirs=include_dirs,
depends=[],
extra_link_args=gccargs),
]
)


python setup.py install will install it as onipy.so

However when invoked it complains:

Python 2.6.5 (release26-maint, Sep 11 2010, 15:24:30)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import onipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initonipy)
>>>

I see an initfromxmlfile function, but not an init?



Meza

unread,
Jan 25, 2011, 7:58:01 AM1/25/11
to OpenNI
Thank you! You've done some great work Gamix.

After over two hours of installing dependencies, setting up and
compiling I've just got it your Python bindings working.

I'm on Windows 7 32bit, Visual Studio 2008, Python 2.6, OpenCV2.1

I uncommented all the 'runUnitTest' statements at the bottom of your
example testOpenNIPythonWrapper.py file, and now all the tests
successfully passed and I can see the RGB and depth videos running on
my desktop.

Now the hard part... to decide what I want to do with this!

Anyone else had luck getting these bindings running?
- Meirion

On Jan 20, 1:14 pm, gamix <gnatan...@gmail.com> wrote:

somedude

unread,
Jan 27, 2011, 11:23:44 PM1/27/11
to OpenNI
in the process of installing dependencies !!!

gamix

unread,
Jan 28, 2011, 2:13:02 PM1/28/11
to OpenNI
Hello,
Thanks for your feedback! I just released an updated version with
minor bug fixes and support for VS2010 under Windows, and XCode under
Mac OS X. I am also actively working on getting some Linux makefiles
up and running!

Jeff Bryner: the entry point of the shared library is
OpenNIImageMetaDataWrapper and the name of the library must reflect
that. You typically get that error when you rename a shared library. I
should actually prepare a distutil setup file as part of the
distribution to simplify the build/installation process, like as you
did.

Alex

unread,
Jan 28, 2011, 2:59:21 PM1/28/11
to openn...@googlegroups.com
Trying to build boost 1.45, getting errors so far. Did you grab a binary somewhere?

Alex

unread,
Jan 28, 2011, 3:13:28 PM1/28/11
to openn...@googlegroups.com
Needed to build bjam and boost from VS2010 command prompt. This step is done now.

gamix

unread,
Jan 28, 2011, 3:16:20 PM1/28/11
to OpenNI
If you are under Windows, you can use the installer for Boost:
http://www.boostpro.com/download/

Unfortunately, there is no installer for Boost 1.45 (1.44 is the one I
am using). Also, if you are running on a 64-bit system, make sure that
Boost libraries match the architecture of your Python installation!

On Mac OS X you can use MacPorts, but you must make sure that Boost
gets compiled against the correct version of Python. I never had luck
building Boost Python properly with MacPorts, so I ended up building
it myself. I blogged about the details on how to do this on my web
page:

http://www.cs.ucla.edu/~nataneli/research_site/train_of_thought/index.html#%5B%5BBoost%20Python%20Common%20Pitfalls%5D%5D%20%5B%5BBuilding%20The%20Boost%20Library%20with%20Python%20Support%20on%20Mac%20OS%20X%5D%5D%20%5B%5BCompiling%20a%20Boost%20Python%20Extension%20in%20Mac%20OS%20X%5D%5D

On Linux you may use something like Apt-Get, but I haven't tried that
in a while.

Let me know what works for you, so I can put it in the README

Jeff Bryner

unread,
Jan 29, 2011, 3:47:12 PM1/29/11
to openn...@googlegroups.com
I thought it might be something like that, but I tried with the name
OpenNIImageMetaDataWrapper and I get the same complaint.

setup.py:

from distutils.core import setup
from distutils.extension import Extension
import os.path
import sys
if sys.platform == "win32" :
include_dirs = ["C:/Boost/include/boost-1_41","."]
libraries=["boost_python-mgw"]
library_dirs=['C:/Boost/lib']
else :
include_dirs =

["/usr/include/boost-1_41",".","/usr/lib","/usr/include/ni","/usr/include"]


libraries=["boost_python","OpenNI"]
library_dirs=["/usr/lib","/usr/include/ni","/usr/include"]

files = ['OpenNIContextWrapper.cpp', 'OpenNIDepthGeneratorWrapper.cpp',\


'OpenNIImageGeneratorWrapper.cpp','OpenNIImageMetaDataWrapper.cpp',\
'conversionHelpers.cpp','PythonOutputStream.cpp','wrapper.cpp']
gccargs=["-export-dynamic"]

setup(name="OpenNIImageMetaDataWrapper",
ext_modules=[
Extension("OpenNIImageMetaDataWrapper",files,


library_dirs=library_dirs,
libraries=libraries,
include_dirs=include_dirs,
depends=[],
extra_link_args=gccargs),
]
)

This builds: build/lib.linux-i686-2.6/OpenNIImageMetaDataWrapper.so ->
/usr/lib/python2.6/site-packages


python session:

>>> import OpenNIImageMetaDataWrapper


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function

(initOpenNIImageMetaDataWrapper)
>>>

I'll be waiting semi-patiently ;-) for your linux make files.

Thanks!

Jeff.

Alex

unread,
Jan 31, 2011, 12:59:09 PM1/31/11
to openn...@googlegroups.com
I was finally able to run the unit test.

Built  boost 1.45 (bootstrap.bat   then bjam --toolset=msvc-10.0 --build-type=complete stage ;) 
Installed Python 2.7
Installed OpenCV 2.2  and copied c:\OpenCV2.2\Python2.7\Lib\site-packages\ to c:\Python27\Lib\site-packages\

Built MSVC2010 solution (library path set to boost\stage\lib, where all the dll's are located for 1.45)

Now will see what I can develop. :-) Any more python samples available for OpenNI?

gamix

unread,
Feb 2, 2011, 5:54:48 PM2/2/11
to OpenNI
Hello Everyone!

I added support for Linux courtesy of Damian Ancukiewicz. I tested the
library under Ubunty 10.10. Please download the latest version (0.4)
from Google Code and let me know if it works for you. I am pretty
happy with build process so far, now I will focus on exposing more
functionality.

Takeshi Mizumoto

unread,
Feb 3, 2011, 8:35:12 PM2/3/11
to OpenNI
Great work!

I succeed to make, and import OpenNIPythonWrapper
on Ubuntu 10.04 and Python 2.6.5.

Jeff Bryner

unread,
Feb 11, 2011, 7:20:17 PM2/11/11
to openn...@googlegroups.com
https://code.google.com/p/onipy/source/detail?r=20

Hey, noticed you included linux support! Much appreciated. It build fine
on my box..on to some code!

Jeff Bryner

unread,
Feb 11, 2011, 9:06:24 PM2/11/11
to openn...@googlegroups.com
FYI: Seems like an open cv incompatability in the test code:

Had to change testOpenNIPythonWrapper.py to:

imageDataRaw = imageGenerator.GetBGR24ImageMapRaw()
cv.SetData( currentImageFrame, imageDataRaw,imageGenerator.XRes()*3)

depthDataRaw = depthGenerator.GetGrayscale8DepthMapRaw()
cv.SetData( currentDepthFrame, depthDataRaw,imageGenerator.XRes() )

in the unittestVideoStreams function.

works fine now!

gamix

unread,
Feb 12, 2011, 5:43:11 AM2/12/11
to OpenNI
It makes sense! Your change actually agrees with the documentation:

http://opencv.willowgarage.com/documentation/python/core_operations_on_arrays.html?highlight=setdata#SetData

I wonder why I don't get any error...which version of OpenCV are you
using?

-gamix

Jeff Bryner

unread,
Feb 12, 2011, 4:06:19 PM2/12/11
to openn...@googlegroups.com
I'm on 2.0

Thanks again for building this!

John Stoner

unread,
Feb 13, 2011, 8:07:27 PM2/13/11
to OpenNI
I'm trying to get it built on OSX. I'm weak with XCode--it's been a
while for me. I think I have the dependencies installed, but now I'm
having trouble figuring out where to set the environment variables.
I'm working with your 0.4 release.

I've tried Project > Project Settings, under the Build tab, but I
still get the same errors on compile.

gamix

unread,
Feb 14, 2011, 12:49:32 AM2/14/11
to OpenNI
Indeed setting environment variables in Mac OS X is tricky! I wrote a
blog post in the past where I explain how to do it. Take a look:

http://www.cs.ucla.edu/~nataneli/research_site/train_of_thought/index.html#%5B%5BEnvironment%20Variables%20in%20Mac%20OS%20X%20Leopard%5D%5D

Remember to restart after you set the environment variable using the
launchd.conf trick.

-gamix

Olx

unread,
Feb 14, 2011, 4:20:06 AM2/14/11
to OpenNI
Hello Gamix,

I've built the binding under OSX 10.6 / Python 2.6.1.
There's a slight problem with testOpenNIPythonWrapper.py and assertion
of PIL installation. In my installation (after easy_install PIL) the
Image module is available as: "import Image", not "from PIL import
Image". "PIL" as a package/module is not available.

--
Alex.

Ivan DelSol

unread,
Mar 4, 2011, 1:10:52 PM3/4/11
to OpenNI
Hi
I'm trying to figure out how to use and help with the onipy project.
I'm an expert programmer, but I'm always mystified by setting up build
environments...
I use mingw and eclipse on windows. I have the openni/nite drivers and
examples working, but I don't know how to set up a project that lets
me actually work on the code. Can anyone help me figure out how to get
started with onipy?

On Feb 13, 9:49 pm, gamix <gnatan...@gmail.com> wrote:
> Indeed setting environment variables in Mac OS X is tricky! I wrote a
> blog post in the past where I explain how to do it. Take a look:
>
> http://www.cs.ucla.edu/~nataneli/research_site/train_of_thought/index...
Reply all
Reply to author
Forward
0 new messages