Python & openni2: use 2 cameras at the same time in different processes

I’m using 2 cameras (Orbbec Astra Mini) with python3, opencv3.2 and openNi2 in xubuntu 16.04.

I can read 1 camera and I can choose which one read (changing dev[0])

dev = openni2.Device.open_all()
depth_stream = dev[0].create_depth_stream()
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 320, resolutionY = 240, fps = 30))

The problem is that if I start another process which read the other camera it crash and says:

File “/home/stark/.local/lib/python3.5/site-packages/primesense/”, line 230, in open_all
return [cls(uri) for uri in cls.enumerate_uris()]
File “/home/stark/.local/lib/python3.5/site-packages/primesense/”, line 230, in
return [cls(uri) for uri in cls.enumerate_uris()]
File “/home/stark/.local/lib/python3.5/site-packages/primesense/”, line 199, in init
File “/home/stark/.local/lib/python3.5/site-packages/primesense/”, line 209, in _reopen
c_api.oniDeviceOpen(self._orig_uri, ctypes.byref(self._handle))
File “/home/stark/.local/lib/python3.5/site-packages/primesense/”, line 2102, in wrapper
raise OpenNIError(res, msg.strip(), logfile)
primesense.utils.OpenNIError: (OniStatus.ONI_STATUS_ERROR, b’Could not open “2bc5/0404@1/10”: Failed to set USB interface!', None)

I tried to plug the cameras in the same bus and in a different one. Now they are plugged one in usb3.0 and the other in usb2.0.

They work both if called in a single process, when I start the second (same code with different device index) the second doesn’t work.

as i can suggest, the problem is in open_all code:
[cls(uri) for uri in cls.enumerate_uris()]
this list comprehension returns two initialized camera object, so even if you using just one, you can’t use another in any other process.
you can implement your own function to open any available camera in openni2 module, something like this

Thank you for the answer, I’ll try today and I’ll let you know!

How can I use it? Where I’ve to insert it? Thanks

the easiest way is to insert it directly to file of primesense module. find Device class there and insert the function into it (for example, after open_all function)

Thank you for your time :slight_smile:
I couldn’t find in my pc. I tried to search in every folder but nothing…Is it possible?

execute this in your python interpreter, this will show location of pyc file. source file will be in the same directory
upd: /home/stark/.local/lib/python3.5/site-packages/primesense/, it was in your traceback

EDIT: Thank you man! I love you! :smiley:

oh my, this forum stole my underscores. __import__("primesense.openni2").__file__
anyway, I updated my previous answer

Thank you very much! :smiley:

ur welcome :slight_smile: