Intel Realsense D435 通过识别目标的像素坐标和深度值(使用内参intrinsics)获取目标点的真实坐标

  • 图原理
  • 基本获取内参`intrinsics`代码
  • 实操代码1(在`tensorflow-yolov3`中获取内参)
  • 实操代码2(在`tensorflow-yolov3` `draw_bbox()`函数中实现坐标转换操作)

图原理

对付fy同理
(0,0)位置为D435 RGB摄像头对应点位置

基本获取内参intrinsics代码

import pyrealsense2 as rspipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
profile = pipeline.start(config)
frames = pipeline.wait_for_frames()
depth = frames.get_depth_frame()
color = frames.get_color_frame()# 获取内参
depth_profile = depth.get_profile()
# print(depth_profile)
# <pyrealsense2.video_stream_profile: 1(0) 640x480 @ 30fps 1>
# print(type(depth_profile))
# <class 'pyrealsense2.pyrealsense2.stream_profile'>
# print(depth_profile.fps())
# 30
# print(depth_profile.stream_index())
# 0
# print(depth_profile.stream_name())
# Depth
# print(depth_profile.stream_type())
# stream.depth
# print('', depth_profile.unique_id)
# <bound method PyCapsule.unique_id of <pyrealsense2.video_stream_profile: 1(0) 640x480 @ 30fps 1>>color_profile = color.get_profile()
# print(color_profile)
# <pyrealsense2.video_stream_profile: 2(0) 640x480 @ 30fps 6>
# print(type(color_profile))
# <class 'pyrealsense2.pyrealsense2.stream_profile'>
# print(depth_profile.fps())
# 30
# print(depth_profile.stream_index())
# 0cvsprofile = rs.video_stream_profile(color_profile)
dvsprofile = rs.video_stream_profile(depth_profile)color_intrin = cvsprofile.get_intrinsics()
# print(color_intrin.fx)
# 616.5906372070312
# print(color_intrin)
# width: 640, height: 480, ppx: 318.482, ppy: 241.167, fx: 616.591, fy: 616.765, model: 2, coeffs: [0, 0, 0, 0, 0]# depth_intrin = dvsprofile.get_intrinsics()
# print(depth_intrin)
# width: 640, height: 480, ppx: 317.78, ppy: 236.709, fx: 382.544, fy: 382.544, model: 4, coeffs: [0, 0, 0, 0, 0]# extrin = depth_profile.get_extrinsics_to(color_profile)
# print(extrin)
# rotation: [0.999984, -0.00420567, -0.00380472, 0.00420863, 0.999991, 0.00076919, 0.00380145, -0.00078519, 0.999992]
# translation: [0.0147755, 0.000203265, 0.00051274]

实操代码1(在tensorflow-yolov3中获取内参)

# 先获取对齐流,得到color_intrin后,将对齐后的流通过比例关系将目标的像素坐标转换为实际坐标。
# 我们这使用的识别框架为Tensorflow-yolov3
import pyrealsense2 as rspipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)pipeline.start(config)# 创建对齐对象(深度对齐颜色)
align = rs.align(rs.stream.color)try:while True:frames = pipeline.wait_for_frames()# 获取对齐帧集aligned_frames = align.process(frames)# 获取对齐后的深度帧和彩色帧aligned_depth_frame = aligned_frames.get_depth_frame()color_frame = aligned_frames.get_color_frame()# 获取颜色帧内参color_profile = color_frame.get_profile()cvsprofile = rs.video_stream_profile(color_profile)color_intrin = cvsprofile.get_intrinsics()color_intrin_part = [color_intrin.ppx, color_intrin.ppy, color_intrin.fx, color_intrin.fy]# print(color_intrin_part)# [318.48199462890625, 241.16720581054688, 616.5906372070312, 616.7650146484375]if not aligned_depth_frame or not color_frame:continue

实操代码2(在tensorflow-yolov3 draw_bbox()函数中实现坐标转换操作)

# video_demo.py文件中:
image = utils.draw_bbox(frame, bboxes, aligned_depth_frame, color_intrin_part)
# utils.py文件中:
def draw_bbox(image, bboxes, aligned_depth_frame, color_intrin_part, classes=read_class_names(cfg.YOLO.CLASSES),show_label=True):print('*' * 50)# 提取ppx,ppy,fx,fyppx = color_intrin_part[0]ppy = color_intrin_part[1]fx = color_intrin_part[2]fy = color_intrin_part[3]for i, bbox in enumerate(bboxes):if show_label:target_xy_pixel = [int(round((coor[0] + coor[2]) / 2)), int(round((coor[1] + coor[3]) / 2))]target_depth = aligned_depth_frame.get_distance(target_xy_pixel[0], target_xy_pixel[1])target_xy_true = [(target_xy_pixel[0] - ppx) * target_depth / fx,(target_xy_pixel[1] - ppy) * target_depth / fy]print('识别出目标:{} 中心点像素坐标:({}, {}) 实际坐标(mm):({:.3f},{:.3f}) 深度(mm):{:.3f}'.format(classes[class_ind],target_xy_pixel[0],target_xy_pixel[1],target_xy_true[0] * 1000,-target_xy_true[1] * 1000,target_depth * 1000))**************************************************识别出目标:person 中心点像素坐标:(272, 142) 实际坐标(mm):(-160,341) 深度(mm):2122识别出目标:person 中心点像素坐标:(414, 197) 实际坐标(mm):(506,234) 深度(mm):3268识别出目标:person 中心点像素坐标:(114, 246) 实际坐标(mm):(-930,-22) 深度(mm):2804识别出目标:chair 中心点像素坐标:(82, 340) 实际坐标(mm):(-934,-390) 深度(mm):2435识别出目标:chair 中心点像素坐标:(60, 296) 实际坐标(mm):(-1021,-216) 深度(mm):2435识别出目标:keyboard 中心点像素坐标:(456, 408) 实际坐标(mm):(199,-241) 深度(mm):892识别出目标:laptop 中心点像素坐标:(287, 303) 实际坐标(mm):(-67,-131) 深度(mm):1306识别出目标:laptop 中心点像素坐标:(354, 221) 实际坐标(mm):(77,44) 深度(mm):1332识别出目标:laptop 中心点像素坐标:(428, 257) 实际坐标(mm):(507,-73) 深度(mm):2856识别出目标:laptop 中心点像素坐标:(522, 357) 实际坐标(mm):(0,-0) 深度(mm):0return image

代码中突出了一些关键代码,删除了不必展示的代码,源框架请参考YunYang1994/tensorflow-yolov3 Readme 翻译。

参考文章1:Intel Realsense D435 如何获取摄像头的内参?get_profile() video_stream_profile() get_intrinsics()

参考文章2:Intel Realsense D435 python 从深度相机realsense生成pcl点云

参考文章3:RGB图和Depth图生成点云图原理与代码实现(realsense D435 )

参考文章4:realsense SDK2.0学习::(三)D435深度图片对齐到彩色图片-代码实现

Intel Realsense D435 通过识别目标的像素坐标和深度值(使用内参intrinsics)获取目标点的真实坐标相关推荐

  1. Tensorflow_yolov3 Intel Realsense D435奇怪的现象,多摄像头连接时一旦能检测到深度马上就会卡(卡住)

    两个摄像头连接时一旦能检测到深度马上就会卡(小于30公分),,单个摄像头没事,这是使用了多线程传输后的现象,不知咋回事... 后来加了这句验证全局变量是否存在,好像好点了,有待验证 20200401 ...

  2. Intel Realsense D435 python (Python Wrapper)example00: NumPy Integration 将深度帧数据转换为 Numpy 数组进行处理

    NumPy Integration: Librealsense frames support the buffer protocol. A numpy array can be constructed ...

  3. python Intel Realsense D435 多线程资源分配问题(卡住、卡死)

    在使用python多线程调用Intel Realsense D435多个摄像头时,发现pyrealsense的例如pipeline.start().context.query_devices()函数会 ...

  4. SQ 小车避障 Intel Realsense D435 基于线性梯度的深度值过滤

    原理图 相关代码 # -*- coding: utf-8 -*- """ @File : 191224_obstacle_detection_建立梯度.py @Time ...

  5. Intel Realsense D435运行报错 RuntimeError: Camera not connected! dev.hardware_reset()函数需加睡眠sleep()

    解决方案: 参考:Intel Realsense D435报错 RuntimeError: MFCreateDeviceSource(_device_attrs, &_source) retu ...

  6. yunyang tensorflow-yolov3 Intel Realsense D435 (并发)调用两个摄像头运行识别程序并画框

    只是一个测试,测试在并发运行下,同时开启两个摄像头获取视频流并调用识别函数的运行结果,以后在摄像头多的情况下,肯定不能这样,需要批量创建各种对象. 并发,指的是不在多线程的情况下,每个摄像头的视频流送 ...

  7. python如何拟合三维平面(拟合Intel Realsense D435深度数据点)

    文章目录 拟合Intel Realsense D435深度数据点 参考文章:[MQ笔记]超简单的最小二乘法拟合平面(Python) import numpy as np import matplotl ...

  8. 为什么Intel Realsense D435深度摄像头在基于深度的水平方向障碍物检测(避障)方案中,摄像头不宜安装太高?

    补一句,为啥R与b对比就要比R与a对比更容易区分? 因为a与b的右端和障碍物R属同一深度,但b左端明显比a左端深度大,总体比a拥有差异性更大的深度范围,因此b与a相比,对R拥有差异性更大的深度范围, ...

  9. Intel Realsense D435 python multiprocessing 摄像头多进程流传输

    参考文章1:python 测试multiprocessing多进程 参考文章2:Intel Realsense D435 多摄像头目标识别架构

最新文章

  1. 基于HT for Web 3D呈现Box2DJS物理引擎
  2. android从放弃到精通 第五天 excellent
  3. Alex学Ruby[详解 block和Proc对象]
  4. 全球及中国养老护理行业十四五趋势前景与投资动向建议报告2022版
  5. NYOJ 741 数学家ST
  6. instanceof 和 对象转型
  7. 计算机行业的pest分析,2014-2018年中国电脑外设行业市场发展现状及未来趋势调研报告...
  8. GDC 2012]Epic Games谈在智能手机上制作和台式游戏机同等级的图形游戏的经验
  9. c++ 服务 以当前用户拉起进程_渗透技巧——通过CredSSP导出用户的明文口令
  10. python基础知识——函数(上)
  11. IDEA使用maven命令打包
  12. excel转word_扫描全能王扫描仪PDF、拍文件转word和excel
  13. 电影《无双》中的管理知识
  14. shopxp商城系统对接个人支付宝免签h5支付
  15. GOT-10k: A Large High-Diversity Benchmark forGeneric Object Tracking in the Wild(论文翻译)
  16. 使用po模型进行自动化测试
  17. 仿抖音--将图片转化成对应的字符图片
  18. xp2 server application error 错误解决
  19. 贝叶斯方法和采样技术结合-MCMC-后验分布
  20. PC实现Win10/原生安卓双系统

热门文章

  1. OPEN(SAP) UI5 扫盲
  2. LSMW批处理使用方法(04)_步骤3上
  3. CO07利润中心必输
  4. ALEIDoc EDI(4)--change point02
  5. SAP中如何实现<生产订单>的批量删除方法!
  6. Smartform下載PDF
  7. ABAP 删除内表重复数据
  8. windows+mysql+解压版_Windows操作系统安装MySQL解压版
  9. python统计字符在文件中出现的次数_python字符串中字符出现次数(python获取字符串个数)...
  10. 移动互联网时代的信息安全与防护_移动互联网时代,草根创业还有哪些机会?...