c++ - 如何使用 C++ 和英特尔 API 将 .JSON 文件加载到 RealSense D435 相机
问题描述
我正在尝试调整我的深度相机(RealSense D435)以获得更好/不同的深度数据。因此,我想尝试使用英特尔建议的参数配置中的不同预设,如英特尔 SDK 中所述。英特尔建议使用预设,不要尝试自己调整和摆弄 50 多个参数。
尽管我想忽略英特尔的评论,但我什至无法上传/读取/处理作为 .JSON 文件(C++)提供的预设配置预设。是否有人能够显示一个代码片段,其中.JSON 文件成功用于更改 Realsense D400 系列相机生成的深度图像的高级设置?
解决方案
我发现了如何做到这一点,这里是代码片段,其中包括一些必须放在 Main() 中的额外图像检索代码:
// Obtain a list of devices currently present on the system
context ctx;
auto devices = ctx.query_devices();
size_t device_count = devices.size();
if (!device_count)
{
cout <<"No device detected. Is it plugged in?\n";
return EXIT_SUCCESS;
}
// Get the first connected device
auto dev = devices[0];
// Enter advanced mode
if (dev.is<rs400::advanced_mode>())
{
// Get the advanced mode functionality
auto advanced_mode_dev = dev.as<rs400::advanced_mode>();
// Load and configure .json file to device
ifstream t("./presets/ShortRangePreset.json");
string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
advanced_mode_dev.load_json(str);
}
else
{
cout << "Current device doesn't support advanced-mode!\n";
return EXIT_FAILURE;
}
//Contruct a pipeline which abstracts the device
rs2::pipeline pipe;
rs2::device selected_device = dev;
auto depth_sensor = selected_device.first<rs2::depth_sensor>();
//Create a configuration for configuring the pipeline with a non default profile
rs2::config cfg;
//Add desired streams to configuration
cfg.enable_stream(RS2_STREAM_INFRARED, ImageWidth_px, ImageHeight_px, RS2_FORMAT_Y8, FrameRate);
cfg.enable_stream(RS2_STREAM_DEPTH, ImageWidth_px, ImageHeight_px, RS2_FORMAT_Z16, FrameRate);
//Instruct pipeline to start streaming with the requested configuration
pipe.start(cfg);
// Camera warmup - dropping several first frames to let auto-exposure stabilize
rs2::frameset frames;
for(int i = 0; i < 5; i++)
{
//Wait for all configured streams to produce a frame
frames = pipe.wait_for_frames();
}
bool quit = false;
char key;
while (!quit){
frames = pipe.wait_for_frames();
//Get each frame
rs2::frame ir_frame = frames.first(RS2_STREAM_INFRARED);
rs2::depth_frame depth_frame = frames.get_depth_frame();
// Creating OpenCV matrix from IR image
Mat ir (Size(ImageWidth_px, ImageHeight_px), CV_8UC1, (void*)ir_frame.get_data(), Mat::AUTO_STEP);
Mat depth (Size(ImageWidth_px, ImageHeight_px), CV_16UC1, (void*)depth_frame.get_data(), Mat::AUTO_STEP);
// etc the rest of your code on how you want to edit/process the images
}
推荐阅读
- python - discord.py 如何在 API 请求中用 %20 替换空格
- python - 在 for 循环中将一维数组转换为二维
- python - 如何捕获从某个字符串开始并从某行结束然后存储到列表中的字符串
- arrays - 是否可以实现修改声明为不可分配的数组的子例程?
- mysql - 将 phpmyadmin 转移到另一台电脑而不导出
- docker - 带有 docker-windows 执行器的 Gitlab 运行器正在拉取 linux docker 映像并失败
- vue.js - 无法将值道具传递给自定义输入组件
- asp.net - .net core 3.1 / .net core 2.1 上的 HttpWebRequest BeginRead 问题
- transactions - 如何使用delphi减少数据集PK字段的序列生成器
- c - 将值附加到结构并打印它