前言
深度图(Depth Map)是一种用于表示场景中各点到观察者距离的图像,它能够为计算机视觉和图形处理提供重要的三维信息。在深度图中,每个像素的值代表了场景中对应点到摄像头的距离,通常使用灰度值或伪彩色来表示,灰度值越大或颜色越暖,表示距离越近。深度图广泛应用于虚拟现实、增强现实、三维重建、物体识别等领域。使用深度图,我们可以实现物体的遮挡检测、距离测量、三维建模等功能,从而为智能设备提供更加丰富的交互体验和更准确的环境感知能力。
本系列旨在通过奥比中光深度相机Gemini335为大家介绍如何使用本相机以及如何使用可见光与深度信息结合的方式用来解决实际问题
一、Gemini介绍
Orbbec Gemini 330系列3D相机集成了Orbbec的最新自研深度引擎ASIC,结合了主动和被动立体视觉技术,可在室内和室外条件下无缝运行。通过在3D相机内部完成深度图像计算和深度图像到彩色图像的空间对齐变换,实现了最小数据延时,并极大降低了对上位机的依赖。相机预置了多种工作模式,便捷高效适应不同的应用场景。灵活而丰富的帧同步机制使多摄像机操作变得简单且可扩展。
Orbbec Gemini 330系列由以下多个组件组成:
● 自研深度引擎ASIC芯片
● 双目IR模块
● 散斑发射模块
● RGB模块
● 激光测距模块
● IMU模块
● Orbbec SDK
● Wrappers(e.g. ROS1 / ROS2 / Python)
本系列使用的相机为Gemini335l ,其相机参数如下图所示: try {
// Create a pipeline with default device
ob::Pipeline pipe;
// By creating config to configure which streams to enable or disable for the pipeline, here the depth stream will be enabled
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();
config->enableVideoStream(OB_STREAM_DEPTH);
// Start the pipeline with config
pipe.start(config);
auto currentProfile = pipe.getEnabledStreamProfileList()->getProfile(0)->as<ob::VideoStreamProfile>();
// Create a window for rendering, and set the resolution of the window
Window app("DepthViewer", currentProfile->width(), currentProfile->height());
while(app) {
// Wait for up to 100ms for a frameset in blocking mode.
auto frameSet = pipe.waitForFrames(100);
if(frameSet == nullptr) {
continue;
}
auto depthFrame = frameSet->depthFrame();
// for Y16 format depth frame, print the distance of the center pixel every 30 frames
if(depthFrame->index() % 30 == 0 && depthFrame->format() == OB_FORMAT_Y16) {
uint32_t width = depthFrame->width();
uint32_t height = depthFrame->height();
float scale = depthFrame->getValueScale();
uint16_t *data = (uint16_t *)depthFrame->data();
// pixel value multiplied by scale is the actual distance value in millimeters
float centerDistance = data[width * height / 2 + width / 2] * scale;
// attention: if the distance is 0, it means that the depth camera cannot detect the object(may be out of detection range)
std::cout << "Facing an object " << centerDistance << " mm away. " << std::endl;
}
// Render frame in the window
app.addToRender(depthFrame);
}
// Stop the pipeline
pipe.stop();
return 0;
}
catch(ob::Error &e) {
std::cerr << "function:" << e.getName() << "\nargs:" << e.getArgs() << "\nmessage:" << e.getMessage() << "\ntype:" << e.getExceptionType() << std::endl;
exit(EXIT_FAILURE);
}
效果: