Reputation: 1
I write a code for snap_shot 10 images of 2D from 3D Face by pymeshlab but the results only contain all images with white face. I need the original color of the face I see on app MeshLab. How can I add function for my code
import pymeshlab
# Đường dẫn đến file mô hình 3D
file_path = r"C:\Users\asus\AppData\Local\Programs\Microsoft VS Code\Deep3DFaceRecon_pytorch\checkpoints\model20\results\datasets\examples\epoch_20_000000\000002.obj"
# Tạo đối tượng MeshLab
ms = pymeshlab.MeshSet()
# Tải file mô hình 3D
ms.load_new_mesh(file_path)
# Đảm bảo sử dụng màu của vertices
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
# 1. Xoay từ phải qua trái (3 lần)
for i in range(3):
# Tải lại file mô hình sau mỗi lần chụp
ms.load_new_mesh(file_path)
# Đảm bảo sử dụng màu từ các vertices
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
angle = 30 * (i + 1) # Xoay từ phải qua trái (mỗi lần 30 độ)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=angle,
freeze=True)
output_filename = f"output000002_right_to_left_{i+1}.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
# 2. Xoay từ trái qua phải (3 lần)
for i in range(3):
# Tải lại file mô hình sau mỗi lần chụp
ms.load_new_mesh(file_path)
# Đảm bảo sử dụng màu từ các vertices
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
angle = -30 * (i + 1) # Xoay từ trái qua phải (mỗi lần -30 độ)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=angle,
freeze=True)
output_filename = f"output000002_left_to_right_{i+1}.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
# 3. Xoay về hướng Đông Bắc (1 lần)
ms.load_new_mesh(file_path)
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=45, # Xoay về hướng Đông (45 độ)
freeze=True)
ms.compute_matrix_from_rotation(rotaxis='X axis',
rotcenter='origin',
angle=30, # Xoay về hướng Bắc (30 độ)
freeze=True)
output_filename = f"output000002_northeast_1.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
# 4. Xoay về hướng Tây Bắc (1 lần)
ms.load_new_mesh(file_path)
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=-45, # Xoay về hướng Tây (45 độ)
freeze=True)
ms.compute_matrix_from_rotation(rotaxis='X axis',
rotcenter='origin',
angle=30, # Xoay về hướng Bắc (30 độ)
freeze=True)
output_filename = f"output000002_northwest_1.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
# 5. Xoay về hướng Tây Nam (1 lần)
ms.load_new_mesh(file_path)
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=-45, # Xoay về hướng Tây (45 độ)
freeze=True)
ms.compute_matrix_from_rotation(rotaxis='X axis',
rotcenter='origin',
angle=-30, # Xoay về hướng Nam (30 độ)
freeze=True)
output_filename = f"output000002_southwest_1.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
# 6. Xoay về hướng Đông Nam (1 lần)
ms.load_new_mesh(file_path)
ms.apply_filter("compute_color_from_scalar_using_transfer_function_per_vertex",
tfslist=1)
ms.compute_matrix_from_rotation(rotaxis='Y axis',
rotcenter='origin',
angle=45, # Xoay về hướng Đông (45 độ)
freeze=True)
ms.compute_matrix_from_rotation(rotaxis='X axis',
rotcenter='origin',
angle=-30, # Xoay về hướng Nam (30 độ)
freeze=True)
output_filename = f"output000002_southeast_1.png"
ms.save_snapshot(imagefilename=output_filename)
print(f"Snapshot saved as {output_filename}")
print("All snapshots saved.")
Results on Meshlab app: enter image description here Results on the code below: enter image description here
Function adding on code
Upvotes: 0
Views: 25