3D 摄像头在现代工业中发挥着重要作用。它们帮助我们解决无法通过 2D 数据完成的计算机视觉任务。两年前,OpenCV 支持 Astra 系列的 Orbbec 3D 摄像头。现在又有一个好消息。OpenCV 支持其 3D UVC 摄像头!
与使用以前的 Astra 3D 摄像头(需要使用 OpenNI2 SDK 构建的 OpenCV)不同,不需要任何第三方库即可使用 Astra+ 系列和 Femto 系列的新 3D UVC 摄像头。只需插入 3D 摄像头,即可使用cv::VideoCapture 类读取深度传感器和彩色传感器的数据或 RGBD 数据流。深度图和彩色图像的校准和对齐也无需费力完成。
以下是一个示例,说明 OpenCV 如何轻松地与 Orbbec 3D UVC 摄像头配合使用。
#include <opencv2/videoio.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <iostream> using namespace cv; int main() { VideoCapture obsensorCapture(0, CAP_OBSENSOR); if(!obsensorCapture.isOpened()){ std::cerr << "Failed to open obsensor capture! Index out of range or no response from device"; return -1; } double fx = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_FX); double fy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_FY); double cx = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CX); double cy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CY); std::cout << "obsensor camera intrinsic params: fx=" << fx << ", fy=" << fy << ", cx=" << cx << ", cy=" << cy << std::endl; Mat image; Mat depthMap; Mat adjDepthMap; while (true) { // Grab the depth map: // obsensorCapture >> depthMap; // Another way to grab the depth map (and bgr image). if (obsensorCapture.grab()) { // bgr image if (obsensorCapture.retrieve(image, CAP_OBSENSOR_BGR_IMAGE)) { imshow("RGB", image); } // depth map if (obsensorCapture.retrieve(depthMap, CAP_OBSENSOR_DEPTH_MAP)) { normalize(depthMap, adjDepthMap, 0, 255, NORM_MINMAX, CV_8UC1); applyColorMap(adjDepthMap, adjDepthMap, COLORMAP_JET); imshow("DEPTH", adjDepthMap); } // overlay depth map on bgr image static const float alpha = 0.6f; if (!image.empty() && !depthMap.empty()) { normalize(depthMap, adjDepthMap, 0, 255, NORM_MINMAX, CV_8UC1); cv::resize(adjDepthMap, adjDepthMap, cv::Size(image.cols, image.rows)); for (int i = 0; i < image.rows; i++) { for (int j = 0; j < image.cols; j++) { cv::Vec3b& outRgb = image.at<cv::Vec3b>(i, j); uint8_t depthValue = 255 - adjDepthMap.at<uint8_t>(i, j); if (depthValue != 0 && depthValue != 255) { outRgb[0] = (uint8_t)(outRgb[0] * (1.0f - alpha) + depthValue * alpha); outRgb[1] = (uint8_t)(outRgb[1] * (1.0f - alpha) + depthValue * alpha); outRgb[2] = (uint8_t)(outRgb[2] * (1.0f - alpha) + depthValue * alpha); } } } imshow("DepthToColor", image); } image.release(); depthMap.release(); } if (pollKey() >= 0) break; } return 0; }
ORBBEC 成立于 2013 年,总部位于深圳,是 3D 感知技术的全方位解决方案提供商,包括传感器、软件和算法。它是继微软、苹果和英特尔之后,全球第四家实现 3D 传感器量产的企业。
该公司已推出多种类型的 3D 传感器,已广泛应用于手机、智慧零售、智慧制造、机器人和物流等行业。如今,Orbbec 已成为 3D 感知技术领域的领先企业之一,致力于为所有终端提供“智慧 3D 眼睛”,以了解世界!
Orbbec 是 OpenCV 的开发合作伙伴之一。OpenCV 和 Orbbec 共同致力于广泛合作,为 3D 计算机视觉领域的开发人员提供服务。