jeremybyu / polylidar Goto Github PK
View Code? Open in Web Editor NEWPolylidar3D - Fast polygon extraction from 3D Data
Home Page: https://jeremybyu.github.io/polylidar/
License: MIT License
Polylidar3D - Fast polygon extraction from 3D Data
Home Page: https://jeremybyu.github.io/polylidar/
License: MIT License
Hey all,
I am trying to use this repository for the first time, and followed the Python documentation to test a pointcloud of my own. But I could not get any planes in the output. This might be a kwargs issue, which I feel is more of a trial and error task but do you think that might be causing this issue? In that case, what would be your solution and how do i get to these optimum argument values for alpha, lmax, z_threshold and others?
This is the code i am using and I am also attaching a link to the pointcloud in discussion
import polylidar
import math
import numpy as np
from polylidar import MatrixDouble, Polylidar3D
import laspy
import time
import matplotlib.pyplot as plt
from polylidar.polylidarutil import (generate_test_points, plot_triangles, get_estimated_lmax,
plot_triangle_meshes, get_triangles_from_list, get_colored_planar_segments, plot_polygons)
from polylidar.polylidarutil import (plot_polygons_3d, generate_3d_plane, set_axes_equal, plot_planes_3d,
scale_points, rotation_matrix, apply_rotation)
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Read LAS file
# las_file_path = 'house1.las'
las_file_path = '/home/tarun/Downloads/house1.las'
las_file = laspy.read(las_file_path)
# Extract x, y, and z coordinates from the LAS points
points = np.vstack((las_file.x, las_file.y, las_file.z)).transpose()
polylidar_kwargs = dict(alpha=0.0, lmax=10, min_triangles=20, z_thresh=0.0, norm_thresh_min=0.94)
polylidar = Polylidar3D(**polylidar_kwargs)
points_mat = MatrixDouble(points, copy=False)
t1 = time.time()
mesh, planes, polygons = polylidar.extract_planes_and_polygons(points_mat)
t2 = time.time()
print("Took {:.2f} milliseconds".format((t2 - t1) * 1000))
triangles = np.asarray(mesh.triangles)
fig, ax = plt.subplots(figsize=(10, 10), nrows=1, ncols=1,
subplot_kw=dict(projection='3d'))
# plot all triangles
plot_planes_3d(points, triangles, planes, ax)
plot_polygons_3d(points, polygons, ax)
# plot points
ax.scatter(*scale_points(points), c='k', s=0.1)
set_axes_equal(ax)
ax.view_init(elev=15., azim=-35)
plt.show()
print("")
Link to the pointcloud: https://drive.google.com/file/d/1xuPerTlJ4ScAXkhR_WyrzlSHmZ4KAhYZ/view?usp=sharing
The installation instructions provide a link to download the Example\Fixture\Data from GoogleDrive, but unfortunately this link is not working.
Is there an alternative download link?
Thank you.
I would like to suggest a new feature to be able to convert a lidar .las / .laz to a .tif file.
Describe the bug
When running the realsense_mesh.py script, I get an error suggesting an incorrect argument type on a call to rotate():
File "examples/python/realsense_mesh.py", line 196, in <module>
main()
File "examples/python/realsense_mesh.py", line 188, in main
pcd = pcd.rotate(R_Standard_d400[:3, :3], center=False)
TypeError: rotate(): incompatible function arguments. The following argument types are supported:
1. (self: open3d.open3d_pybind.geometry.Geometry3D, R: numpy.ndarray[float64[3, 3]], center: numpy.ndarray[float64[3, 1]]) -> open3d.open3d_pybind.geometry.Geometry3D
Invoked with: geometry::PointCloud with 24259 points., array([[ 1., 0., 0.],
[ 0., 0., 1.],
[ 0., -1., 0.]]); kwargs: center=FalseTraceback (most recent call last):
File "examples/python/realsense_mesh.py", line 196, in <module>
main()
File "examples/python/realsense_mesh.py", line 188, in main
pcd = pcd.rotate(R_Standard_d400[:3, :3], center=False)
TypeError: rotate(): incompatible function arguments. The following argument types are supported:
1. (self: open3d.open3d_pybind.geometry.Geometry3D, R: numpy.ndarray[float64[3, 3]], center: numpy.ndarray[float64[3, 1]]) -> open3d.open3d_pybind.geometry.Geometry3D
Invoked with: geometry::PointCloud with 24259 points., array([[ 1., 0., 0.],
[ 0., 0., 1.],
[ 0., -1., 0.]]); kwargs: center=False
To Reproduce
Steps to reproduce the behavior:
Simply run realsense_mesh.py.
Expected behavior
I think the problem is that somewhere along the way, an open3d point cloud is being passed around rather than a numpy array, or vice-versa. Obviously, the expected behavior is that it shouldn't crash, but I haven't been able to sort out where exactly the wrong type starts being used.
Environment (please complete the following information):
Additional context
Add any other context about the problem here.
Hi @JeremyBYU, thank you for sharing your awesome work. I would like to achieve what you did in polylidar-realsense
using ROS and C++. However, the C++ tutorials are empty and the c++ example (simple.cpp) might be too simple to let me figure out how to deal with the streaming 3D point cloud. Therefore, could you give me some advice on how to do it?
I followed the steps on Polylidar3D installation. But get the error
ImportError: cannot import name 'MatrixDouble'
when running the line
from polylidar import MatrixDouble, Polylidar3D
I am currently running Python version 3.6.13 on a Windows 11 OS with an x86_64 architecture. I am utilizing WSL to run the Python environment.
Describe the bug
Trying to run the python example robust.py throws an error Traceback (most recent call last): File "robust.py", line 7, in <module> from tests.python.helpers.utils import load_csv ModuleNotFoundError: No module named 'tests'
I have built everything from the source and did not install using pip command
Environment (please complete the following information):
Thanks in advance
Using Polylidar with Python 3.8 on MacOS. I get "Segmentation fault" when calling extract_point_cloud_from_float_depth()
function. Tried both OrganizedDemo.ipynb
and in polylidar-realsense's capture
Environment
On both Ubuntu x64 and ARM, it works correctly. issue only on MacOS (intel)
I get the following error "No module named 'polylidar.polylidar' " trying to run the example file basic2d.py on python3.6 on Ubuntu 18.04.5 LTS
Traceback (most recent call last):
File "", line 1, in
File "/home/priyas/polylidar-master/cmake-build/lib/python_package/polylidar/init.py", line 1, in
from .polylidar import * # py2 py3 compatible
ModuleNotFoundError: No module named 'polylidar.polylidar'
Polylidar installation was complete without errors
O/P of ./bin/polylidar-simple
Very Simple C++ Example of Polylidar3D on 2D Point Set
Polylidar took 0 milliseconds processing a 5 point cloud
Point indices of Polygon Shell: [3,0,1,2]
Installation was tried both on virtual environment and directly ; both gives No module error.
Installation on Windows platform works well. I could run the example files successfully.
Earlier I had tried polylidar old verison on Ubuntu and all worked well. Switching to Polylidar3D to address large Pointcloud 3d data.
Any insight to this would be of great help , Thanks in advance
Hi,
I have compiled successfully, however I can't run polylidar-simple, cloud you please tell me what's the problem?
recent:///caaa6a1ad59055fe9355edc15ea904c1
Thanks for the awesome repo.
I used the extractPolygons. In some data, the function can extract polygon, but in some cases, it returns empty?
I don't understand, why? is there role of the mentioned parameters?
Describe the bug
Shapely with shapely 2.0 updated but the library descartes didn't follow the update.
As result, polylidar fails
In 2022 with shapely 1.8 was warning about the deprecation:
ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.
vertices = concatenate([
The problem is on line 62 of patch.py.
I suggest to remove the integration with descartes (only few lines of code) and integrate the fixed version of PolygonPath, Polygon, PolygonPatch directly in polylidar.
This is the fixed version of patch.py since descartes looks like dead.
"""Paths and patches"""
from matplotlib.patches import PathPatch
from matplotlib.path import Path
from numpy import asarray, concatenate, ones
class Polygon(object):
# Adapt Shapely or GeoJSON/geo_interface polygons to a common interface
def __init__(self, context):
if isinstance(context, dict):
self.context = context['coordinates']
else:
self.context = context
@property
def exterior(self):
return (getattr(self.context, 'exterior', None)
or self.context[0])
@property
def interiors(self):
value = getattr(self.context, 'interiors', None)
if value is None:
value = self.context[1:]
return value
def PolygonPath(polygon):
"""Constructs a compound matplotlib path from a Shapely or GeoJSON-like
geometric object"""
def coding(ob):
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
# beginning of each subpath
n = len(getattr(ob, 'coords', None) or ob)
vals = ones(n, dtype=Path.code_type) * Path.LINETO
vals[0] = Path.MOVETO
return vals
if hasattr(polygon, 'geom_type'): # Shapely
ptype = polygon.geom_type
if ptype == 'Polygon':
polygon = [Polygon(polygon)]
elif ptype == 'MultiPolygon':
polygon = [Polygon(p) for p in polygon]
else:
raise ValueError(
"A polygon or multi-polygon representation is required")
else: # GeoJSON
polygon = getattr(polygon, '__geo_interface__', polygon)
ptype = polygon["type"]
if ptype == 'Polygon':
polygon = [Polygon(polygon)]
elif ptype == 'MultiPolygon':
polygon = [Polygon(p) for p in polygon['coordinates']]
else:
raise ValueError(
"A polygon or multi-polygon representation is required")
vertices = concatenate([
concatenate([asarray(t.exterior.coords)[:, :2]] +
[asarray(r)[:, :2] for r in t.interiors])
for t in polygon])
codes = concatenate([
concatenate([coding(t.exterior.coords)] +
[coding(r) for r in t.interiors]) for t in polygon])
return Path(vertices, codes)
def PolygonPatch(polygon, **kwargs):
"""Constructs a matplotlib patch from a geometric object
The `polygon` may be a Shapely or GeoJSON-like object with or without holes.
The `kwargs` are those supported by the matplotlib.patches.Polygon class
constructor. Returns an instance of matplotlib.patches.PathPatch.
Example (using Shapely Point and a matplotlib axes):
>>> b = Point(0, 0).buffer(1.0)
>>> patch = PolygonPatch(b, fc='blue', ec='blue', alpha=0.5)
>>> axis.add_patch(patch)
"""
return PathPatch(PolygonPath(polygon), **kwargs)
To Reproduce
Just pip install and run the example basic2d.py
Environment (please complete the following information):
Every environment and version
I am trying to install the polylidar python package on Windows (Python 3.7; conda 4.9.2).
I first conda install shapely
(version 1.7.1) and then pip install polylidar
(version 0.0.8).
The installations seem to succeed. However, when I try to import polylidar in Python, I get the following error message: ModuleNotFoundError: No module named 'polylidar.polylidar'
I highly appreciate any advice, thanks in advance!
I need to calculate the concave hull. I would like to use your repo to calculate due to faster than other packages.
Would you give a way to calculate concave hull using polylidar?
Thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.