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)
相关推荐
顾林海1 小时前
Agent入门阶段-编程基础-Python:流程控制
python·agent·ai编程
呱呱复呱呱4 小时前
Django CBV 源码解读:一个请求是怎么找到你的 get() 方法的
python·django
曲幽9 小时前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict
荣码9 小时前
用Streamlit给AI应用套个界面,10行代码出Web页面
java·python
兵慌码乱19 小时前
基于Python+PyQt5+SQLite的药房管理系统实现:事务一致性与界面解耦全流程解析
python·sqlite·信号与槽·pyqt5·数据库设计·桌面应用开发·事务处理
金銀銅鐵20 小时前
[Python] 体验用欧几里得算法计算最大公约数的过程
python·数学
FreakStudio1 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
用户0332126663671 天前
使用 Python 从零创建 Word 文档
python
Csvn1 天前
Python 两大经典坑点 —— 可变默认参数 & 闭包延迟绑定
后端·python
曲幽1 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate