日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Intel Realsense d435 使用python对深度图进行预处理

發(fā)布時(shí)間:2025/3/15 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Intel Realsense d435 使用python对深度图进行预处理 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Intel Realsense d435 使用python對(duì)深度圖進(jìn)行預(yù)處理

本文中主要翻譯一下一篇關(guān)于深度圖預(yù)處理過濾器的內(nèi)容,后面還會(huì)有關(guān)于距離測量的。
原文中的圖像顯示,是使用matplotlib.pyplot工具,在本文中,使用opencv來顯示深度圖》
首先常規(guī)操作導(dǎo)入包:

import cv2 import numpy as np import pyrealsense2 as rs

獲取我們所需要的圖像,通過攝像頭或者本地都可以

pipe = rs.pipeline() cfg = rs.config() cfg.enable_stream(rs.stream.depth,640,480,rs.format.z16,30) cfg.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30) profile = pipe.start(cfg)try:while True:frame = pipe.wait_for_frames()depth_frame = frame.get_depth_frame()print('capture success')if cv2.waitKey(10)&0xff == ord('q'):breakfinally:pipe.stop()

獲取成功,在終端打印信息

一、深度圖像的可視化

使用pyrealsense2庫中提供的colorizer來將圖像中的深度值轉(zhuǎn)為可以顯示的形式:

colorizer = rs.colorizer() colorizer_depth = np.asanyarray(colorizer.colorize(depth_frame).get_data()) cv2.imshow('colorizer depth',colorizer_depth)

二、應(yīng)用過濾器

(1)抽取(Decimation)

When using Depth-from-Stereo solution, z-accuracy is related to original spacial resolution.
If you are satisfied with lower spatial resolution, the Decimation Filter will reduce spatial resolution preserving z-accuracy and performing some rudamentary hole-filling.
這段話的意思就是類似與圖像處理中的降采樣,圖像的分辨率會(huì)降低(640x480----->320x240),但會(huì)講一些黑色的空洞進(jìn)行填充。

#二、抽取Decimationcolorizer = rs.colorizer()decimation = rs.decimation_filter()decimationed_depth = decimation.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(decimationed_depth).get_data())cv2.imshow('decimationed depth',colorized_depth)#可以設(shè)置參數(shù)類似于迭代次數(shù)decimation.set_option(rs.option.filter_magnitude,4)decimationed_depth = decimation.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(decimationed_depth).get_data())cv2.imshow('decimationed4 depth',colorized_depth)

(2)空間過濾器(Spatial Filter)

空間濾波器的論文:
Domain Transform for Edge-Aware Image and Video Processing

#三、空間濾波器(spatial filter)colorizer = rs.colorizer()spatial = rs.spatial_filter()filtered_depth = spatial.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())cv2.imshow('filtered depth',colorized_depth)# 可以設(shè)置相關(guān)的參數(shù)spatial.set_option(rs.option.filter_magnitude,5)spatial.set_option(rs.option.filter_smooth_alpha,1)spatial.set_option(rs.option.filter_smooth_delta,50)filtered_depth = spatial.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())cv2.imshow('filtered1 depth',colorized_depth)

同時(shí),spatial也提供了一個(gè)基本的空洞填充操作:

spatial.set_option(rs.option.holes_fill,3)filtered_depth = spatial.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(filtered_depth).get_data())cv2.imshow('fill hole',colorized_depth)

(3)時(shí)間過濾器(Temporal Filter)

Our implementation of Temporal Filter does basic temporal smoothing and hole-filling. It is meaningless when applied to a single frame, so let’s capture several consecutive frames:
我們對(duì)“時(shí)間過濾器”的實(shí)現(xiàn)實(shí)現(xiàn)了基本的時(shí)間平滑和孔填充。 當(dāng)應(yīng)用于單個(gè)幀時(shí)它是沒有意義的,因此讓我們捕獲幾個(gè)連續(xù)的幀:

#四、時(shí)間濾波器(Temporal Filter)colorizer = rs.colorizer()frames.append(depth_frame)i += 1if i == 10:i = 0temporal = rs.temporal_filter()print(len(frames))for x in range(10):temp_filtered = temporal.process(frames[x])frames = []colorized_depth = np.asanyarray(colorizer.colorize(temp_filtered).get_data())cv2.imshow('temporal depth',colorized_depth)

(4)孔填充(Hole Filling)

Hole Filling filter offers additional layer of depth exterpolation:
孔填充過濾器提供了深度外推的附加層:

#五、孔填充(Hole Filling)colorizer = rs.colorizer()hole_filling = rs.hole_filling_filter()filled_depth = hole_filling.process(depth_frame)colorized_depth = np.asanyarray(colorizer.colorize(filled_depth).get_data())cv2.imshow('filled depth',colorized_depth)

(5)放在一起(Putting Everything Together)

These filters work best when applied sequentially one after another. At longer range, it also helps using disparity_transform to switch from depth representation to disparity form:
依次順序應(yīng)用這些過濾器時(shí),效果最佳。 在更大范圍內(nèi),它還有助于使用disparity_transform從深度表示轉(zhuǎn)換為視差形式:

#六、復(fù)合多個(gè)濾波器colorizer = rs.colorizer() depth_to_disparity = rs.disparity_transform(True)disparity_to_depth = rs.disparity_transform(False)decimation = rs.decimation_filter()spatial = rs.spatial_filter()temporal = rs.temporal_filter()hole_filling = rs.hole_filling_filter()frames.append(depth_frame)i += 1if i == 10:i = 0for x in range(10):frame = frames[x]frame = decimation.process(frame)frame = depth_to_disparity.process(frame)frame = spatial.process(frame)frame = temporal.process(frame)frame = disparity_to_depth.process(frame)frame = hole_filling.process(frame)frames = []colorized_depth = np.asanyarray(colorizer.colorize(frame).get_data())cv2.imshow('more depth filter',colorized_depth)

總結(jié)

以上是生活随笔為你收集整理的Intel Realsense d435 使用python对深度图进行预处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。