Python | python调用D435i报错:Failed to resolve the request 及其解决办法

简介

英特尔实感深度摄像机D435i可以同时输出深度图像和RGB图像。

官网上下载了一个D435i的测试文件,编程语言为:python3.7. 输出结果应该为同时显示深度图和RGB图的窗口

但是运行时报错。报错为:RuntimeError: Failed to resolve the request: Format: BGR8, width: 640, height: 480Into:Formats: YUYV

具体情况如下所示。

报错

python测试程序为:

import pyrealsense2 as rs
import numpy as np
import cv2

if __name__ == "__main__":
    # Configure depth and color streams
    pipeline = rs.pipeline()
    config = rs.config()
    config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 15)
    config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 15)
    # Start streaming
    pipeline.start(config)



    try:
        while True:
            # Wait for a coherent pair of frames: depth and color
            frames = pipeline.wait_for_frames()
            depth_frame = frames.get_depth_frame()
            color_frame = frames.get_color_frame()
            if not depth_frame or not color_frame:
                continue
            # Convert images to numpy arrays

            depth_image = np.asanyarray(depth_frame.get_data())

            color_image = np.asanyarray(color_frame.get_data())

            # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
            depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
            # Stack both images horizontally
            images = np.hstack((color_image, depth_colormap))
            # Show images
            cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
            cv2.imshow('RealSense', images)
            key = cv2.waitKey(1)
            # Press esc or 'q' to close the image window
            if key & 0xFF == ord('q') or key == 27:
                cv2.destroyAllWindows()
                break
    finally:
        # Stop streaming
        pipeline.stop()

报错如下:

Traceback (most recent call last):
  File "***/testDeepFigure.py", line 12, in <module>
    pipeline.start(config)
RuntimeError: 
Failed to resolve the request: 
	Format: BGR8, width: 640, height: 480

Into:
	Formats: 
	 YUYV

解决办法

实际上,从网上也搜到了类似的问题,但是我按照网上的指示操作却没有解决该问题。bug仍然存在。

首先需要确定USB数据流接口,D435i相机只能接USB3.0口(从颜色上可以区分USB3.0和USB2.0:USB3.0接口是蓝色的)。

然后,我偶然发现了一个问题:当我的python程序报错的时候,我的Intel Realsense Viewer的窗口,总是在运行D435i相机!

于是,我试着在关闭Viewer界面(关闭Viewer界面的相机即可)后,再次运行python程序,神奇的事情发生了!

程序输出:NOHA :: multistream:::open :: added 1000ms sleep !

并且有相机的拍摄窗口了!

大概如下:
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我之前提供的示例代码有误。在 Katalon Studio 中,我们可以使用 WebUI 类提供的方法来发送 HTTP 请求并保存响应内容到本地文件。以下是修正后的示例代码: ```groovy import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import internal.GlobalVariable import java.nio.file.Files // 设置全局变量 GlobalVariable.ossEndpoint = "YOUR_OSS_ENDPOINT" GlobalVariable.ossAccessKeyId = "YOUR_OSS_ACCESS_KEY_ID" GlobalVariable.ossAccessKeySecret = "YOUR_OSS_ACCESS_KEY_SECRET" GlobalVariable.bucketName = "YOUR_BUCKET_NAME" // 下载文件夹路径 def folderPath = "YOUR_FOLDER_PATH" // 本地保存路径 def localPath = "YOUR_LOCAL_PATH" // 构建下载链接 def downloadUrl = "https://${GlobalVariable.bucketName}.${GlobalVariable.ossEndpoint}/${folderPath}" // 发送 GET 请求并保存响应内容到本地文件 WebUI.downloadFile(downloadUrl, localPath) // 验证文件是否下载成功 if (Files.exists(Paths.get(localPath))) { println("文件已成功下载到本地路径: " + localPath) } else { println("下载文件夹失败!") } ``` 请将示例代码中的 `YOUR_OSS_ENDPOINT`、`YOUR_OSS_ACCESS_KEY_ID`、`YOUR_OSS_ACCESS_KEY_SECRET`、`YOUR_BUCKET_NAME`、`YOUR_FOLDER_PATH` 和 `YOUR_LOCAL_PATH` 替换为您自己的 OSS 相关信息和路径。 这个修正后的示例代码使用 Katalon Studio 内置的 WebUI 类提供的 `downloadFile` 方法来发送 GET 请求并保存响应内容到本地文件。我们还使用了 Java 的 `Files.exists` 方法来验证文件是否成功下载。 非常抱歉给您带来的困扰,希望这次能够正确运行。如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值