体感学习笔记(一)——关于opencv 如何提取realsense的数据并显示(librealsense2)

本文介绍如何使用RealSense摄像头并借助librealsense和OpenCV库捕获并显示彩色图像。通过设置摄像头参数,如分辨率和帧率,实现稳定的图像流传输。代码示例展示了如何初始化摄像头、获取图像帧及利用OpenCV进行图像展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// include the librealsense C++ header file
#include <librealsense2/rs.hpp>

// include OpenCV header file
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    //Contruct a pipeline which abstracts the device
    rs2::pipeline pipe;//创建一个通信管道//https://baike.so.com/doc/1559953-1649001.html pipeline的解释
    //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_COLOR, 640, 480, RS2_FORMAT_BGR8, 30);//向配置添加所需的流
    //彩色图片:分辨率640*480 8位bgr格式 每秒30帧
    //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 < 30; i++)
    {
        //Wait for all configured streams to produce a frame
        frames = pipe.wait_for_frames();//等待所有配置的流生成框架
    }

    //Get each frame
    rs2::frame color_frame = frames.get_color_frame();

    // Creating OpenCV Matrix from a color image
    Mat color(Size(640, 480), CV_8UC3, (void*)color_frame.get_data(), Mat::AUTO_STEP);
    //创建一个mat类,大小,格式,数据地址(其实。。。。不知道到底是啥,后期再补充),步长
    // Display in a GUI
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", color);

    waitKey(0);

    return 0;
}

刚拿到realsense,配置还是很好配置的,但是怎么输出一直是个问题,主要是做一个笔记

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值