与 Roboflow 集成
与 Roboflow 集成
请注意,目前在 OAK 设备上部署 Roboflow 模型时,我们仅支持对象检测任务。
安装
roboflowoak、depthai 和 opencv-python:Command Line
1pip install roboflowoak
2pip install depthai
3pip install opencv-python从 Roboflow 部署模型
model:将此替换为 Roboflow 中模型的 ID。version:插入您模型的特定版本号。api_key:使用 Roboflow 为您的帐户提供的私有 API 密钥。
Python
1from roboflowoak import RoboflowOak
2import cv2
3import time
4import numpy as np
5
6if __name__ == '__main__':
7 # 使用 RoboflowOak 模块实例化一个对象 (rf)
8 rf = RoboflowOak(model="YOUR-MODEL-ID", confidence=0.05, overlap=0.5,
9 version="YOUR-MODEL-VERSION-#", api_key="YOUR-PRIVATE_API_KEY", rgb=True,
10 depth=True, device=None, blocking=True)
11 # 运行我们的模型并显示带有检测结果的视频输出
12 while True:
13 t0 = time.time()
14 # rf.detect() 函数运行模型推理
15 result, frame, raw_frame, depth = rf.detect()
16 predictions = result["predictions"]
17 # {
18 # predictions:
19 # [ {
20 # x: (中心),
21 # y:(中心),
22 # width:
23 # height:
24 # depth: ###->
25 # confidence:
26 # class:
27 # mask: {
28 # ]
29 # }
30 # frame - 预处理后的帧,带有检测结果
31 # raw_frame - 来自您的 OAK 的原始帧
32 # depth - 原始帧的深度图,已进行中心校正到中心摄像头
33
34 # 计时:用于基准测试
35 t = time.time()-t0
36 print("FPS ", 1/t)
37 print("PREDICTIONS ", [p.json() for p in predictions])
38
39 # 设置深度计算参数
40 # 如果您使用的是没有深度功能的 OAK,请注释掉以下两行
41 max_depth = np.amax(depth)
42 cv2.imshow("depth", depth/max_depth)
43 # 显示视频流作为连续帧
44 cv2.imshow("frame", frame)
45
46 # 如何关闭 OAK 推理窗口/停止推理:按 CTRL+q 或 CTRL+c
47 if cv2.waitKey(1) == ord('q'):
48 break