完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好
我不确定问题是来自英特尔Realsense库还是来自OpenCV: 我有一个简单的程序,只是从英特尔Realsense D435获取RGB图像,使用OpenCV函数cvtColor将图像转换为BGR,并使用OpenCVs imshow显示它。 这一直有效,直到我同时激活英特尔Realsense D435的深度相机和RGB相机。 然后我得到一些帧似乎是OpenCV没有完成RGB图像的转换。 所以红色显示为蓝色,反之亦然。 这种情况不规则地发生。 我基于github上的OpenCV imshow示例编写代码。 我使用的是最新的OpenCV版本3.4.3和Intel Realsense SDK 2.0版本2.16.0。 我还在answers.opencv.org上发布了这个问题,因为如果这是英特尔Realsense或OpenCV的问题,我不会感到害羞。 这是我的代码: #include librealsense2 / rs.hpp> //包括RealSense跨平台API #include opencv2 / opencv.hpp> //包含OpenCV APIint main(int argc,char * argv [])try {//声明RealSense管道,封装实际 设备和传感器rs2 ::管道管道; rs2 :: config cfg; //深度流配置cfg.enable_stream(RS2_STREAM_DEPTH,1280,720,RS2_FORMAT_Z16,30); // color stream config cfg.enable_stream(RS2_STREAM_COLOR,1280,720,RS2_FORMAT_RGB8,30); //开始流式传输pipe.start(cfg); const auto window_name =“显示图像”; cv :: namedWindow(window_name,cv :: WINDOW_AUTOSIZE); while(cv :: waitKey(1)0&amp;&amp; cvGetWindowHandle(window_name)){rs2 :: frameset data = pipe.wait_for_frames(); //等待相机的下一组帧rs2 :: frame color = data.get_color_frame(); //查询帧大小(宽度和高度)const int w = colour.asrs2 :: video_frame>()。get_width(); const int h = colour.asrs2 :: video_frame>()。get_height(); //从着色深度数据cv :: Mat image(cv :: Size(w,h),CV_8UC3,(void *)colour.get_data(),cv :: Mat创建大小为(w,h)的OpenCV矩阵: :AUTO_STEP); //从RGB转换为BGR cv :: cvtColor(image,image,cv :: COLOR_RGB2BGR); //使用新数据imshow更新窗口(window_name,image); } return EXIT_SUCCESS;} catch(const rs2 :: error&amp; e){std :: cerr“RealSense错误调用”e.get_failed_function()“(”e.get_failed_args()“): n”e.what() 的std :: ENDL; return EXIT_FAILURE;} catch(const std :: exception&amp; e){std :: cerr e.what()std :: endl; 返回EXIT_FAILURE;} 以上来自于谷歌翻译 以下为原文 Hello I'm not sure if the problem comes from the Intel Realsense library or from OpenCV: I have a simple program that just gets a RGB image from the Intel Realsense D435, converts the image to BGR with the OpenCV function cvtColor and shows it with OpenCVs imshow. This works until I activate the depth camera and the RGB camera of the Intel Realsense D435 at the same time. Then I get some frames where it seems like the conversion of the RGB image was not done by OpenCV. So red appears blue and vice versa. This happens in irregular intervals. I based the code on the OpenCV imshow example from github. I'm using the newest OpenCV version 3.4.3 and Intel Realsense SDK 2.0 version 2.16.0. I also posted this question on answers.opencv.org because I'm not shure if this is a problem with Intel Realsense or OpenCV. Here is my code: #include #include int main(int argc, char * argv[]) try { // Declare RealSense pipeline, encapsulating the actual device and sensors rs2::pipeline pipe; rs2::config cfg; //depth stream config cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30); //colour stream config cfg.enable_stream(RS2_STREAM_COLOR, 1280, 720, RS2_FORMAT_RGB8, 30); // Start streaming pipe.start(cfg); const auto window_name = "Display Image"; cv::namedWindow(window_name, cv::WINDOW_AUTOSIZE); while (cv::waitKey(1) < 0 && cvGetWindowHandle(window_name)) { rs2::frameset data = pipe.wait_for_frames(); // Wait for next set of frames from the camera rs2::frame colour = data.get_color_frame(); // Query frame size (width and height) const int w = colour.as const int h = colour.as // Create OpenCV matrix of size (w,h) from the colorized depth data cv::Mat image(cv::Size(w, h), CV_8UC3, (void*)colour.get_data(), cv::Mat::AUTO_STEP); //convert from RGB to BGR cv::cvtColor(image, image, cv::COLOR_RGB2BGR); // Update the window with new data imshow(window_name, image); } return EXIT_SUCCESS; } catch (const rs2::error & e) { std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):n " << e.what() << std::endl; return EXIT_FAILURE; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; } |
|
相关推荐
1个回答
|
|
HelloHonk5000,感谢您对英特尔实感D435相机的兴趣。我们注意到的问题是源Mat和目标Mat是相同的cv :: cvtColor(image,image,cv :: COLOR_RGB2BGR);更改代码如下
它会工作: cv :: Mat image(cv :: Size(w,h),CV_8UC3,(void *)colour.get_data(),cv :: Mat :: AUTO_STEP); cv :: Mat dst; //添加了这个 //从RGB转换为BGR cv :: cvtColor(image,dst,cv :: COLOR_RGB2BGR); //将目标矩阵更改为dst //使用新数据更新窗口 imshow(window_name,dst); //显示新的目标matrixBest问候,Eliza 以上来自于谷歌翻译 以下为原文 Hello Honk5000, Thank you for your interest in the Intel RealSense D435 camera. The problem we have noticed is that the source Mat and the destination Mat are the same cv::cvtColor(image, image, cv::COLOR_RGB2BGR); Change the code as below and it will work: cv::Mat image(cv::Size(w, h), CV_8UC3, (void*)colour.get_data(), cv::Mat::AUTO_STEP); cv::Mat dst; //added this //convert from RGB to BGR cv::cvtColor(image, dst, cv::COLOR_RGB2BGR); //changed destination matrix to dst // Update the window with new data imshow(window_name, dst); //show the new destination matrix Best regards, Eliza |
|
|
|
只有小组成员才能发言,加入小组>>
448浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-10 16:22 , Processed in 0.383633 second(s), Total 45, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号