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)
相关推荐
疯狂成瘾者15 分钟前
语义分块提升RAG检索精度
python
551只玄猫16 分钟前
【数学建模 matlab 实验报告12】聚类分析和判别分析
开发语言·数学建模·matlab·课程设计·聚类·实验报告
小陈工2 小时前
Python Web开发入门(十七):Vue.js与Python后端集成——让前后端真正“握手言和“
开发语言·前端·javascript·数据库·vue.js·人工智能·python
H Journey2 小时前
C++之 CMake、CMakeLists.txt、Makefile
开发语言·c++·makefile·cmake
A__tao6 小时前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
研究点啥好呢6 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
lly2024067 小时前
C 标准库 - `<stdio.h>`
开发语言
沫璃染墨7 小时前
C++ string 从入门到精通:构造、迭代器、容量接口全解析
c语言·开发语言·c++
jwn9997 小时前
Laravel6.x核心特性全解析
开发语言·php·laravel
迷藏4947 小时前
**发散创新:基于Rust实现的开源合规权限管理框架设计与实践**在现代软件架构中,**权限控制(RBAC)** 已成为保障
java·开发语言·python·rust·开源