简介
英特尔实感深度摄像机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 !
并且有相机的拍摄窗口了!
大概如下: