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

Projection of color images onto a mesh #14

Open
Grimwork opened this issue Sep 19, 2023 · 1 comment
Open

Projection of color images onto a mesh #14

Grimwork opened this issue Sep 19, 2023 · 1 comment

Comments

@Grimwork
Copy link

Hi,

I have seen in your README.md that you present a use case where you project an image's color onto a mesh.

And i wanted to know how did you do that ?
Did you programmatically add the color of each pixel on each point ?

@marip8
Copy link
Collaborator

marip8 commented Sep 19, 2023

  • transform the mesh into camera coordinates
  • project mesh into camera using camera matrix
  • for each projected vertex
    • convert floating point projected vertex to integers to create u-v coordinates
    • index into color image at projected vertex u-v coordinate to get color for vertex
    • add color info to original mesh vertex

Here's a snippet of some Python psuedocode for doing this

# Get transform from camera to mesh (using TF)
camera_to_mesh = ...

# Extract camera matrix from ROS camera info message
camera_matrix = np.array(camera_info.P).reshape((3, 4))
  
# Put mesh vertices into homogenous coordinates (i.e., [x, y, z, 1])
verts = np.vstack([mesh_verts.T, np.ones((mesh_verts.shape[0],))])

# Project the mesh vertices into the camera frame
projected_verts = camera_matrix @ camera_to_mesh @ verts
projected_verts /= projected_verts[2, :]

# Convert to u-v coordinates
vert_coords = projected_verts[:2, :].T.astype(int)

# Extract the colors from the image
colors = image[vertex_coords[:, 1], vertex_coords[:, 0]]

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