Intel realsense摄像头捕获的RGB图像为黑色(使用python代码)
我正在使用下面的python代码使用Intel realsense(D 435i)摄像头拍摄RGB图像。python代码捕获的图像是黑色的。但是,当我使用相机的SDK时,图像并不暗。如何拍摄与相机SDK拍摄的图像质量相同的图像 提前谢谢你的帮助Intel realsense摄像头捕获的RGB图像为黑色(使用python代码),python,rgb,intel,realsense,Python,Rgb,Intel,Realsense,我正在使用下面的python代码使用Intel realsense(D 435i)摄像头拍摄RGB图像。python代码捕获的图像是黑色的。但是,当我使用相机的SDK时,图像并不暗。如何拍摄与相机SDK拍摄的图像质量相同的图像 提前谢谢你的帮助 import pyrealsense2 as rs import numpy as np import cv2 import time import math pipeline = rs.pipeline() config = rs.config()
import pyrealsense2 as rs
import numpy as np
import cv2
import time
import math
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)
profile = pipeline.start(config)
depth_sensor = profile.get_device().first_depth_sensor()
depth_scale = depth_sensor.get_depth_scale()
# We will be removing the background of objects more than
# clipping_distance_in_meters meters away
clipping_distance_in_meters = 1.5
clipping_distance = clipping_distance_in_meters / depth_scale
align_to = rs.stream.color
align = rs.align(align_to)
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()
depth_image = np.asanyarray(aligned_depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
# Remove background - Set pixels further than clipping_distance to grey
grey_color = 153
depth_image_3d = np.dstack((depth_image,depth_image,depth_image)) #depth image is 1 channel, color is 3 channels
bg_removed = np.where((depth_image_3d > clipping_distance) | (depth_image_3d <= 0), grey_color, color_image)
# Render images
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
images = np.hstack((bg_removed, depth_colormap))
cv2.namedWindow('Align Example', cv2.WINDOW_AUTOSIZE)
# Filename
path = 'C:/Users/aatefi2/Desktop/Intel real sense/Codes/'
imageName1 = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '_Color.jpg'
imageName2 = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '_Depth.jpg'
imageName3 = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '_bg_removed.jpg'
imageName4 = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '_ColorDepth.jpg'
imageName5 = str(time.strftime("%Y_%m_%d_%H_%M_%S")) + '_DepthColormap.jpg'
# Saving the image
cv2.imwrite(imageName1, color_image)
cv2.imwrite(imageName2, depth_image)
cv2.imwrite(imageName3, images)
cv2.imwrite(imageName4, bg_removed )
cv2.imwrite(imageName5, depth_colormap )
key = cv2.waitKey(1)
# Press esc or 'q' to close the image window
cv2.destroyAllWindows()
pipeline.stop()
将pyrealsense2作为rs导入
将numpy作为np导入
进口cv2
导入时间
输入数学
管道=rs.管道()
config=rs.config()
配置启用_流(rs.stream.depth,1280720,rs.format.z16,30)
配置启用_流(rs.stream.color,1280720,rs.format.bgr8,30)
profile=pipeline.start(配置)
深度传感器=配置文件。获取设备()。第一个深度传感器()
深度刻度=深度刻度传感器。获取深度刻度()
#我们将删除对象的背景超过
#以米为单位剪裁距离
剪裁距离(单位:米)=1.5
剪裁距离=剪裁距离,单位为米/深度比例
对齐到=rs.stream.color
align=rs.align(对齐到)
frames=管道。等待\u帧()
对齐的\u帧=对齐。处理(帧)
对齐的\深度\帧=对齐的\帧。获取\深度\帧()
颜色框架=对齐的框架。获取颜色框架()
depth\u image=np.asanyarray(对齐的\u depth\u frame.get\u data())
color\u image=np.asanyarray(color\u frame.get\u data())
#移除背景-将像素设置为比剪裁距离更远的灰色
灰色=153
depth_image_3d=np.dstack((depth_image,depth_image,depth_image))#深度图像为1个通道,颜色为3个通道
bg_removed=np。其中((深度图像三维>剪裁距离)|(深度图像三维我添加了下面的代码以手动更改曝光时间()。图像(通过此手动设置捕获)比通过自动曝光设置捕获的图像更亮
# The code to set exposure time manually#
profile = pipeline.start(config)
# Get the sensor once at the beginning. (Sensor index: 1)
sensor = pipeline.get_active_profile().get_device().query_sensors()[1]
# Set the exposure anytime during the operation
sensor.set_option(rs.option.exposure, 156.000)