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)
相关推荐
Lyn_Li22 分钟前
Kaggle Top 5 | 198只股票、200条数据的金融预测——BattleFin高分方案从零复现
python·kaggle·比赛复盘·金融预测
小九九的爸爸5 小时前
前端想要入门Agent开发,要具备哪些Python基础?
python·agent·ai编程
阿耶同学6 小时前
手把手教你用 LangGraph 搭建三层嵌套 Agent 架构
python·程序员
花酒锄作田1 天前
Pydantic校验配置文件
python
hboot1 天前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python