Hi Everyone,
I am trying to use the Metashape Python API to generate 3D Meshes using raw images. However, whenever I try to export the models they do not contain any color information. I have tried exporting them as
OBJ and
PLY files, however, both do not seem to contain the RGB color data in the final output. When I load the files into a viewer the model does not have any color information.
Here is the code I am using to generate the Meshes, feel free to point out if any part is missing:
# create new project
doc = Metashape.Document()
doc.save(path = '/home/ubuntu/metashape/project')
# chunk to add photos
if len(doc.chunks):
chunk = doc.chunk
else:
chunk = doc.addChunk()
# loading images
image_list = os.listdir(photos_dir)
photo_list = list()
for photo in image_list:
if photo.rsplit(".", 1)[1].lower() in ["jpg", "jpeg", "tif", "tiff"]:
photo_list.append("/".join([photos_dir, photo]))
# add photos to chunk
chunk.addPhotos(photo_list)
# align photos 0- highest 1-high 2- medium
chunk.matchPhotos(downscale=0, generic_preselection=True, reference_preselection=False)
# align cameras
chunk.alignCameras()
# build DepthMaps 1- ultra high 2- high
chunk.buildDepthMaps(downscale=1, filter_mode=Metashape.AggressiveFiltering)
# build model
#face count/2 equals no. of vertices.
chunk.buildModel(surface_type=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation,source_data=Metashape.DepthMapsData,face_count=Metashape.CustomFaceCount,face_count_custom=16000000,vertex_colors=True)
chunk.buildUV(mapping_mode=Metashape.GenericMapping)
# Add Texture
chunk.buildTexture(blending_mode=Metashape.MosaicBlending, texture_size=4096, fill_holes=True)
# export
chunk.exportModel(export_model_path, format =Metashape.ModelFormat.ModelFormatOBJ)
#chunk.exportModel(export_pointcloud_path, format =Metashape.ModelFormat.ModelFormatPLY)
print ('Processing complete')
Have also tried exporting the model right after the
buildModel step but that too does not contain colors.
I have installed the python library using this command
python3 -m pip install <file_name>.whl
and I have tried the following versions:
- Metashape-1.7.3
- Metashape-1.6.6
Both seem to be causing the same issue.
For reference, I have followed similar steps to create Meshes on the Windows Desktop version and the exported meshes turnout just fine.
System Info:
OS: Ubuntu 18.04
Python: 3.6
Looking forward to your help!
Regards