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

相关文章

pyqt5使用按钮进行界面的跳转方法

简介 进行按钮进行界面的跳转,我这里面我介绍两种,一种是没有使用Qtdesigner的代码,另一种是使用Qtdesigner的代码 代码1 import sys from PyQt5...

python中 ? : 三元表达式的使用介绍

(1) variable = a if exper else b(2)variable = (exper and [b] or [c])[0](2) variable = exper a...

Python利用itchat对微信中好友数据实现简单分析的方法

Python利用itchat对微信中好友数据实现简单分析的方法

前言 最近在一个微信公众号上看到一个调用微信 API 可以对微信好友进行简单数据分析的一个包 itchat 感觉挺好用的,就简单尝试了一下。 库文档说明链接在这: itchat 安装 在...

Django 通过JS实现ajax过程详解

ajax的优缺点 AJAX使用Javascript技术向服务器发送异步请求 AJAX无须刷新整个页面 因为服务器响应内容不再是整个页面,而是页面中的局部,所以AJAX性能高 小练习:计算...

Python通过Pygame绘制移动的矩形实例代码

Python通过Pygame绘制移动的矩形实例代码

Pygame是一个多用于游戏开发的模块。 本文实例主要是在演示框里实现一个移动的矩形实例代码,完整代码如下: #moving rectangle project import py...