realsense D455读取深度图时,深度值不变问题解决方案

使用python代码读取深度相机D455时,保存每一帧的深度信息,结果使用时发现除了前两帧以外,后面所有的深度图都完全一样,同样的代码分别3个场景做实验:

一、深度相机+树莓派(Ubuntu系统)

二、深度相机+树莓派(Ubuntu系统)

三、深度相机+PC机(win10系统)

上述三个场景使用同样的代码,后面两种情况都正常,只有第一种会出现这种问题。

经过调试,将相机读取的fps从30设置为15,问题消失,保存数据正常。读取基本代码如下:

def get_image():
    # Configure depth and color streams
    pipeline = rs.pipeline()
    config = rs.config()
    # ctx = rs.context()
    # ds5_serial = '*****'
    # ds5_serial = ctx.devices[1].get_info(rs.camera_info.serial_number)
    # print('启动的摄像头序列号:{}'.format(ds5_serial))
    # config.enable_device(ds5_serial)
    config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 15)
    config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 15)
    # Start streaming
    pipeline.start(config)
    # 获取颜色对齐
    align_to = rs.stream.color
    align = rs.align(align_to)
    save_path = './data_psk'
    if not os.path.isdir(save_path):
        os.makedirs(save_path)
    n = 0
    count = 0
    while 1:
        frames = pipeline.wait_for_frames()
        # 将图像对齐
        aligned_frames = align.process(frames)
        # 获取对齐后的深度图
        aligned_depth_frame = aligned_frames.get_depth_frame()
        color_frame = aligned_frames.get_color_frame()
        # 获取16位深度图
        depth_image = np.asanyarray(aligned_depth_frame.get_data())
        # 获取彩色图
        color_image = np.asanyarray(color_frame.get_data())

        if count % 10 == 0:
            # 保存rgb图
            cv2.imwrite(os.path.join(save_path, 'rgb_' + str(n).zfill(6) + '.jpg'), color_image)
            # 保存16位深度图
            np.save(os.path.join(save_path, 'rgb_' + str(n).zfill(6)), depth_image)
            print(os.path.join(save_path, 'rgb_' + str(n).zfill(6) + '.jpg'))
            n = n + 1
        if n > 1000:
            break
        count += 1
    print("done!")
可能是树莓派性能有限,造成深度计算拥堵造成的,后面还需修改读取图像大小来做对比试验,保证相机在边缘端稳定运行。
PS:fps设置过小(如设置为10),相机不能正常读取。
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
OpenCV是一个开源的计算机视觉库,可以用于处理图像和视频数据,包括读取和写入图像数据。 realsense d435i是英特尔推出的一款深度相机,可以获取深度信息和RGB图像。 要读取realsense d435i的RGB图像,可以使用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循环中读取每一帧图像并显示它们。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Boris_LB

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值