Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load texture file mtl into python? #12

Open
xiaodongww opened this issue Nov 22, 2021 · 1 comment
Open

How to load texture file mtl into python? #12

xiaodongww opened this issue Nov 22, 2021 · 1 comment

Comments

@xiaodongww
Copy link

Hi, thanks for your great job.

In my work, I want to extract the vertex coordinates and vertex color of the reconstructed mesh using python. However, I find it is not convenient to extract the vertex color. I have tried Open3D and it does not work.

I tried to load the *.obj using Open3D as follows:

import numpy as np
import open3d as o3d
import cv2

mesh = o3d.io.read_triangle_mesh('mesh.refined.obj', True)
img = cv2.imread('mesh.refined_0.png')
mesh.textures = [o3d.geometry.Image(img)]

vertex_colors = np.asarray(mesh.vertex_colors)  # what we want
o3d.visualization.draw_geometries([mesh])  # check if texture loaded correctly

The texture is not correctly loaded. The result seems messy.
It should looks like this
image

However, the actual visualization is as follows:
image

What tool do you use to generate the mesh.refined.mtl and mesh.refined_0.png? Do you have any idea how to extract vertex colors using python?

Any suggestion will be helpful. Thanks a lot.

@vincentcartillier
Copy link

I also had issues with loading the mesh with texture in Open3D.
Mostly my problem was that I am using open3d==0.9 because I am still under ubuntu 16 and this doesn't seem to be supported.
However I believe with newer versions it should work.

Anyhow, using trimesh should do

import trimesh

mesh = trimesh.load(mesh_filename)
mesh_colors = mesh.visual.to_color()

points = mesh.verties
colors = mesh_colors.vertex_colors

I just tried it with trimesh 3.9.43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants