at first i have to say that I'm very new to programming, especially in Open3D. I'm trying to crop a point cloud, but not as shown in the Open3D tutorial with a *.json file, but rather with a polygon volume which i created by using 4 coordinates (corner points of the 2D bounding box). My code is shown below.
model = "point_cloud.ply"
pcd = o3d.io.read_point_cloud(model)
downpcd = pcd.voxel_down_sample(voxel_size = 0.015)
corners = np.array([
[ -0.091687413867212741, -0.14071210477866827, 0.0 ],
[ 0.030980770065893004, -0.14071210477866827, 0.0 ],
[ 0.030980770065893004, -0.044064443478879611, 0.0 ],
[ -0.091687413867212741, -0.044064443478879611, 0.0 ]
])
bounding_polygon = corners.astype("float64")
vol = o3d.visualization.SelectionPolygonVolume()
vol.orthogonal_axis = "Z"
vol.axis_max = 0.81700000000000017
vol.axis_min = -2.8580000000000001
vol.bounding_polygon = o3d.utility.Vector3dVector(bounding_polygon)
Up to this line everything seems to work fine, but when I'm trying to use this polygon volume to crop my loaded point cloud with this function I always recieve an error.
cropped_pcd = vol.crop_point_cloud([downpcd])
This is the error i get:
Traceback (most recent call last):
File "c:\Users\Privat\Desktop\User\PCD\CropPCDByCoordinates.py", line 42, in <module>
cropped_pcd = vol.crop_point_cloud([downpcd])
TypeError: crop_point_cloud(): incompatible function arguments. The following argument types are supported:
1. (self: open3d.cpu.pybind.visualization.SelectionPolygonVolume, input: open3d.cpu.pybind.geometry.PointCloud) -> open3d.cpu.pybind.geometry.PointCloud
Invoked with: SelectionPolygonVolume, access its members:
orthogonal_axis, bounding_polygon, axis_min, axis_max, [PointCloud with 364980 points.]
When I'm using a *.json file with the same information everything works fine, but I would like to crop it without loading a *.json file.
This is the *.json file where i got my information from:
{
"axis_max" : 0.81700000000000017,
"axis_min" : -2.8580000000000001,
"bounding_polygon" :
[
[ -0.091687413867212741, -0.14071210477866827, 0.0 ],
[ 0.030980770065893004, -0.14071210477866827, 0.0 ],
[ 0.030980770065893004, -0.044064443478879611, 0.0 ],
[ -0.091687413867212741, -0.044064443478879611, 0.0 ]
],
"class_name" : "SelectionPolygonVolume",
"orthogonal_axis" : "Z",
"version_major" : 1,
"version_minor" : 0
}
Any advice and/or explanation how to avoid this error would be appreciated. Thanks.
I'm using Python 3.9 in MS Visual Studio Code on Windows 10.