Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: seikamoomoo on May 11, 2021, 09:09:03 AM

Title: Build Texture Without Cameras
Post by: seikamoomoo on May 11, 2021, 09:09:03 AM
Hello!

I'm trying to build a textured model from a dense point cloud. The point cloud was generated in Dot3D and has normals and vertex colors but does not have any aligned cameras. When using the Metashape Pro client, I was able to create a mesh and then generate a texture directly from the mesh. However, I have not been able to do this with the Python API. Depending on the settings I use, BuildTexture() either gives an error that says "no aligned cameras" or one that says "model has no diffuse texture." I tried to copy the settings I used in the client (I've included a screenshot) but was unable to match them exactly - for example, there is no keep_uv mapping mode. I tried running BuildUV() before generating the texture, but still had the same issues.

Any help would be appreciated!
Title: Re: Build Texture Without Cameras
Post by: Alexey Pasumansky on May 12, 2021, 05:03:28 PM
Hello seikamoomoo,

If the polygonal model contains the vertex color information, then you should use the following lines to build the texture (including UV layout) from the vertex colors:

Code: [Select]
chunk.buildUV()
chunk.buildTexture(blending_mode = Metashape.BlendingMode.MosaicBlending, texture_size = 4096, texture_type = Metashape.Model.TextureType.DiffuseMap, source_model = chunk.model, transfer_texture = False)
Title: Re: Build Texture Without Cameras
Post by: miglenaray on April 13, 2022, 12:22:20 PM
Hi, I’m having the same problem. But when I enter the code that @alexey posted, I’m getting this error: “ SyntaxError: invalid character in identifier”.
My scan was created with FARO.

How can I fix this error, or is there another way to build colored mesh from colored scan?

Best wishes,

Miglena
Title: Re: Build Texture Without Cameras
Post by: Alexey Pasumansky on April 13, 2022, 12:44:22 PM
Hello Miglena,

You cannot copy-paste multi-line code to a simple console, if you want to input multi-line Python script to the Console pane you need to enable Rich Console option via Advanced Preferences tab of Metashape window.

Also you need to make an assignment for the chunk variable before using those lines, so if you want to have a complete code that works for the active chunk of the currently opened document, use the following:
Code: [Select]
import Metashape
chunk = Metashape.app.document.chunk
chunk.buildUV()
chunk.buildTexture(blending_mode = Metashape.BlendingMode.MosaicBlending, texture_size = 4096, texture_type = Metashape.Model.TextureType.DiffuseMap, source_model = chunk.model.key, transfer_texture = False)

It can be also executed via Run Script dialog, if saved in .py file.