Python实现点云投影到平面显示

yipeiwu_com5年前Python基础

值得学习的地方:

1.选择合法索引的方式

2.数组转图像显示

import numpy as np
from PIL import Image

#input : shape(N, 4)
#    (x, y, z, intensity)
def pointcloud2image(point_cloud):
  x_size = 640
  y_size = 640
  x_range = 60.0
  y_range = 60.0
  grid_size = np.array([2 * x_range / x_size, 2 * y_range / y_size])
  image_size = np.array([x_size, y_size])
  # [0, 2*range)
  shifted_coord = point_cloud[:, :2] + np.array([x_range, y_range])
  # image index
  index = np.floor(shifted_coord / grid_size).astype(np.int)
  # choose illegal index
  bound_x = np.logical_and(index[:, 0] >= 0, index[:, 0] < image_size[0])
  bound_y = np.logical_and(index[:, 1] >= 0, index[:, 1] < image_size[1])
  bound_box = np.logical_and(bound_x, bound_y)
  index = index[bound_box]
  # show image
  image = np.zeros((640, 640), dtype=np.uint8)
  image[index[:, 0], index[:, 1]] = 255
  res = Image.fromarray(image)
  # rgb = Image.merge('RGB', (res, res, res))
  res.show()

以上这篇Python实现点云投影到平面显示就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Django模板导入母版继承和自定义返回Html片段过程解析

1.ROOT_URLCONF = '总路由所在路径(比如untitled.urls)'<===默认情况是这样 根路由的路径是可以修改的:ROOT_URLCONF = app01.u...

python列表,字典,元组简单用法示例

本文实例讲述了python列表,字典,元组简单用法。分享给大家供大家参考,具体如下: 列表 #_*_ coding:utf-8 _*_ # 列表,定义在方括号的形式中,可以进行切片操...

Python多线程实现同步的四种方式

临界资源即那些一次只能被一个线程访问的资源,典型例子就是打印机,它一次只能被一个程序用来执行打印功能,因为不能多个线程同时操作,而访问这部分资源的代码通常称之为临界区。 锁机制 thre...

Python中的zipfile模块使用详解

zip文件格式是通用的文档压缩标准,在ziplib模块中,使用ZipFile类来操作zip文件,下面具体介绍一下: class zipfile.ZipFile(file[, mode[,...

Python如何筛选序列中的元素的方法实现

本篇文章给大家带来的内容是关于Python如何筛选序列中的元素 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。 1、需求 序列中含有一些数据,我们需要提取其中的值或...