Orbbec Astra Pro 设备调试 Demo
使用奥比中光Astra Pro捕获深度图与彩色图代码
#include <astra/astra.hpp>
#include <opencv2/opencv.hpp>
int main(int argc, char** argv)
{
astra::initialize();
astra::StreamSet streamset;
astra::StreamReader reader = streamset.create_reader();
auto depthStream = reader.stream<astra::DepthStream>();
astra::ImageStreamMode depthMode;
depthMode.set_width(640);
depthMode.set_height(480);
depthMode.set_pixel_format(astra_pixel_formats::ASTRA_PIXEL_FORMAT_DEPTH_MM);
depthMode.set_fps(30);
depthStream.set_mode(depthMode);
depthStream.start();
auto colorStream = reader.stream<astra::ColorStream>();
astra::ImageStreamMode colorMode;
colorMode.set_width(640);
colorMode.set_height(480);
colorMode.set_pixel_format(astra_pixel_formats::ASTRA_PIXEL_FORMAT_RGB888);
colorMode.set_fps(30);
colorStream.set_mode(colorMode);
colorStream.start();
while (true)
{
astra_update();
if (!reader.has_new_frame())
{
continue;
}
auto frame = reader.get_latest_frame(100);
auto depthFrame = frame.get<astra::DepthFrame>();
auto depth = depthFrame.data();
auto depthWidth = depthFrame.width();
auto depthHeight = depthFrame.height();
if (depthFrame.is_valid())
{
cv::Mat rawMat(depthHeight, depthWidth, CV_16UC1, (void*)depth);
cv::Mat depthMat;
rawMat.convertTo(depthMat, CV_8UC1);
cv::imshow("Depth Viewer", depthMat);
}
auto colorFrame = frame.get<astra::ColorFrame>();
auto color = colorFrame.data();
auto colorWidth = colorFrame.width();
auto colorHeight = colorFrame.height();
if (colorFrame.is_valid())
{
cv::Mat rawMat(colorHeight, colorWidth, CV_8UC3, (void*)color);
cv::Mat colorMat;
cv::cvtColor(rawMat, colorMat, cv::COLOR_BGR2RGB);
cv::imshow("Color Viewer", colorMat);
}
int key = cv::waitKey(100);
if (key == 27)
break;
}
astra::terminate();
}
