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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

intel realsense保存16位深度图与rgb图程序

發布時間:2024/3/26 编程问答 89 豆豆
生活随笔 收集整理的這篇文章主要介紹了 intel realsense保存16位深度图与rgb图程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IntelRealsense庫安裝

pip install pyrealsense2

代碼解釋

import pyrealsense2 as rs import numpy as np import cv2 import json import png # 開啟攝像頭通信管道 pipeline = rs.pipeline() # 獲取配置 config = rs.config() # 設置深度圖為16位,fps為30,尺寸640x480 config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) # 設置RGB圖為bgr格式(每個通道8位共24位),fps為30,尺寸640x480 config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) # 開啟通道 profile = pipeline.start(config) # 獲取顏色對齊 align_to = rs.stream.color align = rs.align(align_to) depth_intrin = None# 該函數作用是獲取對齊后的圖像(rgb和深度圖對齊) def get_aligned_images():# 獲取一幀圖像frames = pipeline.wait_for_frames()# 將圖像對齊aligned_frames = align.process(frames)# 獲取對齊后的深度圖aligned_depth_frame = aligned_frames.get_depth_frame()# 深度相關參數# depth_intrin = aligned_depth_frame.profile.as_video_stream_profile().intrinsicscolor_frame = aligned_frames.get_color_frame()intr = color_frame.profile.as_video_stream_profile().intrinsicscamera_parameters = {'fx': intr.fx, 'fy': intr.fy,'ppx': intr.ppx, 'ppy': intr.ppy,'height': intr.height, 'width': intr.width,'depth_scale': profile.get_device().first_depth_sensor().get_depth_scale()}with open('./intrinsics.json', 'w') as fp:json.dump(camera_parameters, fp)# 獲取16位深度圖depth_image = np.asanyarray(aligned_depth_frame.get_data())# 轉為8位深度圖# 2^8為256,2^16為65536, 2^8/2^16約等于0.004,alpha=0.004,cv2.convertScaleAbs作用是所有像素點的值乘以alphadepth_image_8bit = cv2.convertScaleAbs(depth_image, alpha=0.004)pos=np.where(depth_image_8bit==0)depth_image_8bit[pos]=255# 獲取彩色圖color_image = np.asanyarray(color_frame.get_data())# 獲取到圖像中心的距離d = aligned_depth_frame.get_distance(320, 240)return color_image, depth_image,if __name__ == "__main__":n=0while 1:# 獲取rgb和深度圖rgb, depth = get_aligned_images()cv2.imshow('RGB image',rgb)key = cv2.waitKey(1)if key & 0xFF == ord('q') or key == 27:pipeline.stop()breakelif key==ord('s'):n=n+1# 保存rgb圖cv2.imwrite('./bd/rgb' + str(n)+'.jpg',rgb)# 保存16位深度圖with open('./bd/rgb' + str(n) + "_d.jpg", 'wb') as f:writer = png.Writer(width=depth.shape[1], height=depth.shape[0],bitdepth=16, greyscale=True)zgray2list = depth.tolist()writer.write(f, zgray2list)cv2.destroyAllWindows()

總結

以上是生活随笔為你收集整理的intel realsense保存16位深度图与rgb图程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。