realsense d435i获取与rgb图像对应的深度值

设置 realsense-ros 的rs_camera.launch文件

<arg name="align_depth"               default="true"/>

就能得到与图像对应的深度图;
比如rgb对应的深度图会在一个独立的ros topic中输出
具体查看方法

rostopic echo /camera/aligned_depth_to_color/image_raw
void DepthCallback(const sensor_msgs::ImageConstPtr& depth_img) {
  ROS_WARN("%s", depth_img->encoding.c_str());
  cv::Mat data;

  data =
      cv_bridge::toCvCopy(depth_img, sensor_msgs::image_encodings::TYPE_32FC1)
          ->image;
  std::cout << "image data: " << data.at<uint16_t>(240, 320) << std::endl;//表示获取图像坐标为240,320的深度值,单位是毫米
}

int main(int argc, char** argv) {
  ros::init(argc, argv, "test_depth");
  ros::NodeHandle node;
  ros::Subscriber depth_sub;
  depth_sub = node.subscribe<sensor_msgs::Image>(
      "/camera/aligned_depth_to_color/image_raw", 10, DepthCallback);
  ros::spin();
  return 0;
}
OpenCV是一个开源的计算机视觉库,可以用于处理图像和视频数据,包括读取和写入图像数据。 realsense d435i是英特尔推出的一款深度相机,可以获取深度信息和RGB图像。 要读取realsense d435iRGB图像,可以使用OpenCV中的cv::VideoCapture类来实现。首先,需要安装realsense SDK并配置环境,然后在代码中初始化VideoCapture对象,并设置参数。 下面是一个简单的示例代码: ``` #include <opencv2/opencv.hpp> #include <librealsense2/rs.hpp> using namespace cv; using namespace rs2; int main(int argc, char* argv[]) { // Declare RealSense pipeline, encapsulating the actual device and sensors pipeline pipe; // Start streaming with default configuration pipe.start(); // Create a VideoCapture object to read from the RealSense camera VideoCapture cap(pipe); // Check if camera opened successfully if (!cap.isOpened()) { std::cout << "Error opening video stream or file" << std::endl; return -1; } // Read and display frames from camera while (1) { Mat frame; // Capture frame-by-frame cap >> frame; // If the frame is empty, break immediately if (frame.empty()) break; // Display the resulting frame imshow("RGB Image", frame); // Press Esc on keyboard to exit if (waitKey(1) == 27) break; } // When everything done, release the video capture object cap.release(); // Closes all the frames destroyAllWindows(); return 0; } ``` 这个程序中,我们首先声明一个RealSense pipeline对象pipe,然后启动流水线。接着我们创建一个VideoCapture对象cap,并将pipe传递给它以读取RGB图像。最后,在while循环中读取每一帧图像并显示它们。
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值