Python opencv读取深度图,网格化显示深度

效果图:

代码:

python 复制代码
import cv2
import os

img_path = "./outdir/180m_norm_depth.png"
depth_img = cv2.imread(img_path, cv2.IMREAD_ANYDEPTH)
filename = os.path.basename(img_path)
img_hig, img_wid = depth_img.shape  # (1080, 1920)
print(depth_img.shape)

point_color = (0, 0, 255) # BGR
thickness = 5 
lineType = 4

grid_size = 80

for i in range(img_wid // grid_size):  # 40 为正方向网格的宽
    for j in range(img_hig // grid_size):
        p1 = ((i + 1) * grid_size, (j + 1) * grid_size)
        p2 = (i * grid_size, (j + 1) * grid_size)
        p3 = ((i + 1) * grid_size, j * grid_size)
        cv2.line(depth_img, p1, p2, point_color, thickness, lineType)
        cv2.line(depth_img, p1, p3, point_color, thickness, lineType)
        depth_pos = ((i + 1) * grid_size - grid_size // 2, (j + 1) * grid_size - grid_size // 2)
        depth_value = depth_img[depth_pos[1], depth_pos[0]]
        cv2.putText(depth_img, str(depth_value), (depth_pos[0] - 20, depth_pos[1]), cv2.FONT_HERSHEY_COMPLEX, 0.8, (100, 200, 200), 1)
        # depth_img[i][j] = depth_img[i][j] / 1000
cv2.imwrite(os.path.join("./outdir/", filename[:filename.rfind('.')] + '_grid.png'), depth_img)
相关推荐
必须得开心呀27 分钟前
QT解决中文乱码问题
开发语言·qt
闲猫40 分钟前
Python FastAPI + SQLAlchemy 入门教程:从零搭建你的第一个 Web 应用
前端·python·fastapi
这不小天嘛1 小时前
JAVA八股——redis篇
java·开发语言·redis
逝水无殇3 小时前
C# 字符串(String)详解
开发语言·后端·c#
精明的身影3 小时前
C++自学之路1:Hello world
开发语言·c++
leo__5203 小时前
基于导航数据的扩展卡尔曼滤波(EKF)MATLAB 实现
开发语言·matlab
gugucoding4 小时前
25. 【C语言】二进制文件与随机读写
c语言·开发语言
北极星日淘4 小时前
中古货品品相评级算法实战|Java权重计分实现标准化五级品相体系
开发语言·python
hangyuekejiGEO4 小时前
临沂GEO服务企业技术选型分析
人工智能·python
小巧的砖头4 小时前
C#会重蹈覆辙吗?系列之2:反射及元数据的性能问题
开发语言·前端·c#