Error loading ShapeNet meshes with texture
Describe the bug When loading specific ShapeNet meshes with Open3D > 0.11, the process ends after printing 'Not a JPEG file: starts with 0x89 0x50'. In contrast, Open3D version 0.8.0 with python 3.7.9 returns a mesh.
To Reproduce Steps to reproduce the behavior: From within your ShapeNetCore.v2 directory...
- cd '02801938/d9f0f7cff584b60d826faebfb5cddf3c/models'
- source activate yourcondaenv
- python
import open3d as o3d o3d.io.read_triangle_mesh('model_normalized.obj')
- See error: Not a JPEG file: starts with 0x89 0x50
(same for this model: 03467517/2cbc0faddf227502bbc745a3524d966b/models)
Expected behavior
- A mesh is returned automatically without texture, or
- An option to not load the texture, or
- A way to catch this in python
Environment (please complete the following information):
- Operating system: RHEL8
- Python version: 3.8
- Open3D version: 0.13.0
- Is this remote workstation?: yes
- How did you install Open3D?: conda
In fact, I also meet the same bug when I used the API read_triangle_mesh in the Shapenet-v1.
And I think that maybe the .obj file has some problem.
The same issue with 02691156/de45798ef57fe2d131b4f9e586a6d334
How can we solve it? I simply removed that particular data..
It seems the error is with the texture files. If you put the .obj file in a separate folder, it loads in Open3D correctly.
If you need the textures, take a look at this answer: https://blender.stackexchange.com/questions/89010/materials-not-applied-after-importing-obj-shapenet/188192#188192 . You can convert the buggy .obj model from ShapeNet to a .glb model using https://github.com/CesiumGS/obj2gltf.
The same issue with 02691156/31b201b7346e6cd15e9e2656aff7dd5b
For more context on the ShapeNet bug (Stanford url download): it comes from png files having jpg extensions, nothing wrong with the obj file by itself. As mentioned by @Saafke, gets solved by moving to different directory.
In terms of possible fix to o3d: I am able to load the images with matplotlib though. It might be that o3d uses file extensions rather than first bytes to determine file type.
@tomas-aftalion yeah, you are right.
https://gist.github.com/leommoore/f9e57ba2aa4bf197ebc5
0x89 0x50 is png magic number.
And open3d does read based on file extension in the name and not using magic number.
https://github.com/isl-org/Open3D/blob/c7718fd626d2f446bbbf40fd552ffd424e66d7a0/cpp/open3d/io/ImageIO.cpp#L23