Hi, so far I've used DepthAI in Python without problems.
Lately I have been trying to integrate DepthAI in a multi-threaded C++ application. Basically I want to be able to stream multiple OAK cameras after selecting them based on their MxId.
I am seeing some weird behavior which I think is caused by the fact that the application itself is multi-threaded, or at least I can't find other explanations for it, but I don't understand exactly what the problem is.
This is a short summary of relevant code:
#include <depthai/depthai.hpp>
oak_camera::oak_camera(const std::string mx_id)
: mx_id(mx_id), thread(&oak_camera::stream, this)
{
}
oak_camera::~oak_camera()
{
thread.join();
}
void oak_camera::stream()
{
dai::Pipeline pipeline;
// define some pipeline here...
bool found;
dai::DeviceInfo device_info;
std::tie(found, device_info) = dai::Device::getDeviceByMxId(mx_id);
dai::Device device{pipeline, device_info};
// start showing frames here....
}
I'll try to explain here the problems I had so far:
the function (found, device_info) = dai::Device::getDeviceByMxId(mx_id)
would return "found" as false even if the camera is connected. If I ignore "found" and initialize a device with the retrieved device_info it works anyway and the correct camera is started.
If I use an "if" statement before initializing the device, something like:
if (mx_id == something)
{
dai::Device device{pipeline, device_info};
}
else
{
dai::Device device{pipeline};
}
the "else" part doesn't work, throwing the error No available devices
. If I remove the if statement and use either of the device initializations on their own it works.
I'm not sure what the problem is. The pipeline and initialization should be run in the same thread and at the moment I'm testing with only one camera so there isn't multiple threads running it.
Anyone could have any idea what the problem is?