yolov9直接调用zed相机实现三维测距(python)

yolov9直接调用zed相机实现三维测距(python)

  • [1. 相关配置](#1. 相关配置)
  • [2. 相关代码](#2. 相关代码)
    • [2.1 相机设置](#2.1 相机设置)
    • [2.2 测距模块](#2.2 测距模块)
    • [2.2 实验结果](#2.2 实验结果)

相关链接

此项目直接调用zed相机实现三维测距,无需标定,相关内容如下:

1. yolov4直接调用zed相机实现三维测距
2.yolov5直接调用zed相机实现三维测距(python)
3. yolov8直接调用zed相机实现三维测距(python)
4.具体实现效果已在哔哩哔哩发布,点击此链接跳转

本篇博文工程源码下载(麻烦github给个星星)
下载链接:https://github.com/up-up-up-up/zed-yolov9

附:Zed调用YOLOv7测距也已经实现,但是3060笔记本6G显存带不动,在大现存服务器上可以运行,可能是由于YOLOv7网络结构导致的,由于不具备普适性,就不再写相关文章了,有需要的可以仿照这个代码去改写

1. 相关配置

python==3.7

Windows-pycharm

zed api 具体配置见 (zed api 配置步骤)

2. 相关代码

2.1 相机设置

python 复制代码
zed = sl.Camera()
input_type = sl.InputType()
 if opt.svo is not None:
     input_type.set_from_svo_file(opt.svo)

 # Create a InitParameters object and set configuration parameters
 init_params = sl.InitParameters(input_t=input_type, svo_real_time_mode=True)
 init_params.camera_resolution = sl.RESOLUTION.HD720
 init_params.coordinate_units = sl.UNIT.METER
 init_params.depth_mode = sl.DEPTH_MODE.ULTRA  # QUALITY
 init_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP
 init_params.depth_maximum_distance = 5

 runtime_params = sl.RuntimeParameters()
 status = zed.open(init_params)

2.2 测距模块

python 复制代码
for *xyxy, conf, cls in reversed(det):
     xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
     cent_x = round(xywh[0] * im0.shape[1])
     cent_y = round(xywh[1] * im0.shape[0])
     cent_w = round(xywh[2] * im0.shape[1])
     point_1 = round(cent_x - 0.4 * cent_w)
     point_2 = round(cent_x + 0.4 * cent_w)
     wide_value_1 = point_cloud.get_value(point_1, cent_y)[1]
     wide_value_2 = point_cloud.get_value(point_2, cent_y)[1]

     try:
         wide = round(wide_value_1[0], 4) - round(wide_value_2[0], 4)
         wide = round(abs(wide * 1000))
     except:
         wide = 0.00
         pass
     point_cloud_value = point_cloud.get_value(cent_x, cent_y)[1]
     point_cloud_value = point_cloud_value * -1000.00
     if point_cloud_value[2] > 0.00:
         try:
             point_cloud_value[0] = round(point_cloud_value[0])
             point_cloud_value[1] = round(point_cloud_value[1])
             point_cloud_value[2] = round(point_cloud_value[2])
             print("x:", point_cloud_value[0], "y:", point_cloud_value[1], "z:",
                   point_cloud_value[2], "W:", wide)
             txt = 'x:{0} y:{1} z:{2} w:{3}'.format(point_cloud_value[0], point_cloud_value[1],
                                                    point_cloud_value[2], wide)
             a=point_cloud_value[0]
             b=point_cloud_value[1]
             c=point_cloud_value[2]
             distance = ((a ** 2 + b ** 2 + c ** 2) ** 0.5)

             # annotator.box_label(xyxy, txt, color=(255, 0, 0))
             label = f'{names[int(cls)]} {conf:.2f} '
             label = label + " " +"dis:" +str(distance)
             annotator.box_label(xyxy, label, color=colors(c, True))

         except:
             pass

2.2 实验结果

测距功能

视频展示

相关推荐
sauTCc2 分钟前
Pytorch加载数据的Dateset类和DataLoader类
人工智能·pytorch·python
码叔义11 分钟前
Jsonpath 使用说明
android·开发语言·javascript
量化投资技术16 分钟前
深入xtquant:掌握实时行情订阅的艺术
python·量化交易·量化·量化投资·qmt·miniqmt
m0_7482459225 分钟前
Python大数据可视化:基于spark的短视频推荐系统的设计与实现_django+spider
python·spark·django
行十万里人生25 分钟前
Qt 对象树详解:从原理到运用
开发语言·数据库·qt·华为od·华为·华为云·harmonyos
原来是猿31 分钟前
蓝桥备赛(四)- 数组(下)
开发语言·数据结构·c++·算法
心流时间34 分钟前
[Java基础] JVM常量池介绍(BeanUtils.copyProperties(source, target)中的属性值引用的是同一个对象吗)
java·开发语言·jvm
网络安全Ash37 分钟前
Python网络安全脚本
开发语言·python·web安全
.猫的树1 小时前
Java集合List快速实现重复判断的10种方法深度解析
java·开发语言·list·集合
刀客1231 小时前
C++ STL(三)list
开发语言·c++