severin-lemaignan / openni-python

Python bindings for OpenNI2 and NiTE2
Other
55 stars 16 forks source link

Can't open .ONI videos using string filenames #12

Open krishynan opened 5 years ago

krishynan commented 5 years ago

Problem: .ONI files can't be opened neither using the filename as the path neither using the Device.open_file() method.

Sample Code:

from openni import openni2
OPENNI_FOLDER_PATH = r".\OpenNI-Windows-x64-2.3.0.55\Redist" #To your Redist folder
ONI_VIDEO_PATH = '.\\video.oni'

openni2.initialize(OPENNI_FOLDER_PATH)
device = openni2.Device.open_file(ONI_VIDEO_PATH)

Alternative method that also fails:

from openni import openni2
OPENNI_FOLDER_PATH = r".\OpenNI-Windows-x64-2.3.0.55\Redist"
ONI_VIDEO_PATH = '.\\video.oni'

openni2.initialize(OPENNI_FOLDER_PATH)
device = openni2.Device(ONI_VIDEO_PATH)

Error log:

Traceback (most recent call last):
  File "c:\Users\user\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\user\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
    run()
  File "c:\Users\user\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\user\Documents\Python Scripts\AstraSProductFlow\test_filter.py", line 6, in <module>
    device = openni2.Device(ONI_VIDEO_PATH)
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\site-packages\openni\openni2.py", line 223, in __init__
    self._reopen()
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\site-packages\openni\openni2.py", line 233, in _reopen
    c_api.oniDeviceOpen(self._orig_uri, ctypes.byref(self._handle))
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\site-packages\openni\_openni2.py", line 2826, in wrapper
    res = func(*args)
  File "C:\Users\user\AppData\Local\Continuum\anaconda3\envs\AstraS\lib\site-packages\openni\_openni2.py", line 2901, in oniDeviceOpen
    return _oniDeviceOpen(uri, pDevice)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

Suggested working correction for the open_file method: File openni2.py line 262 From return cls(filename) to return cls(filename.encode('utf-8'))

rokopi-byte commented 5 years ago

I can confirm, I always have to do like this: dev = openni2.Device.open_file(video_path.encode('utf-8'))