Forum

Author Topic: Create new psx file from standalone python script  (Read 6726 times)

tpubben

  • Newbie
  • *
  • Posts: 11
    • View Profile
Create new psx file from standalone python script
« on: May 27, 2019, 09:10:46 PM »
Hi, I'm trying to write a script so that I can process my data on my home computer while I'm on my laptop. I've installed the standalone python module for 1.5.2 on my home windows computer but can't seem to run my scripts because there is no existing psx file to open. I'll get rid of the hard-coded filepaths later but I keep getting a NoneType error when trying to save the document and add the chunk.

Code: [Select]
import Metashape
import os

def process_imagery():
    doc = Metashape.app.document
    doc.save("S:\\ImageProcessing\AutoPhoto\ProcDoc.psx")

    path_photos = "S:\\ImageProcessing\ProcessImagery\Test"
    photo_export = 'S:\\ImageProcessing\ProcessImagery\MsExport'

    # creating new chunk
    if len(doc.chunks):
        chunk = Metashape.app.document.chunk
    else:
        chunk = doc.addChunk()
    chunk.label = 'New Chunk'

    # loading images
    image_list = os.listdir(path_photos)
    photo_list = list()
    for photo in image_list:
        if photo.rsplit(".", 1)[1].lower() in ["jpg", "jpeg", "tif", "tiff"]:
            photo_list.append("/".join([path_photos, photo]))
    chunk.addPhotos(photo_list)

    # align photos
    chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=False, reference_preselection=True)
    chunk.alignCameras()
    chunk.buildDepthMaps(quality=Metashape.MediumQuality, filter=Metashape.AggressiveFiltering)
    chunk.buildDenseCloud()
    chunk.buildModel(surface=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation)
    chunk.buildUV(mapping=Metashape.GenericMapping)
    Metashape.app.update()

    # export
    chunk.exportModel(photo_export + '\\model.tif', format = 'tif')
    print ('Processing complete')

    doc.save()

process_imagery()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15723
    • View Profile
Re: Create new psx file from standalone python script
« Reply #1 on: June 20, 2019, 08:30:13 PM »
Hello tpubben,

When working with the scripts run in headless mode, we usually recommend the following way of project creation:

Code: [Select]
doc = Metashape.Document()
doc.save(path = "D:\Projects\new_empty_project.psx") #new empty project is created
So do not use Metashape.app.document in case of stand-alone module and scripts run in the headless mode.
Best regards,
Alexey Pasumansky,
Agisoft LLC