Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何对齐已捕获的RGB图像和深度图像_Python 3.x_Image Processing_Kinect V2_Image Registration_Color Depth - Fatal编程技术网

Python 3.x 如何对齐已捕获的RGB图像和深度图像

Python 3.x 如何对齐已捕获的RGB图像和深度图像,python-3.x,image-processing,kinect-v2,image-registration,color-depth,Python 3.x,Image Processing,Kinect V2,Image Registration,Color Depth,我有一些由Microsoft Kinect v2拍摄的RGB和深度图像。我想对齐RGB和深度图像(图像注册)。在浏览了一段时间的互联网后,我在这里找到了下面的python代码,它将RGB图像和深度图像对齐,但是来自一个实时摄像机这里有人解决了对齐已捕获的RGB和深度图像的问题吗?非常感谢您的帮助,谢谢 ## License: Apache 2.0. See LICENSE file in root directory. ## Copyright(c) 2017 Intel Corporation

我有一些由Microsoft Kinect v2拍摄的RGB和深度图像。我想对齐RGB和深度图像(图像注册)。在浏览了一段时间的互联网后,我在这里找到了下面的python代码,它将RGB图像和深度图像对齐,但是来自一个实时摄像机这里有人解决了对齐已捕获的RGB和深度图像的问题吗?非常感谢您的帮助,谢谢

## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#####################################################
##              Align Depth to Color               ##
#####################################################

# First import the library
import pyrealsense2 as rs
# Import Numpy for easy array manipulation
import numpy as np
# Import OpenCV for easy image rendering
import cv2

# Create a pipeline
pipeline = rs.pipeline()

#Create a config and configure the pipeline to stream
#  different resolutions of color and depth streams
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
profile = pipeline.start(config)

# Getting the depth sensor's depth scale (see rs-align example for explanation)
depth_sensor = profile.get_device().first_depth_sensor()
depth_scale = depth_sensor.get_depth_scale()
print("Depth Scale is: " , depth_scale)

# We will be removing the background of objects more than
#  clipping_distance_in_meters meters away
clipping_distance_in_meters = 1 #1 meter
clipping_distance = clipping_distance_in_meters / depth_scale

# Create an align object
# rs.align allows us to perform alignment of depth frames to others frames
# The "align_to" is the stream type to which we plan to align depth frames.
align_to = rs.stream.color
align = rs.align(align_to)

# Streaming loop
try:
    while True:
        # Get frameset of color and depth
        frames = pipeline.wait_for_frames()
        # frames.get_depth_frame() is a 640x360 depth image

        # Align the depth frame to color frame
        aligned_frames = align.process(frames)

        # Get aligned frames
        aligned_depth_frame = aligned_frames.get_depth_frame() # aligned_depth_frame is a 640x480 depth image
        color_frame = aligned_frames.get_color_frame()

        # Validate that both frames are valid
        if not aligned_depth_frame or not color_frame:
            continue

        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)
        cv2.imshow('Align Example', 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:
    pipeline.stop()
##许可证:Apache 2.0。请参阅根目录中的许可证文件。
##版权所有(c)2017英特尔公司。版权所有。
#####################################################
##将深度与颜色对齐##
#####################################################
#首先导入库
将pyrealsense2作为rs导入
#导入Numpy以便于阵列操作
将numpy作为np导入
#导入OpenCV以便于图像渲染
进口cv2
#创建管道
管道=rs.管道()
#创建配置并将管道配置为流
#颜色和深度流的不同分辨率
config=rs.config()
配置启用_流(rs.stream.depth,640480,rs.format.z16,30)
配置启用_流(rs.stream.color,640480,rs.format.bgr8,30)
#开始流媒体
profile=pipeline.start(配置)
#获取深度传感器的深度刻度(有关说明,请参见rs align示例)
深度传感器=配置文件。获取设备()。第一个深度传感器()
深度刻度=深度刻度传感器。获取深度刻度()
打印(“深度刻度为:”,深度刻度)
#我们将删除对象的背景超过
#以米为单位剪裁距离
剪裁距离(单位:米)=1米
剪裁距离=剪裁距离,单位为米/深度比例
#创建对齐对象
#rs.align允许我们将深度帧与其他帧对齐
#“align_to”是我们计划与深度帧对齐的流类型。
对齐到=rs.stream.color
align=rs.align(对齐到)
#流循环
尝试:
尽管如此:
#获取颜色和深度的框架集
frames=管道。等待\u帧()
#frames.get_depth_frame()是一个640x360深度的图像
#将深度框与颜色框对齐
对齐的\u帧=对齐。处理(帧)
#对齐帧
aligned_depth_frame=aligned_frames.获取_depth_frames()#aligned_depth_frames是一个640x480深度的图像
颜色框架=对齐的框架。获取颜色框架()
#验证两个帧是否有效
如果未对齐\u深度\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.其中((深度图像三维>剪裁距离)|(depth_image_3d通常,此问题需要K_rgb、K_depth、描述rgb和深度之间关系的外部变量。在OpenCV contrib库中,您有用于此目的的函数registerDepth。通常,此问题需要K_rgb、K_depth、描述rgb和深度之间关系的外部变量。在OpenCV contrib库中,您可以为此,请删除函数registerDepth。