Forum

Author Topic: Python Script - Multiprocessing MetaShape V1.80  (Read 4328 times)

Ipoffline1

  • Newbie
  • *
  • Posts: 2
    • View Profile
Python Script - Multiprocessing MetaShape V1.80
« on: January 29, 2022, 06:46:52 PM »
Hi
Great program by the way.

We have done an underwater survey with an AUV. We have 30000 plus images to process.

We made 8 chunks and imported the photos. These were aligned and 8 projects of each chunk were created.

We compiled a script to multi-process the 8 projects simultaneously.

We found after the first run that the dense clouds, meshes, DEMs and orthomosaics were created.

However, the project files used were not saved. So when we open the projects to view the data we can only see the initial alignment Tie Points. (last saved time)

Is there anyway of building a project file from the data that was produced?

We did have two instances of Metashape open at the time.

Any suggestions will be greatly appreciated.

Note: We have edited the script and we think that it saves alright now.  Still need a final test,

Kind Regards

IP Offline

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15472
    • View Profile
Re: Python Script - Multiprocessing MetaShape V1.80
« Reply #1 on: January 29, 2022, 07:12:58 PM »
Hello!

Without seeing the script code I could assume that you might be calling doc.save(path) without later re-assigning chunk variable, for example:

Code: [Select]
chunk = doc.chunk
chunk.matchPhotos()
#...
doc.save(path)
chunk.buildDem()

Using doc.save(path) for PSX projects works similar to Save As operation called from GUI - the project is saved and re-opened. So in case of script you need to re-assign the chunk variable after such calls.
But easier way would be to save the document right is the beginning and then call doc.save() without path argument, for example:

Code: [Select]
doc = Metashape.Document()
doc.save(path)
chunk = doc.addChunk()
chunk.matchPhotos()
doc.save()
#....

Best regards,
Alexey Pasumansky,
Agisoft LLC

Ipoffline1

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Python Script - Multiprocessing MetaShape V1.80
« Reply #2 on: January 29, 2022, 09:43:44 PM »
Hi Alex
Wow, Thanks for the fast reply.
Here is our code at the moment. I think we are missing the first doc.save(path) after the doc.open(path.....). I have attached the script too.

def process(args):

   #mprojects = ('E:\AUV4_Metashape\Site_25_Split_Chunk_1_Align.psx',
   #         'E:\AUV4_Metashape\Site_25_Split_Chunk_2_Align.psx')
   mprojects = ('E:\AUV4_Metashape\Site_25_Split_Chunk_3_Align.psx',
            'E:\AUV4_Metashape\Site_25_Split_Chunk_4_Align.psx',
            'E:\AUV4_Metashape\Site_25_Split_Chunk_5_Align.psx',
            'E:\AUV4_Metashape\Site_25_Split_Chunk_6_Align.psx',
            'E:\AUV4_Metashape\Site_25_Split_Chunk_7_Align.psx',
            'E:\AUV4_Metashape\Site_25_Split_Chunk_8_Align.psx')   

   multiprocessing(batches,mprojects,"Running Metashape batches")

def batches(projects,i):
   doc = Metashape.Document()
   doc.open(path=projects,ignore_lock=True)
   chunk = doc.chunk
   #run_camera_alignment(chunk)
   #chunk.matchPhotos(downscale=3, generic_preselection=True, reference_preselection=False)
   #chunk.triangulatePoints(max_error=10, min_image=1)
   #chunks.alignCameras()
   chunk.buildDepthMaps(downscale=4, filter_mode=Metashape.MildFiltering)
   doc.save(path=projects)
   chunk.buildDenseCloud()
   doc.save(path=projects)
   chunk.buildModel(surface_type=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation, face_count=Metashape.MediumFaceCount, source_data=Metashape.DenseCloudData, vertex_colors=True)
   doc.save(path=projects)
   #chunks.buildTexture(blending_mode=Metashape.MosaicBlending, texture_size=4096)
   chunk.buildOrthomosaic(surface_data=Metashape.ModelData,blending_mode=Metashape.MosaicBlending,fill_holes=True)
   
   #chunks.buildUV(mapping_mode=Metashape.GenericMapping)
   doc.save(path=projects)

   doc.save()

Thanks again.

Regards
IP Offline

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15472
    • View Profile
Re: Python Script - Multiprocessing MetaShape V1.80
« Reply #3 on: January 31, 2022, 08:55:54 PM »
Hello Ipoffline1,

Please try to replace doc.save(path=projects) lines in your script with doc.save(), then check, if it works.
Best regards,
Alexey Pasumansky,
Agisoft LLC