Python可视化深度图

代码来源:https://www.cnblogs.com/BambooEatPanda/p/9921446.html

将深度图映射到颜色空间,是深度图更易查看,下面是颜色空间:

代码,需要做的就是把for循环里面的文件路径和转换后的输出文件夹改一下就可以直接使用python3运行,你可能需要先安装必要的python包,例如opencv-python、numpy和PIL:

import cv2
import os.path
import glob
import numpy as np
from PIL import Image
 
def convertPNG(pngfile,outdir):
    # READ THE DEPTH
    im_depth = cv2.imread(pngfile)
    #apply colormap on deoth image(image must be converted to 8-bit per pixel first)
    im_color=cv2.applyColorMap(cv2.convertScaleAbs(im_depth,alpha=15),cv2.COLORMAP_JET)
    #convert to mat png
    im=Image.fromarray(im_color)
    #save image
    im.save(os.path.join(outdir,os.path.basename(pngfile)))
 
for pngfile in glob.glob("./depth/000000000.png"):#C:/Users/BAMBOO/Desktop/source pics/rgbd_6/depth/*.png
    print(pngfile)
    convertPNG(pngfile,"seedepth")#C:/Users/BAMBOO/Desktop/source pics/rgbd_6/color

 

你可以使用Python可视化深度图。以下是一种实现的方法: 首先,你需要导入必要的库,包括numpy、matplotlib和cv2。你可以使用以下代码导入这些库: ```python import numpy as np import matplotlib.pyplot as plt import cv2 ``` 接下来,你需要加载深度图像。你可以使用numpy的`np.load()`函数来加载.npy文件,例如: ```python depthmap = np.load('example.npy') ``` 然后,你可以使用matplotlib的`plt.imshow()`函数来显示深度图像,例如: ```python plt.imshow(depthmap) ``` 请注意,执行这一行代码并不会立即显示图像,而是将深度图像加载到plt中。 如果你想将图像保存为jpg格式,你可以使用`plt.savefig()`函数,例如: ```python plt.savefig('depthmap.jpg') ``` 如果你想在线显示图像,你可以使用`plt.show()`函数,例如: ```python plt.show() ``` 另外,如果你想将图像保存为灰度图,你可以使用cv2的`cv2.imwrite()`函数,例如: ```python cv2.imwrite("depthmap.png", depthmap) ``` 以上是使用Python可视化深度图的一个简单示例。请注意,这只是一个基本的示例,你可以根据你的具体需求进行进一步的修改和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Python使用open3d或matplotlib库实现显示深度3D效果图](https://blog.csdn.net/zzhceo/article/details/125990965)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [【Python】npy 格式深度图可视化](https://blog.csdn.net/qq_44324181/article/details/127491550)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值