深度图转为点云说白了其实就是坐标系的变换:图像坐标系-->世界坐标系。变换的约束条件就是相机内参,公式很简单:

,其中x,y,z是点云坐标系,x',y'是图像坐标系,D为深度值。

在进行上述转换之前必须对x',y'进行undistort(反畸变)运算,即便如此最终得到的点云数据还是存在误差的。棋盘标定出的内参本身是带有误差的,它是一种近似逼近值,也就是说它不能真实的映射相机内部结构。

作者:崔世界
链接:https://www.zhihu.com/question/268488496/answer/353439189
来源:知乎

网上一个版本的转换:

http://ziyedy.top/page/python-depth-points.html

def depth2pc(depth_img):"""深度图转点云数据图像坐标系 -> 世界坐标系 :param depth_img: 深度图:return: 点云数据 N*3"""# 相机内参cam_fx = 1120.12cam_fy = 1120.12cam_cx = 640.5cam_cy = 360.5factor = 1# 逐点处理,此过程可以使用numpy优化m, n = depth_img.shapepoint_cloud = []for v in range(m):for u in range(n):if depth_img[v, u] == 0:continuedepth = depth_img[v, u]p_z = depth / factorp_x = (u - cam_cx) * p_z / cam_fxp_y = (v - cam_cy) * p_z / cam_fypoint_cloud.append([p_x, p_y, p_z])point_cloud = np.array(point_cloud)return point_cloud

最近做实验,想实现深度估计到三维点云再到网格的生成,第一步做出深度图结合RGB图生成三维点云

RGB室内图:

Depth Image:(隐隐约约能过看到点什么)

生成的结果:

转个角度:

结果很粗糙,感觉这个方法不是很理想,也就是通过深度估计得到的深度图转换成点云的想法不太靠谱!

代码如下:(需要安装open3d)

from PIL import Image
import pandas as pd
import numpy as np
from open3d import read_point_cloud, draw_geometries
import timeclass point_cloud_generator():def __init__(self, rgb_file, depth_file, pc_file, focal_length, scalingfactor):self.rgb_file = rgb_fileself.depth_file = depth_fileself.pc_file = pc_fileself.focal_length = focal_lengthself.scalingfactor = scalingfactorself.rgb = Image.open(rgb_file)self.depth = Image.open(depth_file).convert('I')self.width = self.rgb.size[0]self.height = self.rgb.size[1]def calculate(self):t1=time.time()depth = np.asarray(self.depth).Tself.Z = depth / self.scalingfactorX = np.zeros((self.width, self.height))Y = np.zeros((self.width, self.height))for i in range(self.width):X[i, :] = np.full(X.shape[1], i)self.X = ((X - self.width / 2) * self.Z) / self.focal_lengthfor i in range(self.height):Y[:, i] = np.full(Y.shape[0], i)self.Y = ((Y - self.height / 2) * self.Z) / self.focal_lengthdf=np.zeros((6,self.width*self.height))df[0] = self.X.T.reshape(-1)df[1] = -self.Y.T.reshape(-1)df[2] = -self.Z.T.reshape(-1)img = np.array(self.rgb)df[3] = img[:, :, 0:1].reshape(-1)df[4] = img[:, :, 1:2].reshape(-1)df[5] = img[:, :, 2:3].reshape(-1)self.df=dft2=time.time()print('calcualte 3d point cloud Done.',t2-t1)def write_ply(self):t1=time.time()float_formatter = lambda x: "%.4f" % xpoints =[]for i in self.df.T:points.append("{} {} {} {} {} {} 0\n".format(float_formatter(i[0]), float_formatter(i[1]), float_formatter(i[2]),int(i[3]), int(i[4]), int(i[5])))file = open(self.pc_file, "w")file.write('''plyformat ascii 1.0element vertex %dproperty float xproperty float yproperty float zproperty uchar redproperty uchar greenproperty uchar blueproperty uchar alphaend_header%s''' % (len(points), "".join(points)))file.close()t2=time.time()print("Write into .ply file Done.",t2-t1)def show_point_cloud(self):pcd = read_point_cloud(self.pc_file)draw_geometries([pcd])a = point_cloud_generator('01446_colors.png', '01446_depth.png', '01446_3d.ply',focal_length=300, scalingfactor=1000)
a.calculate()
a.write_ply()
a.show_point_cloud()
df = a.df
np.save('pc.npy',df)

————————————————
版权声明:本文为CSDN博主「冷心笑看丽美人」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:

RGBD 转换成点云 open3d相关推荐

  1. RGB深度图转换成点云-三维重建001

    最近做实验,想实现深度估计到三维点云再到网格的生成,第一步做出深度图结合RGB图生成三维点云,感觉效果凑合, 供大家欣赏! RGB室内图: Depth Image:(隐隐约约能过看到点什么) 生成的结 ...

  2. 文档转换 云服务器,pdf转换成word云服务器

    pdf转换成word云服务器 内容精选 换一换 切换操作系统是为您的弹性云服务器重新切换一个系统盘.切换完成后弹性云服务器的系统盘ID会发生改变,并删除原有系统盘.如果弹性云服务器当前使用的操作系统不 ...

  3. 如何将stl模型,转换成点云文件)

    如何将stl模型,转换成点云文件) 借用cloudcompare 借用cloudcompare 步骤 :打开cloudcompare-> file->open ->你的stl文件-& ...

  4. TUM RGB-D数据集转换成点云数据

    德国慕尼黑工业大学TUM计算机视觉组2012年提出了一个RGB-D数据集,是目前应用最为广泛的RGB-D数据集.数据集使用Kinect采集,包含了depth图像和rgb图像,以及ground trut ...

  5. open3d,读取stl/ply/obj/off/gltf/glb三维模型,并转换成点云,保存

    1.三维模型获取 可以自己用建模软件建立一个模型 本案例使用模型的下载地址 可以从free3d免费下载,无需注册 2.导入open3d import open3d as o3d 3.open3d模型读 ...

  6. open3d教程(二):可视化三维模型,并转换成点云(Python版本)

    1.三维模型获取 可以自己用建模软件建立一个模型 从free3d免费下载 2.关键函数 open3d.visualization.draw_geometries 参数: geometry_list(L ...

  7. 1万字精讲,这你还学不废?Python爬取腾讯视频《斛珠夫人》弹幕,并转换成词云(单线程)——爬虫实例2

    hello,大家好,我是小浪宝宝,一个想凭借自己双手活下去的00后,想把自己的思路详细的分享给大家,励志让看到我的分享的人,一看程序就懂.

  8. 『OPEN3D』1.3 RGB-D image与点云拼接 python篇

    目录 1 open3d中的IMAGE 1.1 open3d中的image 1.2 open3d中的rgbd image 2 open3d.camera 3 RGBD图像的点云拼接 1 open3d中的 ...

  9. python基础教程廖雪峰云-Python 爬虫:把廖雪峰的教程转换成 PDF 电子书

    写爬虫似乎没有比用 Python 更合适了,Python 社区提供的爬虫工具多得让你眼花缭乱,各种拿来就可以直接用的 library 分分钟就可以写出一个爬虫出来,今天就琢磨着写一个爬虫,将廖雪峰的 ...

最新文章

  1. 计算机网络基础 1.0 -- 概述
  2. 常见的神经网络求导总结!
  3. 首尾连接的数组的求和问题
  4. git指定版本openwrt源码_[OpenWrt Wiki] LEDE源代码
  5. Frida 基础操作2
  6. SAP Spartacus 在 Github 托管虚拟机上执行的 pipeline 明细
  7. SAP Fiori Elements 应用里和 Fiori 3 相关的外观设置
  8. Linux惊群效应详解(最详细的了吧)
  9. 50种Java编程技巧,越早知道越好!(建议收藏)
  10. 惯性矩和偏心距描述器
  11. 亿级流量请求,多级缓存解救
  12. C++中用TinyXML对XML文件进行解析
  13. 记Python的一些用法
  14. CISP-PTS学习笔记-XSS
  15. vue-d2admin前端axio异步请求详情
  16. tc7102路由器虚拟服务器,电信华为tc7102路由器怎么设置
  17. 2021年3月最新-李沐-动手学深度学习第二版-中、英文版
  18. 数组 reduce 简介及使用场景
  19. DCOM Access Denied 禁止访问的解决方法
  20. Python ffmpeg视频压缩

热门文章

  1. 解决docker镜像无法删除的问题
  2. Linux中error while loading shared libraries错误解决办法
  3. 终端读写命令 -- read write wall
  4. 三维家导入户型镜像怎么使用_UG虎钳三维建模教学,认真看仔细学习了!
  5. 计算机室活动实施方案,微机室活动计划
  6. maven生成jar包,包含第三方jar包
  7. spring_在Spring中使用多个动态缓存
  8. MySQL和java连连看_用 JAVA 开发游戏连连看(之一)动手前的准备
  9. php umount强制,linux mount挂载与umount 卸载及“Device is busy”问题 | 璞玉(POOY)
  10. mysql 开启不严谨模式,mysql – 为什么innodb严格模式无法启用?