Get the serial number of a camera - Openni2 python

1.4k views Asked by At

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

2

There are 2 answers

5
Ufuk Can Bicici On BEST ANSWER

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.

0
Dan Erez On
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