Hi everyone,
I’m trying to create a point cloud visualization in Streamlit using the following code:
def pcd_visualization(self):
try:
uploaded_file = st.file_uploader("Choose a PCD file", type=["pcd"])
if uploaded_file is not None:
# Load point cloud from temporary file
pcd = o3d.io.read_point_cloud(uploaded_file)
# Check if point cloud contains data
if len(pcd.points) == 0:
st.warning("The PCD file does not contain any points.")
return
# Convert point cloud to numpy array
points = np.asarray(pcd.points)
# Create a plot using PyVista
cloud = pv.PolyData(points)
if cloud.n_points == 0:
st.warning("The point cloud resulted in an empty mesh.")
return
plotter = pv.Plotter()
plotter.add_mesh(cloud, color='white', point_size=2)
plotter.view_isometric()
plotter.show_bounds(grid='front', location='all', color='gray')
# Display the visualization in Streamlit
stpyvista(plotter, key="3d_plot")
except Exception as e:
st.error(f"Error visualizing the point cloud: {e}")
However, the visualization does not seem to work as expected. The file uploader works, but the point cloud is not displayed. I’m not sure if I’m missing something or if there’s an issue with how I’m integrating PyVista with Streamlit.
Could someone please help me understand what might be going wrong and how to fix it?
Thanks in advance!
Feel free to adjust the question as needed.