Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: danimlk on June 11, 2021, 11:44:18 AM

Title: Exported Model does not have RGB color values
Post by: danimlk on June 11, 2021, 11:44:18 AM
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:

Code: [Select]
    # 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
Code: [Select]
python3 -m pip install <file_name>.whl and I have tried the following versions:


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
Title: Re: Exported Model does not have RGB color values
Post by: Alexey Pasumansky on June 11, 2021, 02:24:57 PM
Hello danimlk,

For buildModel operation which uses depth maps data as a source, I suggest to add the following lines for the vertex colors calculation:

Code: [Select]
colorizeModel = Metashape.Tasks.ColorizeModel()
colorizeModel.source_data =Metashape.DataSource.ImagesData
colorizeModel.apply(chunk)
Title: Re: Exported Model does not have RGB color values
Post by: danimlk on June 14, 2021, 03:02:36 PM
Hello danimlk,

For buildModel operation which uses depth maps data as a source, I suggest to add the following lines for the vertex colors calculation:

Code: [Select]
colorizeModel = Metashape.Tasks.ColorizeModel()
colorizeModel.source_data =Metashape.DataSource.ImagesData
colorizeModel.apply(chunk)

Hi Alexey,

Thank for replying, I've added this to my script and it works now. The final output now has the color information.

Thanks for the help!  :)
Title: Re: Exported Model does not have RGB color values
Post by: Alexey Pasumansky on June 16, 2021, 12:48:38 PM
Hello danimlk,

Starting from the next version update the behavior of buildModel operation from the depth maps source with vertex_colors option enabled should automatically perform the colorization.