I’m trying to use couple of Orbbec sensors with OpenCV, but only one of the sensors work. Second image is the same as first one. Is there a way to use multiple Orbbec sensors with OpenCV. Here is the code that I’m using.
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
const int num_sensors = 2;
int main()
{
VideoCapture cap[num_sensors];
for (int i = 0; i < num_sensors; ++i)
{
cap[i].open(CAP_OPENNI2 + i);
if (!cap[i].isOpened())
throw std::runtime_error("Failed to open sensor " + std::to_string(i));
}
Mat color[num_sensors];
Mat depth[num_sensors];
Mat depth_colored[num_sensors];
while (true)
{
for (int i = 0; i < num_sensors; ++i)
{
if (!cap[i].grab())
throw std::runtime_error("Failed to grab image from sensor " + std::to_string(i));
cap[i].retrieve(depth[i], CV_CAP_OPENNI_DEPTH_MAP);
cap[i].retrieve(color[i], CV_CAP_OPENNI_BGR_IMAGE);
// depth to colormap
double min, max;
minMaxIdx(depth[i], &min, &max);
depth[i].convertTo(depth[i], CV_8UC1, 255. / (max - min), -min);
applyColorMap(depth[i], depth_colored[i], COLORMAP_HOT);
// show
imshow("depth" + std::to_string(i), depth_colored[i]);
imshow("color" + std::to_string(i), color[i]);
}
char c = waitKey(30);
if (c == 27) // escape
break;
}
}