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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

D415的使用

發(fā)布時(shí)間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 D415的使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

本文參考

【OpenCV 4】偽色彩 applyColorMap() 函數(shù)使用_kingkee的博客-CSDN博客_applycolormap函數(shù)

利用D415讀取 需要標(biāo)記的人臉face_recognition的距離 Python + wind10_weixin_44576543的博客-CSDN博客

目錄

1.環(huán)境安裝

2.獲取雙目圖像

3.深度圖像的獲取


?

D415是深度圖像的攝像機(jī)

我們使用python進(jìn)行驅(qū)動(dòng)

1.環(huán)境安裝

python版本3.7,下面這些包使用pip都可以安裝上,我是使用conda創(chuàng)建的環(huán)境,可能有的與使用別的環(huán)境不太一樣

2.獲取雙目圖像

我們使用普通彩色圖像與紅外線圖像

import pyrealsense2 as rs import numpy as np import cv2pipeline = rs.pipeline() config = rs.config() config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) config.enable_stream(rs.stream.infrared, 640, 480, rs.format.y8, 30) pipeline.start(config)try:while True:# Wait for a coherent pair of frames: depth and colorframes = pipeline.wait_for_frames()color_frame = frames.get_color_frame()depth_frame = frames.get_infrared_frame()# Convert images to numpy arrays 把圖像轉(zhuǎn)換為numpy datadepth_image = np.asanyarray(depth_frame.get_data())color_image = np.asanyarray(color_frame.get_data())color_image = cv2.cvtColor(color_image,cv2.COLOR_BGR2GRAY)# Stack both images horizontally 把兩個(gè)圖片水平拼在一起images = np.hstack((color_image, depth_image))# Show images 展示一下圖片cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', images)key = cv2.waitKey(1)if key == ord(' '):breakfinally:# Stop streamingpipeline.stop()

運(yùn)行后的效果是這樣的,左側(cè)本來是彩色的圖像,我將其轉(zhuǎn)換為灰度圖像?

紅外線圖像中會(huì)有紋路一樣的東西

?當(dāng)我用手擋住其中彩色的攝像頭,紅外線攝像頭不受影響

3.深度圖像的獲取

我使用了彩色原圖像與深度圖像進(jìn)行對(duì)比,要不然效果不明顯

import pyrealsense2 as rs import numpy as np import cv2pipeline = rs.pipeline() 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 pipeline.start(config)try:while True:# Wait for a coherent pair of frames: depth and colorframes = 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 把圖像轉(zhuǎn)換為numpy datadepth_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)depth_colormap = cv2.blur(depth_colormap,(3,3))# Stack both images horizontally 把兩個(gè)圖片水平拼在一起images = np.hstack((color_image, depth_colormap))# Show images 展示一下圖片cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', images)key = cv2.waitKey(1)if key == ord(' '):break finally:# Stop streamingpipeline.stop()
  • 代碼中的blur濾波不是官方的demo,是我后來加的,加入后感覺上可以識(shí)別到更短的距離?

這里使用到了偽彩色,如果不加入偽彩色的話,圖像是這樣的

偽彩色的用法可以參考?【OpenCV 4】偽色彩 applyColorMap() 函數(shù)使用_風(fēng)語留痕-CSDN博客

深度圖像是兩個(gè)攝像頭的綜合結(jié)果,擋上兩個(gè)中的一個(gè)攝像頭,深度圖像就會(huì)消失

總結(jié)

以上是生活随笔為你收集整理的D415的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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