Agisoft Metashape > Python and Java API

Exported Model does not have RGB color values

(1/1)

danimlk:
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: ---    # 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')


--- End code ---

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: ---python3 -m pip install <file_name>.whl
--- End code ---
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

Alexey Pasumansky:
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: ---colorizeModel = Metashape.Tasks.ColorizeModel()
colorizeModel.source_data =Metashape.DataSource.ImagesData
colorizeModel.apply(chunk)
--- End code ---

danimlk:

--- Quote from: 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: ---colorizeModel = Metashape.Tasks.ColorizeModel()
colorizeModel.source_data =Metashape.DataSource.ImagesData
colorizeModel.apply(chunk)
--- End code ---

--- End quote ---

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!  :)

Alexey Pasumansky:
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.

Navigation

[0] Message Index

Go to full version