open-forest-observatory / geograypher

Multiview Semantic Reasoning with Geospatial Data
BSD 3-Clause "New" or "Revised" License
10 stars 4 forks source link

'NoneType' has no len() While Loading Mesh and camera.XML #87

Closed matebene closed 3 months ago

matebene commented 4 months ago

Hi, I'm new to this package and currently just testing out the given examples in the repo. I have a problem with mesh loading in the aggregate_predictions notebook.

I've used the following code and my own mesh and .XML file for the mesh load and got an error

MESH_FILENAME="C:\\Users\\Huawei\\Desktop\\Drone processing\\multiview-mapping-toolkit-main\\data\\example_Emerald_Point_data\\inputs\\kastely_mesh.ply"

EXAMPLE_CAMERAS_FILENAME="C:\\Users\\Huawei\\Desktop\\Drone processing\\multiview-mapping-toolkit-main\\data\\example_Emerald_Point_data\\inputs\\kastely_cameras.xml"

mesh = TexturedPhotogrammetryMesh(
    MESH_FILENAME, transform_filename=EXAMPLE_CAMERAS_FILENAME, IDs_to_labels=IDS_TO_LABELS
)

This is the error code I think the problem is with the kastely_cameras.xml I've used Metashape for the export and followed the instructions in the readme


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[59], [line 1](vscode-notebook-cell:?execution_count=59&line=1)
----> [1](vscode-notebook-cell:?execution_count=59&line=1) mesh = TexturedPhotogrammetryMesh(
      [2](vscode-notebook-cell:?execution_count=59&line=2)     MESH_FILENAME, transform_filename=EXAMPLE_CAMERAS_FILENAME, IDs_to_labels=IDS_TO_LABELS
      [3](vscode-notebook-cell:?execution_count=59&line=3) )

File [c:\Users\Huawei\anaconda3\envs\pytorch3d\lib\site-packages\multiview_mapping_toolkit\meshes\meshes.py:105](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:105), in TexturedPhotogrammetryMesh.__init__(self, mesh, downsample_target, transform_filename, texture, texture_column_name, IDs_to_labels, ROI, ROI_buffer_meters, require_transform, log_level)
    [103](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:103) # Load the transform
    [104](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:104) self.logger.info("Loading transform to EPSG:4326")
--> [105](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:105) self.load_transform_to_epsg_4326(
    [106](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:106)     transform_filename, require_transform=require_transform
    [107](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:107) )
    [108](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:108) # Load the mesh with the pyvista loader
    [109](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:109) self.logger.info("Loading mesh")

File [c:\Users\Huawei\anaconda3\envs\pytorch3d\lib\site-packages\multiview_mapping_toolkit\meshes\meshes.py:186](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:186), in TexturedPhotogrammetryMesh.load_transform_to_epsg_4326(self, transform_filename, require_transform)
    [183](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:183)     return
    [185](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:185) elif Path(transform_filename).suffix == ".xml":
--> [186](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:186)     self.local_to_epgs_4978_transform = parse_transform_metashape(
    [187](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:187)         transform_filename
    [188](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:188)     )
    [189](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:189) elif Path(transform_filename).suffix == ".csv":
    [190](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:190)     self.local_to_epgs_4978_transform = np.loadtxt(
    [191](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:191)         transform_filename, delimiter=","
    [192](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/meshes/meshes.py:192)     )

File [c:\Users\Huawei\anaconda3\envs\pytorch3d\lib\site-packages\multiview_mapping_toolkit\utils\parsing.py:39](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:39), in parse_transform_metashape(camera_file)
     [36](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:36) # first level
     [37](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:37) components = root.find("chunk").find("components")
---> [39](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:39) assert len(components) == 1
     [40](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:40) transform = components.find("component").find("transform")
     [42](file:///C:/Users/Huawei/anaconda3/envs/pytorch3d/lib/site-packages/multiview_mapping_toolkit/utils/parsing.py:42) rotation = transform.find("rotation").text

TypeError: object of type 'NoneType' has no len()
``
russelldj commented 4 months ago

Thanks for your interest in this project. I agree, there's probably something wrong with your exported camera file. Specifically, it looks like the components field is probably missing in the .xml file. Is this file something you are willing to share? I also have some other questions that might help with debugging.

matebene commented 4 months ago

Thanks for the assist.

  1. The project is geo-referenced, we used the GPS data of the images
  2. The metashape version is 1.5.1
  3. I was able to run the code with the example data Here is the link for the .XML file
russelldj commented 4 months ago

Thanks for sharing that, it does appear that the issue is the camera file. The components field is indeed missing from the chunk. Since this project is georeferenced, I assume this comes down to a metashape version issue. We use metashape version 2.0.0, if you have access to that, maybe give it a try.

The big picture issue here is both the camera information and the "local" mesh export are defined in an arbitrary coordinate frame that is used for metashape processing. We need to relate this coordinate frame to geospatial coordinates to do operations like adding geospatial labels to the mesh. Usually the camera file contains information to transform this arbitrary coordinate system into the earth-centered, earth-fixed frame, EPSG:4978. But I cannot find it anywhere in the file you exported.

The easiest solution is if you can get the metashape export working with a different version. But if not, we can try the following. The mesh you currently have should be in the same "local" coordinate system as the camera. If we get a second mesh in geospatial coordinates, we can compute the transform between them. You should be able to select a geospatial option when you export the mesh. I can write a script to estimate this transform, but it might be a bit before I have time. We can directly provide this transform as the transform_filename argument in the TexturedPhotogrammetryMesh constructor if we save it as a .csv file containing a 4x4 homogeneous transformation matrix.

russelldj commented 3 months ago

Did this fix your issue? If not, I'm happy to try to help out.

russelldj commented 3 months ago

Closing since no response, feel free to reopen if you need help.