3

I'm using python3 and openni2.

When I open the communication with a camera (in this case I'm using an Orbbec Astra), is it possible to read the serial number of the camera?

This is how I open the communication:

    dev = openni2.Device.open_any()
    depth_stream = dev.create_depth_stream()
    depth_stream.start()
    depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 320, resolutionY = 240, fps = 30))

My goal is to find everytime the same camera even if I change the usb port and I've more orrbec connected.

Thank you

parsley72
  • 8,449
  • 8
  • 65
  • 98
G. Threepwood
  • 454
  • 8
  • 23

2 Answers2

2

I don't know exactly about the python version, but in the old OpenNI C++ library, you were able to query the device id with something similar to following:

openni::Array deviceList;
openni::OpenNI::enumerateDevices(&deviceList);

for(int i = 0; i != deviceList.getSize(); i++) {
   const openni::DeviceInfo& info = deviceList[i];
   std::string uri = info.getUri(); 
   cout << "URI " << i << ": " << uri << "\n";
 }

Most probably there could be a python class wrapping the underlying DeviceInfo class and its capabilities, so you can ask for the Uri.

Ufuk Can Bicici
  • 3,589
  • 4
  • 28
  • 57
  • 1
    Hi! Thank you for the answer. I tried this: dev.get_device_info() and it returns : OniDeviceInfo(uri = b'2bc5/0401@1/2', vendor = b'Orbbec', name = b'Astra', usbVendorId = 11205, usbProductId = 1025) I wanted to ask: What's uri and which one is the id of the camera? – G. Threepwood Jul 12 '17 at 12:59
  • OK, I think the uri field contains the unique identifier for your device. Try dev.get_device_info().uri – Ufuk Can Bicici Jul 12 '17 at 13:00
  • 1
    I think the uri is the right id, but the @1/2 means that is the first of two devices, because if I unplug and plug again the device in another usb it changes (1/3, 1/4, ecc..). However dev.get_device_info().uri works! Thank you! Thumbs up for you :) – G. Threepwood Jul 12 '17 at 13:55
  • Hi again! :) Sorry but the uri is the same in different cameras. I've 5-6 cameras and they have 2 different uri... – G. Threepwood Jul 14 '17 at 09:25
  • I see, back in the past I worked with Asus Xtion Pro cameras and they provided different Uri's per device via the OpenNI Api. This is a really weird situation that getUri() gives the same code for different devices... – Ufuk Can Bicici Jul 14 '17 at 09:55
0
import ctypes
from primesense import openni2  # , nite2
from primesense import _openni2 as c_api
serial_number = str(dev.get_property(c_api.ONI_DEVICE_PROPERTY_SERIAL_NUMBER, (ctypes.c_char * 100)).value)

You may want to clean up the string you get a bit. ( tested on orbbec astra ).

I used the following links to get to the answer:

https://github.com/OpenNI/OpenNI2/blob/master/Include/OniProperties.h http://docs.ros.org/api/openni2_camera/html/openni2__device__manager_8cpp_source.html

Dan Erez
  • 1,364
  • 15
  • 16