graspnet+Astra2相機實現部署

graspnet+Astra2相機實現部署

🚀 環境配置 🚀

  • ubuntu 20.04
  • Astra2相機
  • cuda 11.0.1
  • cudnn v8.9.7
  • python 3.8.19
  • pytorch 1.7.0
  • numpy 1.23.5

1. graspnet的復現

具體的復現流程可以參考這篇文章:Ubuntu20.04下GraspNet復現流程

這里就不再詳細介紹了

2. Astra2的Python API

以下內容都是參考官方文檔:Orbbec SDK for Python 使用手冊

我們首先確認輸入到網絡中的數據為一個點云數據,再一個我們需要一個rgb圖像用來給點云上色,graspnetAPI幫我們寫好了從深度圖轉換到點云的函數create_point_cloud_from_depth_image,所以我們只需要寫好從相機的視頻流獲取深度圖片和rgb圖片的部分就好了,特別注意的是,大多數相機的rgb的fov是要大于深度圖的fov所以我們要對兩者進行對齊操作,對齊操作的本質就是在深度圖中填充0,使得深度圖和rgb圖的大小一致。大多數的相機廠商已經提供了具體的示例來演示如何進行對齊,這里就不再贅述。

這里我直接給出我寫的astra2.py,用于獲取相機的深度圖和rgb圖的代碼,大家可以參考一下思路

astra2.py

from pyorbbecsdk import *
import numpy as np
import cv2
import os
import open3d as o3dclass Camera:def __init__(self, width=1280, height=720,fps=15):self.im_width = widthself.im_height = heightself.fps = fpsself.intrinsic = Noneself.scale = None# 連接相機# self.connect()def connect(self):"""用于連接相機"""self.pipeline = Pipeline()config = Config()# color configprofile_list = self.pipeline.get_stream_profile_list(OBSensorType.COLOR_SENSOR)color_profile = profile_list.get_default_video_stream_profile()config.enable_stream(color_profile)# depth configprofile_list = self.pipeline.get_stream_profile_list(OBSensorType.DEPTH_SENSOR)assert profile_list is not Nonedepth_profile = profile_list.get_default_video_stream_profile()assert depth_profile is not Noneprint("color profile : {}x{}@{}_{}".format(color_profile.get_width(),color_profile.get_height(),color_profile.get_fps(),color_profile.get_format()))print("depth profile : {}x{}@{}_{}".format(depth_profile.get_width(),depth_profile.get_height(),depth_profile.get_fps(),depth_profile.get_format()))config.enable_stream(depth_profile)# set synchronize for depth img and color imgconfig.set_align_mode(OBAlignMode.SW_MODE)self.pipeline.enable_frame_sync()# start configself.pipeline.start(config)# get intrinsicself.intrinsic = self.get_intrinsic()def disconnect(self):"""用于斷開相機"""self.pipeline.stop()def get_frame(self):"""通過流來獲取color frame和depth frame"""while True:frames: FrameSet = self.pipeline.wait_for_frames(200)if frames is None:continuecolor_frame = frames.get_color_frame()if color_frame is None:continuedepth_frame = frames.get_depth_frame()if depth_frame is None:continueif color_frame != None and depth_frame != None:breakreturn color_frame, depth_framedef frame2data(self, color_frame, depth_frame):"""暫時沒用"""width = depth_frame.get_width()height = depth_frame.get_height()scale = depth_frame.get_depth_scale()depth_data = np.frombuffer(depth_frame.get_data(), dtype=np.uint16)depth_data = depth_data.reshape((height, width))width = color_frame.get_width()height = color_frame.get_height()color_data = np.asanyarray(color_frame.get_data(), dtype=np.uint16)# color_data = color_data.reshape((height, width, 3))return color_data.astype(np.float32), depth_data.astype(np.float32)def get_data(self):"""通過流來獲取color data和depth data"""# 連接相機self.connect()color_frame, depth_frame = self.get_frame()width = color_frame.get_width()height = color_frame.get_height()color_format = color_frame.get_format()data = np.asanyarray(color_frame.get_data())color_data = cv2.imdecode(data, cv2.IMREAD_COLOR)color_data.astype(np.float32)print('color_image.shape: ', color_data.shape)# print("===width: {}===".format(width))# print("===height: {}===".format(height))width = depth_frame.get_width()height = depth_frame.get_height()scale = depth_frame.get_depth_scale()print("===width: {}===".format(width))print("===height: {}===".format(height))print("===scale: {}===".format(scale))save_dir = os.path.join(os.getcwd(), "real/intrinsic")if not os.path.exists(save_dir):os.mkdir(save_dir)filename = save_dir + "/camera_depth_scale.txt"save = np.array([scale])np.savetxt(filename, save, delimiter=' ')depth_data = np.frombuffer(depth_frame.get_data(), dtype=np.uint16)depth_data = depth_data.reshape((height, width))depth_data = depth_data.astype(np.float32) * scaleprint('depth_image.shape: ', depth_data.shape)depth_data = cv2.normalize(depth_data, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_16U)# 斷開相機self.disconnect()return color_data, depth_datadef get_data_saved(self):color_data, depth_data = self.get_data()# depth_image = depth_data_normalized.astype(np.uint8)save_image_dir = os.path.join(os.getcwd(), "real/images")if not os.path.exists(save_image_dir):os.mkdir(save_image_dir)depth_filename = save_image_dir + "/depth_{}x{}.png".format(depth_data.shape[0], depth_data.shape[1])color_filename = save_image_dir + "/color_{}x{}.png".format(color_data.shape[0], color_data.shape[1])cv2.imwrite(color_filename, color_data)# depth_data.tofile(depth_filename)cv2.imwrite(depth_filename, depth_data)return color_data, depth_datadef get_intrinsic(self):"""獲取內參"""# get intrinsicitsc = self.pipeline.get_camera_param()raw_intrinsic = itsc.depth_intrinsicintrinsic = np.array([raw_intrinsic.fx, 0, raw_intrinsic.cx, 0, raw_intrinsic.fy, raw_intrinsic.cy,0, 0, 1]).reshape(3,3)print("intrinsic: ", itsc)print('depth intrinsic: ', raw_intrinsic)print("intrinsic matrix", intrinsic)save_dir = os.path.join(os.getcwd(), "real/intrinsic")if not os.path.exists(save_dir):os.mkdir(save_dir)filename = save_dir + "/camera_itcs.txt"np.savetxt(filename, intrinsic, delimiter=' ')return intrinsic# for testdef visualize(self):"""顯示rgbd圖像"""color_data, depth_data = self.get_data()depth_image = cv2.normalize(depth_data, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U)depth_image = cv2.applyColorMap(depth_image, cv2.COLORMAP_JET)# overlay color image on depth imagedepth_image = cv2.addWeighted(color_data, 0.5, depth_image, 0.5, 0)cv2.imshow("Depth with Color", depth_image)cv2.waitKey(500)if __name__ == '__main__':camera = Camera()camera.visualize()color, depth = camera.get_data()print("depth.shape: ", depth.shape)

測試相機是否實現對齊,結果如下

Image

表明了相機確實實現了對齊操作

3. 修改demo.py

我們使用get_data()函數就能夠讓相機進行一次拍攝,然后得到color_datadepth_data供我們進行后續的處理。然后可以修改一下demo.py,將從文件讀取數據改為直接從相機進行讀取

demo.py

...
from astra2 import Camera()
astra2 = Camera()...def get_and_process_data():# 使用相機獲取一次數據color, depth = astra2.get_data()color = color / 255.0...

然后別的部分可以保持不變或者以后再修改。這里一定要使用官方提供的checkpoint-rs.tar,如果使用checkpoint-kn.tar,會出現異常,暫時我也沒有找到原因。

最后處理的效果如下

Image

可以看到出現了許多我們不希望存在的抓取框,這個可以通過調整workspace_mask來進行過濾

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/14107.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/14107.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/14107.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

數據庫系統概論(第5版)復習筆記

筆記的Github倉庫地址 👆這是筆記的gihub倉庫,內容是PDF格式。 因為圖片和代碼塊太多,放到CSDN太麻煩了(比較懶🤣) 如果感覺對各位有幫助的話歡迎點一個?\^o^/

41-4 DDOS攻擊防護實戰

一、UDP FLOOD攻擊 # hping3 -q -n -a <攻擊IP> -S -s <源端口> --keep -p <目的端口> --flood <被攻擊IP> hping3 --udp -s 6666 -p 53 -a 192.168.1.6 --flood 192.168.1.13 這個命令是使用hping3工具進行UDP Flood攻擊的命令。下面是各個選項的作…

three.js能實現啥效果?看過來,這里都是它的菜(06)

這是第五期了&#xff0c;本期繼續分享three.js可以實現的3D動畫案例&#xff0c;有老鐵反饋再發案例的時候&#xff0c;是否可以順道分享一下three.js的知識點&#xff0c;好吧&#xff0c;安排。 材質動畫 材質動畫可以實現各種復雜的視覺效果&#xff0c;包括但不限于以下…

【css】引入背景圖時候,路徑寫入@會報錯

看報錯信息 我的寫法 解決辦法 在前面加個~

js解決數字小數計算出現的精度丟失問題(2024-05-24)

精度丟失的原因 js小數進行數值運算時出現精度丟失問題 JavaScript 的number類型在進行運算時都先將十進制轉二進制&#xff0c;此時&#xff0c;小數點后面的數字轉二進制時會出現無限循環的問題。 為了避免這一個情況&#xff0c;要舍0進1&#xff0c;此時就會導致精度丟失…

企業寬帶跑pcdn會被查嗎?

企業寬帶使用PCDN技術&#xff0c;本身并不違反相關規定&#xff0c;因此一般不會被查。PCDN是一種內容分發網絡技術&#xff0c;通過將內容緩存在離用戶更近的服務器上&#xff0c;減少數據傳輸的延遲&#xff0c;提高訪問速度。這種技術可以提高網頁加載速度和視頻播放流暢度…

Excel未響應時強關后,Excel插件消失

目錄 我們分析一下插件消失的原因&#xff1a; 針對上面表現出來的2個問題&#xff0c;進行針對性的解決 &#xff1a; 1、不被關進去&#xff0c;是不是就沒有后續的一系列的問題了&#xff0c;各自安好 2、保留住自動加載的行為 PS&#xff1a;配置受信任的位置注冊列表…

2024電工杯B題保姆級分析完整思路+代碼+數據教學

2024電工杯B題保姆級分析完整思路代碼數據教學 B題題目&#xff1a;大學生平衡膳食食譜的優化設計及評價 接下來我們將按照題目總體分析-背景分析-各小問分析的形式來 總體分析&#xff1a; 題目要求對兩份一日膳食食譜進行營養分析和調整&#xff0c;然后設計優化的平衡膳…

生成模型 | 從 VAE 到 Diffusion Model (上)

文章目錄 一&#xff0c;GAN(對抗式生成網絡&#xff09;二&#xff0c;Auto-Encoder(AE) 和 Denoising Auto-Encoder (DAE)三&#xff0c;VAE四&#xff0c;VQ-VAE (Vector Quantized Variational Autoencoder)VQ-VAE 2小總結&#xff1a; 五&#xff0c;DALL-E &#xff08;O…

硅谷裸機云服務器性能測評哪些內容

硅谷裸機云服務器&#xff0c;作為云計算領域的一股新興力量&#xff0c;近年來受到了廣泛關注。其強大的性能和靈活性為用戶提供了更高效、更穩定的云計算服務。那么&#xff0c;硅谷裸機云服務器的性能測評究竟包括哪些內容呢?接下來&#xff0c;我們就來科普一下。 首先&am…

如何讓大模型更聰明?

如何讓大模型更聰明&#xff1f; *隨著人工智能技術的飛速發展&#xff0c;大模型在多個領域展現出了前所未有的能力&#xff0c;但它們仍然面臨著理解力、泛化能力和適應性等方面的挑戰。那么&#xff0c;如何讓大模型變得更聰明呢&#xff1f; 方向一&#xff1a;算法創新 …

留學培訓行業PaaS應用系統架構的設計與實踐

隨著留學需求的增長和教育培訓市場的不斷擴大&#xff0c;留學培訓行業正面臨著越來越多的挑戰和機遇。在這個背景下&#xff0c;利用PaaS&#xff08;Platform as a Service&#xff09;平臺來構建留學培訓行業的應用系統架構&#xff0c;將成為提升服務質量和效率的重要手段。…

Nacos 2.x 系列【8】集成 Spring Cloud Gateway

文章目錄 1. 概述1.1 API 網關1.1 Spring Cloud Gateway 2. 集成案例2.1 入門案例2.2 動態路由 1. 概述 1.1 API 網關 API網關已經成為了微服務架構的一個標配組件&#xff0c;是系統對外的唯一入口。所有的客戶端都通過統一的網關接入微服務&#xff0c;在網關層處理所有非業…

部署 harbor 創建私有項目

一在 Docker harbor 節點&#xff08;192.168.11.&#xff09;上操作 1 關閉防火墻防護 systemctl stop firewalld.service systemctl disable firewalld.service setenforce 0 2 安裝docker yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-ma…

SSRF攻擊技術

1、SSRF形成原因 SSRF(Server-Side Request Forgery:服務器端請求偽造) 是一種由攻擊者構造形成由服務端發起請求的一個安全漏洞。一般情況下&#xff0c;SSRF是要目標網站的內部系統。&#xff08;因為他是從內部系統訪問的&#xff0c;所有可以通過它攻擊外網無法訪問的內部系…

思科模擬器--03.RIP協議路由--24.5.17

1.首先&#xff0c;先創建兩個個人電腦:PC0和PC1和三個路由器:R1&#xff0c;R2和R3. (訣竅:建議用文本框標注一下重要簡短的內容; 目的:降低失誤概率,提高成功率!) 第0步:(個人電腦的IP,子網掩碼和默認網關配置) 接著&#xff0c;可以先將個人電腦的IP和網關先配置一下…

ThreadLocal原理及使用

一、引言 在Java多線程編程中&#xff0c;ThreadLocal是一個非常有用的工具&#xff0c;它提供了一種將對象與線程關聯起來的機制&#xff0c;使得每個線程都可以擁有自己獨立的對象副本&#xff0c;從而避免了線程安全問題。然而&#xff0c;使用不當會導致內存泄漏問題。 二…

go 微服務框架kratos錯誤處理的使用方法及原理探究

通過go語言原生http中響應錯誤的實現方法&#xff0c;逐步了解和使用微服務框架 kratos 的錯誤處理方式&#xff0c;以及探究其實現原理。 一、go原生http響應錯誤信息的處理方法 處理方法&#xff1a; ①定義返回錯誤信息的結構體 ErrorResponse // 定義http返回錯誤信息的…

無人機飛手前途分析

無人機飛手的前途充滿了各種可能性和挑戰&#xff0c;這主要得益于無人機技術的快速發展和廣泛應用。以下是對無人機飛手前途的一些分析&#xff1a; 1. 技術發展與需求增長&#xff1a;隨著無人機技術的不斷進步&#xff0c;其應用場景也在持續擴大。從地理測繪、巡檢、農林植…

利用阿里OSS服務給文件設置過期刪除--簡單版

在云存儲廣泛應用的今天&#xff0c;阿里云的Object Storage Service&#xff08;OSS&#xff09;以其高度可擴展性、安全性和成本效益&#xff0c;成為了眾多企業和開發者存儲海量數據的首選方案。隨著數據量的不斷膨脹&#xff0c;高效的數據管理和成本控制變得尤為重要。其中…