-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Opening a device with OpenNI2Grabber #3227
Comments
Can you try |
I get the following error:
|
AFAIK Orbec requires custom OpenNI2 libraries and does not work with the libs you get with |
Yeah, I installed the OpenNI2 library from here: https://orbbec3d.com/develop/ I indeed had to work around a few issues (like the Structure Sensor being recognized as an Astra), and eventually the only thing that I haven't fixed yet is getting the correct |
No, I didn't try that. I will try a few things and report back when I have something that looks like a solution :) |
Update on the state of things: the exception I got was unrelated (my bad), but feeding Failing to find another option, I resumed sending device_ = deviceManager->getAnyDevice (); I replaced it with a loop that checks whether the bool found = false;
for (int idx = 0; idx < deviceManager->getNumOfConnectedDevices (); ++idx) {
auto device = deviceManager->getDeviceByIndex (idx);
if (device->getUri () == device_id) {
device_ = device;
found = true;
break;
}
}
if (not found) {
device_ = deviceManager->getAnyDevice ();
} It's rather inelegant, but it finally works for our use case, and even though the string comparison against I entertained the idea of passing device indices as you proposed, but our devices are sometimes discovered separately in different places, so it's difficult to maintain a proper device count. If we had to restart the project from the ground up, we would probably do it differently. I don't know whether there could be an elegant solution to this issue in PCL, so if you don't wish to discuss the problem further, I will close this issue. |
Thanks for reporting back.
I'd rather prefer to find a solution and merge a patch. The device manager seems to have a method called |
Hum, I will try this, just the time to recompile everything again. Won't it throw an exception if the URI doesn't match anything though? We will most likely want to catch it and fall back to |
Totally agree. |
I replaced the previous loop by the following code and everything seems to work fine when try {
device_ = deviceManager->getDevice (device_id);
} catch (const pcl::io::IOException&) {
device_ = deviceManager->getAnyDevice ();
} |
Great -- please send a patch. If it wasn't for backwards compatibility, I would not catch the exception; it's up to the user to decide what to do if the device with given URI is not available. Now that we do have a try/catch, I think we should at least notify the user with a |
I think that the only case when How should we document that: in the bragger constructor documentation or in the |
It'd be super-helpful if you add the explanation of valid options for |
I skimmed through openni2 |
Undocumented behavior that supplying an invalid device URI results in opening a device (albeit random) without exceptions. |
I suspect that this is a behavior worth "breaking" :) |
OK, well, I wouldn't be against actually. @Morwenn what's your opinion? In case you agree, let's not catch/warn and let the user deal with the exception. |
I'm all for loud errors rather than silent ones; actually it would have saved me a few hours this week if my code had been rejected instead of picking the first available device. If it's ok with you I'll just replace the device_ = deviceManager->getDevice (device_id); The only case where where picking the first available device makes sense is when providing an empty string, which is already handled by the constructor of |
Is there a way to initialize an
OpenNI2Grabber
once theOpenNI2Device
I want to work with is known (which is to say I've got an instance of the device class)?Your Environment
Context
I am trying to use the
OpenNI2Grabber
class and have noticed an issue while trying to use both the StructureSensor and the Orbbec Astra at the same time: I thought that the expecteddevice_id
passed to its constructor corresponded to a device'sgetUri
, but it took me quite some time to realize that the grabber didn't really work with that parameter, and from reading the code it seems that it's usingOpenNI2DeviceManager::getAnyDevice()
under the hood and thus both my devices are initialized with the default device (in my case the StructureSensor).To give a bit more context: I inherited a code base where we use
OpenNI2DeviceManager::getNumOfConnectedDevices
andgetDeviceByIndex
to discover the existing devices compatible with OpenNI2. We save a value somewhere (currently the result ofgetUri
) and later reuse that value to instantiate anOpenNI2Grabber
and work with the device we're interested in. However it doesn't seem thatOpenNI2Grabber
is expecting the result ofgetUri
, but I failed to find which kind of value I could retrieve from theOpenNI2Device
to make sure that it will grab the appropriate device. How can I retrieve the relevant information to construct a grabber matching the device I want?The
getUri
function returns values such as1d27/0600@1/11
or2bc5/0402@1/12
on my computer.Expected Behavior
I expect the following code to work (or at least that there is a function in
OpenNI2Device
that will return a value sufficient to construct a correspondingOpenNI2Grabber
):Current Behavior
The code above works as expected when a single device is found by the
OpenNI2DeviceManager
but fails when two devices are connected. Both return the same URI as if the grabber was constructed withOpenNI2DeviceManager::getAnyDevice()
.The text was updated successfully, but these errors were encountered: