引言
今天我們主要了解3D攝像頭是如何跟機(jī)械臂應(yīng)用相結(jié)合的。我們最近準(zhǔn)備推出一款新的機(jī)械臂套裝AI Kit 2023 3D,熟悉我們的老用戶應(yīng)該知道,我們之前的AI Kit 2023套裝使用的是2D攝像頭。
隨著技術(shù)進(jìn)步,市場(chǎng)需求和領(lǐng)域的擴(kuò)大,2D的攝像頭已經(jīng)不能夠滿足很多場(chǎng)景。3D攝像頭也在近些年間火了起來。隨著我們的步伐,一起來認(rèn)識(shí)一下3D攝像頭帶給我們的應(yīng)用。
產(chǎn)品介紹
RealSence-Depth camera
我們今天涉及到的3D攝像頭是RealSence是Intel公司開發(fā)的一種深度感知攝像頭。可以從圖片中看出來,這個(gè)相機(jī)有四個(gè)鏡頭,它們分別是一個(gè)紅外激光投影儀,兩個(gè)紅外攝像頭和一個(gè)彩色攝像頭。這幾個(gè)鏡頭具體有啥作用:
紅外激光投影儀:
投射一個(gè)紅外光點(diǎn)網(wǎng)格到場(chǎng)景中,然后這些光點(diǎn)被紅外攝像頭捕獲。因?yàn)橥队皟x和攝像頭的位置是固定的,所以通過計(jì)算光點(diǎn)在攝像頭中的位置偏移,可以推算出每個(gè)光點(diǎn)對(duì)應(yīng)的物體距離攝像頭的距離,從而得到場(chǎng)景的深度信息。
紅外攝像頭:
紅外攝像頭是一種能夠捕獲紅外光譜的攝像頭。紅外光譜是電磁譜中的一部分,其波長長于可見光,但短于微波。紅外攝像頭的主要作用是能夠在無可見光照明的條件下進(jìn)行成像,因?yàn)樵S多物體會(huì)發(fā)射、反射或透過紅外光。
彩色攝像頭:
通常用于捕獲場(chǎng)景的常規(guī)視覺信息,而其他的攝像頭則用于捕獲額外的信息,如場(chǎng)景的深度信息或在低光照條件下的圖像。這些信息可以與彩色攝像頭捕獲的圖像相結(jié)合,以提供更豐富的視覺數(shù)據(jù),支持更高級(jí)的功能,如面部識(shí)別、增強(qiáng)現(xiàn)實(shí)或3D建模等。
結(jié)合這四個(gè)攝像頭的功能,能夠獲取一個(gè)物體的三維信息,這種技術(shù)可以用于人臉識(shí)別、手勢(shì)識(shí)別、物體識(shí)別、測(cè)量物體的深度等多種應(yīng)用。
Artificial Intelligence Kit 3D
人工智能3D套裝是機(jī)械臂應(yīng)用人工智能,機(jī)器視覺的入門款套裝。套裝使用了四種識(shí)別算法,顏色識(shí)別,形狀識(shí)別,yolov8等,適配可視化的操作界面,使用3D攝像頭解決了2D攝像頭需要標(biāo)志定位的短板,開源代碼基于python平臺(tái),可通過開發(fā)軟件實(shí)現(xiàn)機(jī)械臂的控制。
該套裝是搭配機(jī)械臂(myCobot,mechArm,myArm)進(jìn)行使用,仿工業(yè)場(chǎng)景的構(gòu)造。
myCobot 280
myCobot 280 M5是一款由Elephant Robotics和M5Stack聯(lián)合開發(fā)的最小和最輕的六軸協(xié)作機(jī)器人。它采用集成模塊化設(shè)計(jì),重量僅為850克,非常輕巧,搭載6個(gè)高性能伺服電機(jī),具有快速響應(yīng),慣性小和平滑旋轉(zhuǎn)的特點(diǎn)。
3D攝像頭應(yīng)用領(lǐng)域
如果在同一個(gè)應(yīng)用領(lǐng)域中,用2D攝像頭和3D攝像頭它們的表型性能會(huì)怎樣。從我們身邊常見的來了解:
從圖標(biāo)中可以知道,2D攝像頭需要通過特定的算法來得到一些參數(shù),而3D攝像頭能夠直接獲取較多的信息,在同一應(yīng)用領(lǐng)域下的性能更加精準(zhǔn)。在未來的,3D攝像頭的趨勢(shì)必然是飛速增長的!
這也是我們推出3D人工智能套裝的原因之一,跟上時(shí)代的步伐。
算法介紹
機(jī)械臂視覺識(shí)別,一定會(huì)涉及手眼標(biāo)定。雖然兩種版本的手眼標(biāo)定的流程是一樣的,但是他們?cè)谟?jì)算中還是會(huì)有一些差別,我們先看它們的識(shí)別區(qū)。
從中間的是被區(qū)域可以看到,3D版本已經(jīng)沒有了二維碼的標(biāo)識(shí),在2D版本上二維碼的標(biāo)識(shí)的主要功能是確定識(shí)別的區(qū)域,以及提供一個(gè)固定高度的值。在獲取了三維數(shù)據(jù)之后,就不需要用到二維碼進(jìn)行標(biāo)識(shí)了,可以直接獲取到相機(jī)距離平面高度的值。
這一點(diǎn)體現(xiàn)了3D攝像頭能夠直接獲取深度的信息。
如何使用 realsence 在python中 environment build operate system:window10/11 program language:python 3.9+ libraries: from typing import Tuple, Optional import pyrealsense2 as rs import numpy as np import cv2 import time class RealSenseCamera: def __init__(self): super().__init__() # Configure depth and color streams self.pipeline = rs.pipeline() self.config = rs.config() self.config.enable_stream(rs.stream.color, 1920, 1080, rs.format.bgr8, 30) # Is the camera mirror image reversed self.flip_h = False self.flip_v = False # Get device product line for setting a supporting resolution pipeline_wrapper = rs.pipeline_wrapper(self.pipeline) pipeline_profile = self.config.resolve(pipeline_wrapper) # set auto exposure color = pipeline_profile.get_device().query_sensors()[0] color.set_option(rs.option.enable_auto_exposure, True) device = pipeline_profile.get_device() sensor_infos = list( map(lambda x: x.get_info(rs.camera_info.name), device.sensors) ) # set resolution self.config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) self.config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) align_to = rs.stream.color self.align = rs.align(align_to) def capture(self): # Start streaming self.pipeline.start(self.config) # warm up for i in range(60): pipeline = self.pipeline frames = pipeline.wait_for_frames() def release(self): self.pipeline.stop() def update_frame(self) -> None: pipeline = self.pipeline frames = pipeline.wait_for_frames() aligned_frames = self.align.process(frames) self.curr_frame = aligned_frames self.curr_frame_time = time.time_ns() def color_frame(self) -> Optional[np.ndarray]: frame = self.curr_frame.get_color_frame() if not frame: return None frame = np.asanyarray(frame.get_data()) if self.flip_h: frame = cv2.flip(frame, 1) if self.flip_v: frame = cv2.flip(frame, 0) return frame def depth_frame(self) -> Optional[np.ndarray]: frame = self.curr_frame.get_depth_frame() if not frame: return None frame = np.asanyarray(frame.get_data()) if self.flip_h: frame = cv2.flip(frame, 1) if self.flip_v: frame = cv2.flip(frame, 0) return frame 顏色識(shí)別和形狀識(shí)別都是基于openCV提供的算法來識(shí)別物體抓取物體。只需要簡單的做一個(gè)hsv的檢測(cè)的算法就能夠檢測(cè)出來顏色。
# 初始化要識(shí)別的顏色 def __init__(self) -> None: self.area_low_threshold = 15000 self.detected_name = None self.hsv_range = { "green": ((40, 50, 50), (90, 256, 256)), # "blueA": ((91, 100, 100), (105, 256, 256)), # "yellow": ((20, 240, 170), (30, 256, 256)), "yellow": ((15, 46, 43), (30, 256, 256)), "redA": ((0, 100, 100), (6, 256, 256)), "redB": ((170, 100, 100), (179, 256, 256)), # "orange": ((8, 100, 100), (15, 256, 256)), "blue": ((100, 43, 46), (124, 256, 256)), } # 對(duì)圖像的處理 result = [] for color, (hsv_low, hsv_high) in self.hsv_range.items(): hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) in_range = cv2.inRange(hsv_frame, hsv_low, hsv_high) # 對(duì)顏色區(qū)域進(jìn)行膨脹和腐蝕 kernel = np.ones((5, 5), np.uint8) in_range = cv2.morphologyEx(in_range, cv2.MORPH_CLOSE, kernel) in_range = cv2.morphologyEx(in_range, cv2.MORPH_OPEN, kernel) contours, hierarchy = cv2.findContours( in_range, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE ) contours = list( filter(lambda x: cv2.contourArea(x) > self.area_low_threshold, contours) ) rects = list(map(cv2.minAreaRect, contours)) boxes = list(map(cv2.boxPoints, rects)) boxes = list(map(np.int32, boxes)) if len(boxes) != 0: if color.startswith("red"): color = "red" for box in boxes: result.append(ColorDetector.DetectResult(color, box)) # self.detected_name = result self.detected_name = result[0].color return result
YOLOv8 和拆碼垛
我們?cè)谶@個(gè)套裝里面還使用到了目前比較火的一款識(shí)別模型YOLOv8,此模型還涉及到深度學(xué)習(xí)和模型訓(xùn)練等功能。
YOLOv8是一種目標(biāo)檢測(cè)算法,它是基于深度學(xué)習(xí)的YOLO(You Only Look Once)系列算法的最新版本。YOLO算法是一種實(shí)時(shí)目標(biāo)檢測(cè)算法,其特點(diǎn)是能夠在一次前向傳播中同時(shí)完成目標(biāo)檢測(cè)和定位,速度非??臁ome - Ultralytics YOLOv8 Docs
主要特點(diǎn):
高性能:YOLOv8在目標(biāo)檢測(cè)任務(wù)中具有較高的準(zhǔn)確性和速度。它能夠在實(shí)時(shí)或接近實(shí)時(shí)的速度下進(jìn)行目標(biāo)檢測(cè),適用于各種應(yīng)用場(chǎng)景。
簡單而有效的設(shè)計(jì):YOLOv8采用了簡單而有效的設(shè)計(jì),通過使用更深的網(wǎng)絡(luò)結(jié)構(gòu)和更多的特征層來提高檢測(cè)性能。它還使用了一種自適應(yīng)的訓(xùn)練策略,可以在不同的目標(biāo)檢測(cè)任務(wù)上進(jìn)行快速訓(xùn)練和調(diào)整。
多種規(guī)模的檢測(cè):YOLOv8提供了不同的模型大小,包括小型、中型和大型模型,以滿足不同場(chǎng)景下的需求。這些模型可以在不同的硬件設(shè)備上進(jìn)行部署和使用。
開源和易用性:YOLOv8是開源的,代碼和預(yù)訓(xùn)練模型都可以在GitHub上獲得。它還提供了簡單易用的API,使得用戶可以方便地進(jìn)行模型訓(xùn)練、推理和部署。
要使用YOLOv8是需要進(jìn)行自定義訓(xùn)練模型的,在進(jìn)行目標(biāo)檢測(cè)任務(wù)是,根據(jù)具體應(yīng)用場(chǎng)景和需求,通過在自定義數(shù)據(jù)集上進(jìn)行訓(xùn)練得到模型。
為什么要訓(xùn)練模型呢?訓(xùn)練模型的目的是讓計(jì)算機(jī)能夠自動(dòng)識(shí)別和定位圖像或視頻中的目標(biāo)物體。通過訓(xùn)練模型,我們可以讓計(jì)算機(jī)學(xué)會(huì)如何識(shí)別不同種類的物體,并且能夠準(zhǔn)確地定位它們的位置。這對(duì)于許多應(yīng)用場(chǎng)景非常重要,比如自動(dòng)駕駛、安防監(jiān)控、智能交通等。
對(duì)此我們的源碼文件中已經(jīng)包含了我們自己訓(xùn)練的模型,如果你對(duì)YOLOv8的技術(shù)很熟練了,你可以自己對(duì)識(shí)別物體進(jìn)行訓(xùn)練。
下面的代碼是程序中使用的代碼
class YOLODetector: DetectResult = List[ultralytics.engine.results.Results] def __init__(self) -> None: """ init YOLO model。 """ self.model_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/resources/yolo/best.pt' self.model = YOLO(self.model_path) self.predict_args = {"conf": 0.2} self.detected_name = None def get_radian(self, res: DetectResult): return 0 def detect(self, frame: np.ndarray): """ Perform object detection on input images. Args: frame (np.ndarray): Input image frame. Returns: List[DetectResult]: A list containing the detection results. """ res = self.model.predict(frame, **self.predict_args) res = list(filter(lambda x: len(x.boxes) != 0, res)) if len(res) == 0: return None else: names = self.get_names(res) self.detected_name = names return res def draw_result(self, frame: np.ndarray, res: List[DetectResult]): """ Draws the bounding box of the detection results on the image. Args: frame (np.ndarray): Input image frame. res (List[DetectResult]): List of detection results. """ res = list(filter(lambda x: len(x.boxes) != 0, res)) for r in res: boxes = r.boxes.xyxy.numpy() for box in boxes: x1, y1, x2, y2 = box.astype(int) cv2.rectangle(frame, (x1, y1), (x2, y2), color=(0, 255, 0), thickness=1) cv2.putText(frame, "Name: " + str(self.detected_name), (20, 80), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 255)) # x1, y1, x2, y2 = np.squeeze(r.boxes.xyxy.numpy()).astype(int) # cv2.rectangle(frame, (x1, y1), (x2, y2), color=(0, 255, 0), thickness=1) def target_position(self, res: DetectResult) -> Tuple[int, int]: """ Extract the location information of the target from the detection results. Args: res (DetectResult): detection result. Returns: Tuple[int, int]: The position coordinates (x, y) of the target. """ boxes = res.boxes.xywh.numpy() boxs_list = [] for box in boxes: x, y, w, h = box.astype(int) boxs_list.append((x, y)) boxs_list = tuple(boxs_list) return boxs_list def get_rect(self, res: DetectResult): """ Obtain the bounding box coordinate information of the target from the detection result. Args: res (DetectResult): detection result. Returns: List[Tuple[int, int]]: The bounding box coordinate information of the target, including four vertex coordinates. """ boxes = res.boxes.xywh.numpy() box_list = [] for box in boxes: x, y, w, h = box.astype(int) size = 3 rect = [ [x - size, y - size], [x + size, y - size], [x + size, y + size], [x - size, y + size], ] box_list.append(rect) return box_list def get_names(self, res: DetectResult): """ Get the category name in the detection results Args: res (DetectResult): detection result. Returns: List[names]: A list category names. """ names_dict = { 0: 'jeep', 1: 'apple', 2: 'banana1', 3: 'bed', 4: 'grape', 5: 'laptop', 6: 'microwave', 7: 'orange', 8: 'pear', 9: 'refrigerator1', 10: 'refrigerator2', 11: 'sofa', 12: 'sofa2', 13: 'tv', 14: 'washing machine1' } ids = [int(cls) for cls in res[0].boxes.cls.numpy()] # Assuming you have only one result in the list names = [names_dict.get(id, 'Unknown') for id in ids] return names
![wKgaomVlUjiAGHlfAARerGQ7tto751.png](https://file1.elecfans.com/web2/M00/B1/86/wKgaomVlUjiAGHlfAARerGQ7tto751.png)
搭配上3D攝像頭的特性,獲取被識(shí)別的物體的高度實(shí)現(xiàn)拆碼垛的demo,能夠?qū)⑺麄兿癫鸱e木一樣拆除。
總結(jié)
我們的機(jī)械臂和深度攝像頭套裝不僅是一款產(chǎn)品,更是一個(gè)開啟學(xué)習(xí)之門的機(jī)會(huì)。這個(gè)套裝以用戶友好的方式,提供了一個(gè)理想的平臺(tái),讓初學(xué)者可以在實(shí)踐中探索和學(xué)習(xí)機(jī)械臂操作和機(jī)器視覺的知識(shí),更重要的是,它提供了一個(gè)獨(dú)特的機(jī)會(huì),讓用戶能夠深入理解和掌握3D相機(jī)算法。
隨著科技的進(jìn)步,3D攝像頭的應(yīng)用正在迅速擴(kuò)展到多個(gè)領(lǐng)域,包括但不限于制造、安全、娛樂和醫(yī)療。我們堅(jiān)信,通過使用我們的套裝,用戶將能夠把握這一技術(shù)趨勢(shì),為自己的未來學(xué)習(xí)和職業(yè)生涯奠定堅(jiān)實(shí)的基礎(chǔ)。
審核編輯 黃宇
-
機(jī)器人
+關(guān)注
關(guān)注
211文章
28714瀏覽量
208727 -
人工智能
+關(guān)注
關(guān)注
1796文章
47818瀏覽量
240605 -
開源
+關(guān)注
關(guān)注
3文章
3415瀏覽量
42752 -
機(jī)械臂
+關(guān)注
關(guān)注
12文章
527瀏覽量
24744
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
英倫科技裸眼3D便攜屏有哪些特點(diǎn)?
![英倫科技裸眼<b class='flag-5'>3D</b>便攜屏有哪些特點(diǎn)?](https://file1.elecfans.com/web2/M00/E8/7E/wKgaomZMIm2AbgVfAACD6ARO2cM449.png)
SciChart 3D for WPF圖表庫
![SciChart <b class='flag-5'>3D</b> for WPF圖表庫](https://file1.elecfans.com/web3/M00/06/FA/wKgZPGeR2MGACTO-AAB0dyVzDd0112.png)
騰訊混元3D AI創(chuàng)作引擎正式發(fā)布
騰訊混元3D AI創(chuàng)作引擎正式上線
使用myCobot 280機(jī)械臂結(jié)合ROS2系統(tǒng)搭建機(jī)械分揀站
![使用myCobot 280<b class='flag-5'>機(jī)械</b><b class='flag-5'>臂</b><b class='flag-5'>結(jié)合</b>ROS2系統(tǒng)搭建<b class='flag-5'>機(jī)械</b>分揀站](https://file1.elecfans.com/web3/M00/05/FD/wKgZPGeHDmCAIR8mAABeZax7Ft8237.png)
FPC與3D打印技術(shù)的結(jié)合 FPC在汽車電子中的應(yīng)用前景
![](https://file1.elecfans.com/web2/M00/09/A6/wKgZomcQfe2AHGeLABCy1Q7BXzM853.png)
虛實(shí)結(jié)合:機(jī)械臂數(shù)字孿生如何改變制造業(yè) #機(jī)械臂 #HMI #虛實(shí)結(jié)合 #數(shù)字孿生
3D霍爾效應(yīng)傳感器在機(jī)器人設(shè)計(jì)中的機(jī)械優(yōu)勢(shì)
![<b class='flag-5'>3D</b>霍爾效應(yīng)傳感器在機(jī)器人設(shè)計(jì)中的<b class='flag-5'>機(jī)械</b>優(yōu)勢(shì)](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
奧比中光推出2.0版大模型機(jī)械臂
歡創(chuàng)播報(bào) 騰訊元寶首發(fā)3D生成應(yīng)用
![歡創(chuàng)播報(bào) 騰訊元寶首發(fā)<b class='flag-5'>3D</b>生成應(yīng)用](https://file1.elecfans.com//web2/M00/FE/11/wKgaomaYjm2AAs3TAAB3LCRK4z892.webp)
裸眼3D筆記本電腦——先進(jìn)的光場(chǎng)裸眼3D技術(shù)
![](https://file1.elecfans.com/web2/M00/FB/65/wKgZomaQ9aWAX3iMAAwqi0yBuXE508.png)
機(jī)械臂3D視覺定位抓取放置 #機(jī)械手 #協(xié)作機(jī)器人 #協(xié)作機(jī)械手 #復(fù)合機(jī)器人
大象機(jī)器人開源協(xié)作機(jī)械臂機(jī)械臂接入GPT4o大模型!
![大象機(jī)器人開源協(xié)作<b class='flag-5'>機(jī)械</b><b class='flag-5'>臂</b><b class='flag-5'>機(jī)械</b><b class='flag-5'>臂</b>接入GPT4o大模型!](https://file1.elecfans.com/web2/M00/F8/76/wKgaomaE562APdcZAASpzMUpXJQ743.png)
![](https://file1.elecfans.com/web2/M00/C5/CE/wKgaomX4xO2AEYO-AABXvRldnzQ502.png)
評(píng)論