此项目直接调用zed相机实现三维测距,无需标定,相关内容如下:
1. YOLOV5 + 双目测距
2. yolov4直接调用zed相机实现三维测距
3.具体实现效果已在哔哩哔哩发布,点击此链接跳转

相关配置
python==3.7
Windows系统
pycharm平台
zed api(zed api 配置步骤)

zed代码比较简洁,但是一定要把环境配置好,后续自己会把他当做普通双目标定,去对比分析效果,并完善相关功能

主代码

def main():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 parametersinit_params = sl.InitParameters(input_t=input_type, svo_real_time_mode=True)init_params.camera_resolution = sl.RESOLUTION.HD720init_params.coordinate_units = sl.UNIT.METERinit_params.depth_mode = sl.DEPTH_MODE.ULTRA  # QUALITYinit_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UPinit_params.depth_maximum_distance = 5runtime_params = sl.RuntimeParameters()status = zed.open(init_params)if status != sl.ERROR_CODE.SUCCESS:print(repr(status))exit()image_left_tmp = sl.Mat()print("Initialized Camera")positional_tracking_parameters = sl.PositionalTrackingParameters()zed.enable_positional_tracking(positional_tracking_parameters)obj_param = sl.ObjectDetectionParameters()obj_param.detection_model = sl.DETECTION_MODEL.CUSTOM_BOX_OBJECTSobj_param.enable_tracking = Truezed.enable_object_detection(obj_param)objects = sl.Objects()obj_runtime_param = sl.ObjectDetectionRuntimeParameters()point_cloud_render = sl.Mat()point_cloud = sl.Mat()image_left = sl.Mat()depth = sl.Mat()# Utilities for 2D displaywhile True and not exit_signal:if zed.grab(runtime_params) == sl.ERROR_CODE.SUCCESS:# -- Get the imagelock.acquire()zed.retrieve_image(image_left_tmp, sl.VIEW.LEFT)image_net = image_left_tmp.get_data()zed.retrieve_measure(depth, sl.MEASURE.DEPTH)zed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA)lock.release()run_signal = True# -- Detection running on the other threadwhile run_signal:sleep(0.001)# Wait for detectionslock.acquire()# -- Ingest detectionslock.release()zed.retrieve_objects(objects, obj_runtime_param)zed.retrieve_image(image_left, sl.VIEW.LEFT)else:exit_signal = Trueexit_signal = Truezed.close()if __name__ == '__main__':parser = argparse.ArgumentParser()parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')parser.add_argument('--svo', type=str, default=None, help='optional svo file')parser.add_argument('--img_size', type=int, default=416, help='inference size (pixels)')parser.add_argument('--conf_thres', type=float, default=0.6, help='object confidence threshold')opt = parser.parse_args()with torch.no_grad():main()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下方代码仅供参考,试图加跟踪模块,出现了问题!
下方代码仅供参考,试图加跟踪模块,出现了问题!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import numpy as np
import pyzed.sl as sl
import cv2help_string = "[s] Save side by side image [d] Save Depth, [n] Change Depth format, [p] Save Point Cloud, [m] Change Point Cloud format, [q] Quit"
prefix_point_cloud = "Cloud_"
prefix_depth = "Depth_"
path = "./"count_save = 0
mode_point_cloud = 0
mode_depth = 0
point_cloud_format_ext = ".ply"
depth_format_ext = ".png"def point_cloud_format_name():global mode_point_cloudif mode_point_cloud > 3:mode_point_cloud = 0switcher = {0: ".xyz",1: ".pcd",2: ".ply",3: ".vtk",}return switcher.get(mode_point_cloud, "nothing")def depth_format_name():global mode_depthif mode_depth > 2:mode_depth = 0switcher = {0: ".png",1: ".pfm",2: ".pgm",}return switcher.get(mode_depth, "nothing")def save_point_cloud(zed, filename):print("Saving Point Cloud...")tmp = sl.Mat()zed.retrieve_measure(tmp, sl.MEASURE.XYZRGBA)saved = (tmp.write(filename + point_cloud_format_ext) == sl.ERROR_CODE.SUCCESS)if saved:print("Done")else:print("Failed... Please check that you have permissions to write on disk")def save_depth(zed, filename):print("Saving Depth Map...")tmp = sl.Mat()zed.retrieve_measure(tmp, sl.MEASURE.DEPTH)saved = (tmp.write(filename + depth_format_ext) == sl.ERROR_CODE.SUCCESS)if saved:print("Done")else:print("Failed... Please check that you have permissions to write on disk")def save_sbs_image(zed, filename):image_sl_left = sl.Mat()zed.retrieve_image(image_sl_left, sl.VIEW.LEFT)image_cv_left = image_sl_left.get_data()image_sl_right = sl.Mat()zed.retrieve_image(image_sl_right, sl.VIEW.RIGHT)image_cv_right = image_sl_right.get_data()sbs_image = np.concatenate((image_cv_left, image_cv_right), axis=1)cv2.imwrite(filename, sbs_image)def process_key_event(zed, key):global mode_depthglobal mode_point_cloudglobal count_saveglobal depth_format_extglobal point_cloud_format_extif key == 100 or key == 68:  # ‘d’ & 'D'save_depth(zed, path + prefix_depth + str(count_save))count_save += 1elif key == 110 or key == 78:  # 'n' & 'N'mode_depth += 1depth_format_ext = depth_format_name()print("Depth format: ", depth_format_ext)elif key == 112 or key == 80:  # 'p' & 'P'save_point_cloud(zed, path + prefix_point_cloud + str(count_save))count_save += 1elif key == 109 or key == 77:  # 'm' & 'M'mode_point_cloud += 1point_cloud_format_ext = point_cloud_format_name()print("Point Cloud format: ", point_cloud_format_ext)elif key == 104 or key == 72:  # 'h' & 'H'print(help_string)elif key == 115:  # 's'save_sbs_image(zed, "ZED_image" + str(count_save) + ".png")count_save += 1else:a = 0def print_help():print(" Press 's' to save Side by side images")print(" Press 'p' to save Point Cloud")print(" Press 'd' to save Depth image")print(" Press 'm' to switch Point Cloud format")print(" Press 'n' to switch Depth format")def main():# Create a ZED camera objectzed = sl.Camera()# Set configuration parameters# 定义视频数据源和相机参数input_type = sl.InputType()if len(sys.argv) >= 2:input_type.set_from_svo_file(sys.argv[1])init = sl.InitParameters(input_t=input_type)init.camera_resolution = sl.RESOLUTION.HD720init.camera_fps = 30init.depth_mode = sl.DEPTH_MODE.PERFORMANCEinit.coordinate_units = sl.UNIT.MILLIMETER# Open the cameraerr = zed.open(init)if err != sl.ERROR_CODE.SUCCESS:print(repr(err))zed.close()exit(1)# Display help in consoleprint_help()# Set runtime parameters after opening the cameraruntime = sl.RuntimeParameters()# 定义深度贴图方法,此处为标准模式,FILL为全填充(小果不是很好)runtime.sensing_mode = sl.SENSING_MODE.STANDARD# Prepare new image size to retrieve half-resolution images# 此处用于获取和设置图像的分辨率image_size = zed.get_camera_information().camera_resolution# image_size.width = image_size.width / 2# image_size.height = image_size.height / 2# Declare your sl.Mat matricesimage_zed = sl.Mat(image_size.width, image_size.height, sl.MAT_TYPE.U8_C4)depth_image_zed = sl.Mat(image_size.width, image_size.height, sl.MAT_TYPE.U8_C4)point_cloud = sl.Mat()key = ' 'while key != 113:err = zed.grab(runtime)if err == sl.ERROR_CODE.SUCCESS:# Retrieve the left image, depth image in the half-resolutionzed.retrieve_image(image_zed, sl.VIEW.LEFT, sl.MEM.CPU, image_size)zed.retrieve_image(depth_image_zed, sl.VIEW.DEPTH, sl.MEM.CPU, image_size)# Retrieve the RGBA point cloud in half resolutionzed.retrieve_measure(point_cloud, sl.MEASURE.XYZRGBA, sl.MEM.CPU, image_size)# To recover data from sl.Mat to use it with opencv, use the get_data() method# It returns a numpy array that can be used as a matrix with opencvimage_ocv = image_zed.get_data()depth_image_ocv = depth_image_zed.get_data()cv2.imshow("Image", image_ocv)cv2.imshow("Depth", depth_image_ocv)key = cv2.waitKey(10)process_key_event(zed, key)cv2.destroyAllWindows()zed.close()print("\nFINISH")if __name__ == "__main__":main()

测距图(感觉挺精准的)

深度图
图1

图2

yolov5直接调用zed相机实现三维测距(python)相关推荐

  1. yolov4直接调用zed相机实现三维测距(免标定)

    此项目直接调用zed相机实现三维测距,无需标定,相关内容如下: 1. yolov5 + 双目测距(标定测距) 2. yolov5直接调用zed相机实现三维测距 3. 具体实现效果已在哔哩哔哩发布,点击 ...

  2. python怎么调用gige相机_带有OpenCV / python的Prosilica GigE摄像机

    我在Mac OS X上使用GigE(以太网)prosilica GC摄像机,并且能够通过Allied Vision的专有样本查看软件将其读出. 我希望能够使用OpenCV读出相机.我已经正确安装了op ...

  3. python语言下如何通过yolov5调用gige相机

    你好! 在 Python 中通过 YOLOv5 调用 GigE 相机需要按照以下步骤进行: 安装 GigE Vision 的 Python 绑定: pipinstall gigecamera 在 Py ...

  4. 【ZED】从零开始使用ZED相机(五):Opencv+Python实现相机标定(双目)

    引言 同样Opencv+Python实现双目相机的标定,单目标定详见[ZED]从零开始使用ZED相机(五):Opencv+Python实现相机标定(单目) 1 cv2.stereoCalibrate ...

  5. ZED 相机 ORB-SLAM2安装环境配置与ROS下的调试

    注:1. 对某些地方进行了更新(红色标注),以方便进行配置. 2. ZED ROS Wrapper官方github已经更新,根据描述新的Wrapper可能已经不适用与Ros Indigo了,如果大家想 ...

  6. 使用ZED相机识别颜色醒目的水壶并计算与相机的距离

    这是以前做的小项目里的一部分,由于时间久远,在这里整理以下,也方便自己以后查阅. 前期准备 ZED-stereo是很好用功能强大的双目相机,可以调用自带的库直接读取点云数据,也可以很方便获得图像任意一 ...

  7. zed相机拆机_「zed」zed双目相机的windows配置 - 金橙教程网

    zed zed相机非常方便,我用的时候10m内的测距效果非常不错,这里讲一下怎么配置. 首先去官网下载安装包,如果你买的zed相机里面附带u盘有安装包的话,,不建议你使用U盘里面的安装包,它给你的安装 ...

  8. ZED相机使用记录(一):利用ZED SDK使用python完成局域网内的远程视频(视频流)传输

    ** 本文主要介绍ZED2相机以及具有的功能,ZED2相机(这里使用ZED2相机,主要是因为视频流传输功能目前只有ZED2.ZED mini等新版本相机才有的功能)** 本文所使用的环境: pytho ...

  9. ROS wrapper for the ZED SDK (ZED相机的ROS驱动包的使用)

    前言 ZED相机 High-Resolution and High Frame-rate 3D Video Capture Depth Perception indoors and outdoors ...

最新文章

  1. 49-今日交易总结.(2015.1.13)
  2. Python虚拟机之if控制流(一)
  3. HDU 1394 求逆序数(线段树)
  4. Html实现QQ音乐首页(响应式)
  5. 企业版IDP的申请及“In House”发布
  6. 四通一达归于阿里后就涨价,证明资本的目标就是以垄断攫取利润
  7. CSS3解决连续英文字符或数字不能自动换行的问题
  8. 7.0版本的微信你会接受它吗?
  9. 匹配,为什么要“共轭”
  10. Android Q 获取设备唯一ID(UDID\GUID\UUID\SSAID\GAID)
  11. 用turtle画各种各样的数学图形
  12. Drone 自定义 UI
  13. vue 图片,视频点击预览按钮方法
  14. 无约束优化和有约束优化原理
  15. OID的获取及使用方法
  16. <meta></meta>设置
  17. 深圳图高智能深耕5G三防夜视智能终端细分领域,引领行业发展
  18. linux 32位中文版,Linux_Deepin_2014下载|Linux Deepin 2014.3 官方简体中文最新版(32位/64位) - 飞极下载站...
  19. 百度网盘高速下载教程
  20. 大势至服务器文件备份系统怎么样,大势至服务器数据备份软件

热门文章

  1. 福建2022农民丰收节 国稻种芯:主会场活动在永泰隆重举办
  2. 02JavaWeb之MyBatis详解、SqlSession执行、mapper代理执行、动态SQL语句、注解开发、resultMap、resultType、多参数传递
  3. linux中的群组与权限
  4. 计算机组成之cpu组成及工作原理
  5. 人体器官类比金融科技,及其终极目标
  6. R语言标准化死亡率 (SMR)分析(3)
  7. 鬼脚七:淘宝卖家需知的搜索知识(下)
  8. 微信扫码支付成功后跳转
  9. 治理工资拖欠离不开大数据土壤
  10. 微软的努力:来看看WP8开发历程吧