Library for detecting lines in a 3D point cloud via Hough transform.
Project description
hough3d
This is a python library to perform a Hough transform to detect lines in 3D point clouds. We implement the iterative algorithm described in Dalitz et al. (2017):
- Direction vectors in 3D are discretized as the position vectors for the vertices of a tessellated icosahedron.
- All points in the point cloud vote, generating the Hough space representation.
- The highest voted line is selected, and the points surrounding that line are identified.
- Linear regression is performed on the selected points to refine the line parameters.
- All of the votes contributed by the selected points are subtracted from Hough space.
- Steps 3-5 are repeated until there are no satisfactory lines remaining.
This method has the advantage of being able to identify numerous lines without the computational burden of recalculating the entire Hough space each time.
The authors of the cited paper have implemented a C++ version here. I am currently working on trying to improve the algorithm specifically to detect line segments accurately, but for now this library functions equivalently to the C++ one. Functions are transpiled with numba, so there shouldn't be a huge difference in computation time despite this one being written in Python.
Usage
pip install hough3d
For test data, I would recommend looking at the datasets in the C++ repo.
from hough3d import hough3D
data = np.genfromtxt('data.csv', delimiter=',')
# Determines how many tesselations of the icosahedron
# to perform; larger number means more fine direction
# discretization, but larger computation time.
# See genIcosahedron docs for exact numbers.
directionGranularity = 4
directionVectors = genIcosahedron(directionGranularity)
# See docs for specific info on kwargs; generally
# these need to be chosen for each specific dataset.
linePoints = hough3D(data, directionVectors, latticeSize=128,
neighborDistance=0.01, minPointsPerLine=5)
And then visualize the results:
import open3d as o3d
flattenedLinePoints = linePoints.reshape((len(linePoints)*2, 3))
lineSet = o3d.geometry.LineSet()
lineSet.points = o3d.utility.Vector3dVector(flattenedLinePoints)
lineSet.lines = o3d.utility.Vector2iVector([[i,i+1] for i in range(len(flattenedLinePoints))[::2]])
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(data)
o3d.visualization.draw_geometries([lineSet, pcd])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hough3d-1.0.0.tar.gz
.
File metadata
- Download URL: hough3d-1.0.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63fb87ca4e6f9ad725194a9bf7c584456ee75beb17b79e9fa626f04fbd8e75c0 |
|
MD5 | 82683fc750edb6bfa52bae064b1fc078 |
|
BLAKE2b-256 | 217fae4bac251148b4a0670a4179d31258a6eee8e49b91f428581a37d48fc1c6 |
File details
Details for the file hough3d-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: hough3d-1.0.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8658c62592a0ef450fff47bf995742b4f322b225b0ef1e17794e9164ee324878 |
|
MD5 | 9b952b1c2a6d780a943e57aa6ece9a2d |
|
BLAKE2b-256 | 90a15ac1b0509aff321a628f4626764eaec972e4002756e2e2968c9e57963672 |