首页 > 其他分享 >test

test

时间:2023-06-18 23:12:49浏览次数:25  
标签:intrinsics color frame depth test cv rs2

#include <librealsense2/rs.hpp>
#include <opencv2/opencv.hpp>
#include <thread>

void capture_thread(rs2::pipeline pipe, rs2::frame_queue& queue) {
while (true) {
rs2::frameset frameset = pipe.wait_for_frames();
queue.enqueue(frameset);
}
}

void process_thread(rs2_intrinsics color_intrinsics, rs2_intrinsics depth_intrinsics, rs2::frame_queue& queue) {
cv::namedWindow("color", cv::WINDOW_NORMAL);
cv::resizeWindow("color", color_intrinsics.width, color_intrinsics.height);
cv::namedWindow("depth", cv::WINDOW_NORMAL);
cv::resizeWindow("depth", depth_intrinsics.width, depth_intrinsics.height);

while (cv::getWindowProperty("color", cv::WND_PROP_AUTOSIZE) >= 0 && cv::getWindowProperty("depth", cv::WND_PROP_AUTOSIZE) >= 0) {
rs2::frameset frameset;
if (queue.poll_for_frame(&frameset)) {
rs2::frame color_frame = frameset.get_color_frame();
rs2::frame depth_frame = frameset.get_depth_frame();
cv::Mat color_image(cv::Size(color_intrinsics.width, color_intrinsics.height), CV_8UC3, (void*)color_frame.get_data(), cv::Mat::AUTO_STEP);
cv::Mat depth_image(cv::Size(depth_intrinsics.width, depth_intrinsics.height), CV_16UC1, (void*)depth_frame.get_data(), cv::Mat::AUTO_STEP);

// 在这里对每一帧图像进行处理
cv::Mat processed_color_image;
cv::cvtColor(color_image, processed_color_image, cv::COLOR_BGR2GRAY);
cv::Mat processed_depth_image = depth_image * 10;

// 显示处理后的图像
cv::imshow("color", processed_color_image);
cv::imshow("depth", processed_depth_image);
}

cv::waitKey(1);
}
}

int main() {
// 初始化 SDK
rs2::context ctx;

// 连接设备
rs2::device_list devices = ctx.query_devices();
if (devices.size() == 0) {
std::cerr << "Error: no device detected" << std::endl;
return 1;
}
rs2::device device = devices[0];

// 配置流
rs2::config cfg;
cfg.enable_stream(rs2_stream::RS2_STREAM_COLOR, 640, 480, rs2_format::RS2_FORMAT_BGR8, 30);
cfg.enable_stream(rs2_stream::RS2_STREAM_DEPTH, 640, 480, rs2_format::RS2_FORMAT_Z16, 30);

// 开始流
rs2::pipeline pipe;
rs2::pipeline_profile profile = pipe.start(cfg);

// 获取相机内参
rs2::video_stream_profile color_profile = profile.get_stream(rs2_stream::RS2_STREAM_COLOR).as<rs2::video_stream_profile>();
rs2_intrinsics color_intrinsics = color_profile.get_intrinsics();
rs2::video_stream_profile depth_profile = profile.get_stream(rs2_stream::RS2_STREAM_DEPTH).as<rs2::video_stream_profile>();
rs2_intrinsics depth_intrinsics = depth_profile.get_intrinsics();

// 创建队列并启动线程
rs2::frame_queue queue;
std::thread capture_thread_obj(capture_thread, pipe, std::ref(queue));
std::thread process_thread_obj(process_thread, color_intrinsics, depth_intrinsics, std::ref(queue));

// 等待线程结束
capture_thread_obj.join();
process_thread_obj.join();

// 停止流
pipe.stop();

return 0;
}

标签:intrinsics,color,frame,depth,test,cv,rs2
From: https://www.cnblogs.com/CharlieKing/p/17489965.html

相关文章

  • AtCoder Beginner Contest 220 H Security Camera
    洛谷传送门AtCoder传送门看到数据范围猜复杂度是\(O(\text{poly}(n)2^{\frac{n}{2}})\),所以考虑折半。至少有一个端点被选不好算,考虑转成两个端点都被选,但是边数奇偶性与\(m\)相同。称编号\(<\frac{n}{2}\)的点为左点,编号\(\ge\frac{n}{2}\)的点为右点(点编号从\(0......
  • AtCoder Beginner Contest 306 题解 A - E
    A-Echo题目大意给定一个字符串,需要把它每个字符重复输出。解题思路可以读完整个字符串,也可以按照字符读一个输出两个。ACCode#include<iostream>#include<algorithm>#include<cstring>#include<numeric>#defineendl'\n'#defineiosios::sync_with_stdio(fals......
  • test1
    技术栈选用1.前端技术栈1.Vue.js2.ElementUI3.axios2.后端技术栈1.SpringBoot2.ApacheShiro3.ApacheLog4j24.SpringDataJPA5.SpringDataRedis3.数据库1.MySQL2.Redis登录页面开发注意我们的项目是前后端分离的前后端分离的意思是前后端之间通过RESTfulAP......
  • ReadWriteStruct
    #include<stdio.h>#include<stdlib.h>#include<string.h>typedefstructnode{intx;//4:0~3[4567]doubley;//8:8~15charch;//1:16~[...]}Node;//24intmain(void){Nodefirst;Nodesecond......
  • AtCoder Beginner Contest 306 G Return to 1
    洛谷传送门AtCoder传送门考虑若干个能被\(1\)到达且能到达\(1\)的环,设它们的环长分别为\(a_1,a_2,...,a_k\)。那么我们现在要每个环走若干遍,使得步数不含除\(2\)或\(5\)以外的质因子。设第\(i\)个环走\(x_i\)遍,那么其实就是要求\(\sum\limits_{i=1}^ka_i......
  • pytest + yaml 框架 -37.mark 标记对用例运行时长断言
    前言pytest执行用例的时候,我们希望对用例的运行时间断言,当用例执行时长大于预期标记此用例失败。@pytest.mark.runtime(1)运行时长单位是秒此插件已打包上传到pypihttps://pypi.org/project/pytest-runtime-yoyo/1.0.0/环境准备pipinstallpytest-yaml-yoyo此功能在v1.3.1版......
  • pytest + yaml 框架 -38.企业微信机器人通知
    前言v1.3.2版本支持企业微信机器人发送报告通知了。pipinstallpytest-yaml-yoyo获取企业微信机器人token企业机器人相关接口可以看官方文档https://developer.work.weixin.qq.com/document/path/91770创建群聊机器人获取到webhook访问地址https://qyapi.weixin.qq.com/cgi-bin/......
  • AtCoder Beginner Contest 306
    A-Echo(abc306a)题目大意给定一个字符串,将每个字符输出两次。解题思路模拟即可。神奇的代码#include<bits/stdc++.h>usingnamespacestd;usingLL=longlong;intmain(void){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intn;......
  • python unitest 测试装置(Test Fixture)
    unittest框架提供了测试装置(TestFixture)的功能,用于在测试用例执行前后进行准备和清理操作。测试装置包括setUp()方法和tearDown()方法,分别用于在每个测试用例执行前和执行后进行相应的操作。下面是一个示例,演示如何使用测试装置:importunittestclassMyTestCase(unittest.Te......
  • python unitest 测试运行器(Test Runner)
    测试运行器(TestRunner)是unittest框架提供的执行测试用例的组件,用于自动运行测试用例并生成测试结果报告。它负责加载测试用例、执行测试用例,并提供测试结果的输出。unittest框架提供了多种测试运行器,包括TextTestRunner、HTMLTestRunner、XMLTestRunner等。这些运行器可以根据不......