isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.55k stars 2.32k forks source link

Segmentation fault for o3d.utility.Vector3dVector() constructor #6993

Open subhamsahoo-ase opened 1 month ago

subhamsahoo-ase commented 1 month ago

Checklist

Describe the issue

I'm trying to visualize a point cloud from a .laz file. I used laspy to extract the pcd points, then used numpy to convert the points into an array. The problem I'm encountering is a segmentation error whenever I try to replace the empty points in the point cloud object with the numpy array. I commented out the converted array and used a simple 3x3 array to see if the o3d.utility.Vector3dVector(pcd_numpy) is taking into too large of a size. Still got the error. I came across a comment saying try to use open3d==0.17.0 and python3.10. Still got the error. I tried installing open3d via pip in conda and I also tried installing via wheel from both the latest and second latest releases.

Steps to reproduce the bug

#import earthaccess as ea
#import h5py
#import pandas as pd
import laspy 
import open3d as o3d
import numpy as np

"""
ea.login()

test_results = ea.search_data(
    short_name = 'ATL03',
    bounding_box = (33, 38.8, 76, 84),
    count = 10
)

files = ea.download(test_results, './data')
"""

# open .h5 file
'''
with h5py.File('./data/ATL03_20181014002445_02350104_006_02.h5') as file:
    # list all groups in the file
    data  = file['gt1l/heights/h_ph']
    # print keys for each level
    for key in file.keys():
        print(key)

    # convert to pandas dataframe
    df = pd.DataFrame(data)
    print(df.head())
'''

with laspy.open('./data/USGS/USGS_LPC_TX_Central_B1_2017_stratmap17_50cm_3097494d3_LAS_2019.laz') as fh:
    print('Points from header:', fh.header.point_count)
    las = fh.read()

x = las.x[:100] 
y = las.y[:100]
z = las.z[:100]

for i in range(5):
    print(f"Point {i}: ({x[i]}, {y[i]}, {z[i]})")    

#pcd_numpy = np.vstack((las.x, las.y, las.z)).transpose()
pcd_numpy = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1]])
pcd = o3d.geometry.PointCloud()

pcd = o3d.utility.Vector3dVector(pcd_numpy)
o3d.visualization.draw([pcd], point_size=2)

Error message

Points from header: 27806620 Point 0: (605353.65, 3334862.61, 255.43) Point 1: (605353.74, 3334862.98, 258.03000000000003) Point 2: (605353.9, 3334862.83, 258.72) Point 3: (605353.63, 3334862.5700000003, 258.71) Point 4: (605353.67, 3334863.14, 251.84) zsh: segmentation fault /Users/subhamsahoo/Documents/SatCNN/.venv/bin/python

Expected behavior

I'm expecting to see a viewer pop up showing the point cloud.

Open3D, Python and System information

- Operating system: Ubuntu 20.04 / macOS 12.7 / Windows 10 64-bit
- Python version: 3.10
- Open3D version: output from python: 0.17.0
- System architecture: x86 
- Is this a remote workstation?: no
- How did you install Open3D?: pip and conda

Additional information

No response

subhamsahoo-ase commented 1 month ago

Downgrade numpy version to 1.24.4 to solve o3d.utilities.Vector3dVector() segmentation fault

ChihaoZhang commented 1 month ago

@subhamsahoo-ase Thanks for pointing out the reason is numpy version which saves me a lot of time. I met the same problem when trying to set camera intrinsic and extrinsic matrices. A further test shows the supported version should be numpy<2.0.0. And in fact, this problem is mentioned before, refer to #6879, though I have no idea when it will be solved for users like me who just install open3d using the most convenient way pip install open3d. 😂