Skip to content

Commit

Permalink
python3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
oroulet committed Jul 20, 2016
1 parent 83b8e20 commit e621f9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
30 changes: 15 additions & 15 deletions cyni.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import sys
from struct import pack, unpack, calcsize

pixelFormats = {
"rgb": c_openni2.PIXEL_FORMAT_RGB888,
"yuv422": c_openni2.PIXEL_FORMAT_YUV422,
"gray16": c_openni2.PIXEL_FORMAT_GRAY16,
"depth1mm": c_openni2.PIXEL_FORMAT_DEPTH_1_MM,
"depth100um": c_openni2.PIXEL_FORMAT_DEPTH_100_UM,
b"rgb": c_openni2.PIXEL_FORMAT_RGB888,
b"yuv422": c_openni2.PIXEL_FORMAT_YUV422,
b"gray16": c_openni2.PIXEL_FORMAT_GRAY16,
b"depth1mm": c_openni2.PIXEL_FORMAT_DEPTH_1_MM,
b"depth100um": c_openni2.PIXEL_FORMAT_DEPTH_100_UM,
}

pixelFormatsReverse = dict([[v, k] for k, v in pixelFormats.items()])
Expand Down Expand Up @@ -166,8 +166,8 @@ class Frame(object):

cdef class VideoStream(object):
cdef c_openni2.VideoStream _stream
cdef string _streamType
cdef string _pixelFormat
cdef bytes _streamType
cdef bytes _pixelFormat
cdef int frameSize

cdef readonly int width
Expand Down Expand Up @@ -200,17 +200,17 @@ cdef class VideoStream(object):
status = self._stream.create(_device, c_openni2.SENSOR_IR)

if status != c_openni2.STATUS_OK:
error("Error opening %s stream." % self.streamType)
error("Error opening %s stream." % self._streamType)

cdef const c_openni2.SensorInfo* _info = &self._stream.getSensorInfo()

cdef const c_openni2.Array[c_openni2.VideoMode]* _modes
_modes = &(_info.getSupportedVideoModes())

foundMode = False
if self._streamType == b"color" and pixelFormat != "rgb":
if self._streamType == b"color" and pixelFormat != b"rgb":
if pixelFormat is None:
pixelFormat = "rgb"
pixelFormat = b"rgb"
else:
error("Only RGB currently supported for color streams.")
self.destroy()
Expand All @@ -233,15 +233,15 @@ cdef class VideoStream(object):
# Set the pixel format in case it was None
pixelFormat = pixelFormatsReverse[mode.getPixelFormat()]

if pixelFormat == "rgb":
if pixelFormat == b"rgb":
pixelSize = sizeof(c_openni2.RGB888Pixel)
elif pixelFormat == "yuv422":
elif pixelFormat == b"yuv422":
pixelSize = sizeof(c_openni2.YUV422DoublePixel)
elif pixelFormat == "depth1mm":
elif pixelFormat == b"depth1mm":
pixelSize = sizeof(c_openni2.DepthPixel)
elif pixelFormat == "depth100um":
elif pixelFormat == b"depth100um":
pixelSize = sizeof(c_openni2.DepthPixel)
elif pixelFormat == "gray16":
elif pixelFormat == b"gray16":
pixelSize = sizeof(c_openni2.Grayscale16Pixel)

self._pixelFormat = pixelFormat
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
openni2_lib = os.getenv('OPENNI2_REDIST')

if openni2_include is None or openni2_lib is None:
print """
print("""
Please make sure OPENNI2_INCLUDE and OPENNI2_REDIST are set. You can
source the OpenNIDevEnvironment that the OpenNI2 installer generates to set
these, or you can set them manually. To keep these environment variables
when running with sudo, you can use sudo -E python setup.py install.
"""
""")
sys.exit(1)

has_emitter_control = os.getenv('OPENNI2_HAS_EMITTER_CONTROL', 0)
has_emitter_control = bool(has_emitter_control)
if has_emitter_control:
print "Using emitter control API"
print("Using emitter control API")

class build_ext_with_config(build_ext):
def build_extensions(self):
print 'Generate config.pxi'
print('Generate config.pxi')
filename = os.path.join(os.path.dirname(__file__), 'config.pxi')
with open(filename, 'w') as fd:
for k, v in c_options.iteritems():
for k, v in c_options.items():
fd.write('DEF %s = %d\n' % (k.upper(), int(v)))
build_ext.build_extensions(self)
os.remove(filename)
Expand Down

0 comments on commit e621f9a

Please sign in to comment.