当前位置: 首页 > news >正文

成都企业建站公司在线咨询能下短视频网站做牙

成都企业建站公司在线咨询,能下短视频网站做牙,学编程多大年龄开始学为最佳,东莞百度seo关键词优化文章目录 前言一、读取深度值与图像1、深度值读取2、图像读取 二、深度图可视化1、深度图可视化代码2、深度图可视化结果展示 三、深度图在图像上可视化1、可视化代码2、可视化坐标显示 四、完整代码 前言 kitti数据是一个通用数据,有关kitti的深度图像内容我已有博…

文章目录

  • 前言
  • 一、读取深度值与图像
    • 1、深度值读取
    • 2、图像读取
  • 二、深度图可视化
    • 1、深度图可视化代码
    • 2、深度图可视化结果展示
  • 三、深度图在图像上可视化
    • 1、可视化代码
    • 2、可视化坐标显示
  • 四、完整代码

前言

kitti数据是一个通用数据,有关kitti的深度图像内容我已有博客介绍。这里,我将给出一个工具,用于显示深度值对应像素坐标再图像上,也给出深度值可视化显示内容。

一、读取深度值与图像

很简单,直接使用cv与PIL库可实现数据读取,其调用代码如下:

    path = './data/2011_09_26_drive_0001_sync'index = '0000000005'image_2_path = os.path.join(path, '2011_09_26_drive_0001_sync/2011_09_26/2011_09_26_drive_0001_sync/image_02/data', index + '.png') # 获得图像depth_path = os.path.join(path,'2011_09_26_drive_0001_sync/proj_depth/groundtruth/image_02',index+'.png')groundtruth = depth_read(depth_path)img = get_image(image_2_path)  # 读取图像

1、深度值读取

使用官网提供方法,该方法得到是真实相机坐标系下z轴距离,我会在后面图显示,其代码如下:

def depth_read(filename):# loads depth map D from png file# and returns it as a numpy array,# for details see readme.txtdepth_png = np.array(Image.open(filename), dtype=int)# make sure we have a proper 16bit depth map here.. not 8bit!assert(np.max(depth_png) > 255)depth = depth_png.astype(np.float) / 256.# depth[depth_png == 0] = -1.return depth

2、图像读取

图像是对应的深度图的图像,以相机02为准,其代码如下:

def get_image(img_path):img = cv2.imread(img_path)return img

二、深度图可视化

显然,我们只需使用深度图信息即可实现。

1、深度图可视化代码

直接使用plt可实现,其代码如下:

def show_depth(groundtruth):# import numpy as np# import matplotlib.pyplot as plt# 假设我们有深度数据存储在一个名为depth_data的NumPy数组中。# 这个数组应该具有与你的图像相同的形状。# 转换深度数据到0-1范围内的浮点数normalized_depth = groundtruth.astype(np.float32) / groundtruth.max()# 创建一个颜色映射,从蓝色(最小值)到黄色(最大值)cmap = plt.get_cmap('viridis')# 使用颜色映射创建一个新的图像color_image = cmap(normalized_depth)# 删除alpha通道(如果有的话)if color_image.shape[-1] == 4:color_image = color_image[..., :3]# 显示新的彩色图像plt.imshow(color_image)plt.colorbar()plt.show()

2、深度图可视化结果展示

在这里插入图片描述

三、深度图在图像上可视化

1、可视化代码

明显,我目的是要将对应深度图值显示在对应图像上,其代码如下:

def show_depth2img(img,groundtruth,interval_x=100, interval_y=20):"""将深度图对应深度图值按照约定行与列像素打印到图像上方法:interval_x=100:x坐标按照多少像素取值,决定x方向间隔:interval_y=20:y坐标按照多少像素取值,决定y方向间隔:param img: 原始图像内容:param groundtruth: 深度图值:return: 返回一个显示深度图值在图像上"""h, w = img.shape[:2]# interval_x, interval_y = 100, 20  # w与h相隔多少像素显示内容numpy_y, numpy_x = int(h / interval_y), int(w / interval_x)for i in range(numpy_x):for j in range(numpy_y):x = int(interval_x * i)y = int(interval_y * j)value = groundtruth[y, x]img = draw_circle_coord(img, coord=(x, y), value=value)

2、可视化坐标显示

在这里插入图片描述
你会发现有很多值是0,这是正常的。你也发现数值确实也是kitti官网说的,是真实距离坐标,确实是这样的,如图显示。

四、完整代码

最后,我给出一个完整代码,可以直接执行,其代码如下:

import os
import cv2
import numpy as np
import matplotlib.pyplot as plt
def get_image(img_path):img = cv2.imread(img_path)return img
def show_img(img):plt.imshow(img)plt.show()from PIL import Imagedef depth_read(filename):# loads depth map D from png file# and returns it as a numpy array,# for details see readme.txtdepth_png = np.array(Image.open(filename), dtype=int)# make sure we have a proper 16bit depth map here.. not 8bit!assert(np.max(depth_png) > 255)depth = depth_png.astype(np.float) / 256.# depth[depth_png == 0] = -1.return depthdef show_depth(groundtruth):# import numpy as np# import matplotlib.pyplot as plt# 假设我们有深度数据存储在一个名为depth_data的NumPy数组中。# 这个数组应该具有与你的图像相同的形状。# 转换深度数据到0-1范围内的浮点数normalized_depth = groundtruth.astype(np.float32) / groundtruth.max()# 创建一个颜色映射,从蓝色(最小值)到黄色(最大值)cmap = plt.get_cmap('viridis')# 使用颜色映射创建一个新的图像color_image = cmap(normalized_depth)# 删除alpha通道(如果有的话)if color_image.shape[-1] == 4:color_image = color_image[..., :3]# 显示新的彩色图像plt.imshow(color_image)plt.colorbar()plt.show()def draw_circle_coord(image,coord=None,value=None):if coord is not None and value is not None:coord = tuple(coord)image = cv2.circle(image, coord, 5, (255, 0, 0), -1)value = round(value,2)image = cv2.putText(image, str(value)+'m', coord, cv2.FONT_HERSHEY_COMPLEX, 0.6, (0, 0, 255), 1, cv2.LINE_AA)return imagedef show_depth2img(img,groundtruth,interval_x=100, interval_y=20):"""将深度图对应深度图值按照约定行与列像素打印到图像上方法:interval_x=100:x坐标按照多少像素取值,决定x方向间隔:interval_y=20:y坐标按照多少像素取值,决定y方向间隔:param img: 原始图像内容:param groundtruth: 深度图值:return: 返回一个显示深度图值在图像上"""h, w = img.shape[:2]# interval_x, interval_y = 100, 20  # w与h相隔多少像素显示内容numpy_y, numpy_x = int(h / interval_y), int(w / interval_x)for i in range(numpy_x):for j in range(numpy_y):x = int(interval_x * i)y = int(interval_y * j)value = groundtruth[y, x]img = draw_circle_coord(img, coord=(x, y), value=value)if __name__ == '__main__':path = './data/2011_09_26_drive_0001_sync'index = '0000000005'image_2_path = os.path.join(path, '2011_09_26_drive_0001_sync/2011_09_26/2011_09_26_drive_0001_sync/image_02/data', index + '.png') # 获得图像depth_path = os.path.join(path,'2011_09_26_drive_0001_sync/proj_depth/groundtruth/image_02',index+'.png')groundtruth = depth_read(depth_path)img = get_image(image_2_path)  # 读取图像show_depth(groundtruth)  # 显示深度图img = show_depth2img(img, groundtruth, interval_x=100, interval_y=20)cv2.imwrite('out_dir/draw_coord.png',img)show_img(img)
http://www.yayakq.cn/news/475631/

相关文章:

  • 学生模拟网站开发项目网络广告创意策划
  • 自己搭建网站怎么搭建青岛广新信建设咨询公司网站
  • seo公司网站推广设计办公室设计公司
  • 剑阁住房和城乡建设厅网站三亚网站建设兼职
  • 工作室网站制作网站建设如何自学
  • 泉州app网站开发价格wordpress cnzz 插件
  • 自贡做网站公司wordpress 页面转跳
  • 温州网站建设价格技术北京做网页的公司
  • 微网站 手机网站展示型网站 asp.net
  • 申请网站空间有哪几种方式开发手机网站的步骤
  • 沈阳网站开发公司网站建设综合推荐
  • 介绍个人网站的ppt怎么做网站搜索功能
  • 手机网站制作平台gta手机网站大全
  • 深圳智慧建设控股有限公司网站wordpress如何调用图片
  • 吃的网站要怎么做的深圳网站搭建价格
  • 哪些行业做网站多运用.net做网站
  • 搭建网站内链系统成都酒店设计十大公司排名
  • 查询自己网站外链重庆做营销网站建设
  • 网站主目录权限配置微网站案例
  • 杭州做服装电商拿货的网站营销型网站建设域名
  • 快速建站教程提升学历官网报名多少钱
  • 为什么网站权重会掉wordpress删除plugins
  • 做网站的标题图片本地wordpress 外网访问不了
  • 推荐网站建设服务商wordpress可视化编辑器 windows
  • 网站建设zgkr医院网站建设运营方案
  • 重庆最火的网站wordpress导入excel
  • 什么专业会制作网站深圳常平网站建设制作公司
  • 东营市建设监理协会网站企业官网开源
  • 佛山网站运营十年乐云seo国内最大的猎头公司
  • 网站制作二级网页怎么做锦州网站设计