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

yipeiwu_com4年前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设计】。

相关文章

详解Python的Django框架中的Cookie相关处理

浏览器的开发者在很早的时候就已经意识到, HTTP's 的无状态会对Web开发者带来很大的问题,于是(cookies)应运而生。 cookies 是浏览器为 Web 服务器存储的一小段信...

Python DataFrame设置/更改列表字段/元素类型的方法

Python DataFrame设置/更改列表字段/元素类型的方法

Python DataFrame 如何设置列表字段/元素类型? 比如笔者想将列表的两个字段由float64设置为int64,那么就要用到DataFrame的astype属性,举例如图:...

python学习之编写查询ip程序

python学习之编写查询ip程序

公司服务器上的ip最少的也有100多个,有时候查到一个站的Ip, 不想通过OA去查,自己就用自己最近学的python知识,结合数据库,编写了一python小程序。实现只要输入主ip就能查...

深入解析Python小白学习【操作列表】

1.遍历列表 需要对列表中的每个元素都执行相同的操作时,可使用for 循环: magicians = ['alice','david','carolina'] for magicia...

Django静态资源URL STATIC_ROOT的配置方法

缘由   新手学习 Django 当配置好 HTML 页面后,就需要使用一些静态资源,如图片,JS 文件,CSS 样式等,但是 Django 里面使用这些资源并不是直接引用一下就好,还要...