mutlugazete.com

Streamlining Your Agisoft Metashape Workflow with Python

Written on

Chapter 1: Introduction to Python in Metashape

Agisoft Metashape is an exceptional tool for generating high-resolution drone orthomosaics and intricate 3D point clouds and mesh models. Its user-friendly graphical user interface (GUI) is suitable for a variety of users. If you are just starting, Aleena Rayamajhi has put together a detailed article to help you navigate the standard GUI effectively.

Once you become accustomed to the interface, you may find that many tasks are repetitive. Automating such tasks is crucial for improving efficiency. Additionally, errors during processing, such as incorrect tie points or key point limits, can result in wasted time and incorrect outputs.

The Professional version of Metashape offers a Python API that can significantly enhance your workflow. If you haven't utilized it yet, now is the time! Implementing the Metashape Python API allows for batch processing of multiple projects and guarantees consistent, reproducible results by applying the same settings across tasks.

One of the major advantages of the Python API is the ability to save your project automatically after each processing step. This is particularly beneficial when processing large sets of images, which can take considerable time—sometimes even running overnight. Manual saving can be problematic, especially if your computer loses power unexpectedly. The Python API mitigates this risk by ensuring your work is saved regularly.

In this article, you will discover how to leverage Metashape's Python API to automate the initial alignment phase of your workflow. Before diving into coding, it's advisable to read the user manuals and properly configure Metashape for your setup. If you're a newcomer, I also recommend exploring Agisoft tutorials and watching relevant YouTube videos.

I highly suggest reviewing the USGS Open File Report on Processing Coastal Imagery in Agisoft Metashape. This report provides a thorough overview of the GUI and processing workflows tailored for drone aerial imagery in coastal settings. While some settings may not be applicable to other scenarios (such as turntables or multi-camera setups), aspects like GPU acceleration configuration and log file generation are universally relevant.

Chapter 1.1: Understanding Chunks

In Metashape, 'Chunks' serve as organizational units for cameras, tie points, reference data, and additional information. Both documents and chunks are accessible as objects in the Python API, with attributes that can be set or retrieved. Here’s a simple example:

doc = Metashape.app.document

for chunk in doc.chunks:

if chunk.label == 'chunk1':

# perform operations

When naming a chunk, ensure that the label makes sense as it will be stored as chunk.label. For instance, if this is your first run in a project, you might name the chunk 'run1'.

Adding Photos to a Chunk

To add photos to the 'run1' chunk, right-click on it, select Add → Add Photos, and navigate to your desired image directory. After selecting the images, click 'Open.'

Once the images are added, save your project. It’s important to establish a clear naming convention for your project files to simplify coding. For example, you might use a format like 20230828_mcourse.psx, where the date is structured as yyyymmdd.

Chapter 1.2: Configuring Camera Settings

If you're using images from a DJI Phantom 3 drone, Metashape automatically extracts GPS data from the EXIF information. If your camera's settings are not included, you can input them manually via Tools → Camera Calibration. After ensuring that all settings are correct, save your project and proceed to the coding phase.

Chapter 2: The Python Code

The following Python code enables you to configure the parameters for image alignment. These parameters correspond to specific settings found in the GUI:

match_accuracy = 1 # High accuracy

gen_pre = True # Enable generic preselection

ref_pre = True # Enable reference preselection

mask_filt = True # Filter points using masks

mask_tie = True # Apply masks to tie points

key_lim = 60000 # Limit of key points

tie_lim = 0 # Limit of tie points

This code also allows for camera optimization after the initial alignment. To disable this feature, set optimus = False.

Note:

  • The project path/name is structured as a list to accommodate multiple projects.
  • The chunk labels should also be in a list format to process multiple chunks.

# Example code snippet

Projs = ["/data2/metashape_course/20230828_mcourse.psx"]

clbls = ["run1"]

doc = Metashape.app.document

for proj in Projs:

doc.open(proj)

for clbl in clbls:

for chunk in doc.chunks:

if chunk.label != clbl:

continue

print(f"Now processing project <{proj}>...")

# Process the chunk...

doc.save() # Save after alignment

Chapter 3: Executing the Code in Metashape

To execute the code in Metashape, copy it into a Python or text editor and save it as 'metashape_align.py'. Adjust the project path in the Projs variable, then open Metashape and navigate to Tools → Run Script. Select your script and enter '-r' in the Arguments dialog before clicking 'Ok.'

If everything is set up correctly, Metashape will begin aligning your images!

Video Tutorials

To further assist in your learning, check out the following video tutorials:

This tutorial covers the basics of the Agisoft Metashape workflow.

This comprehensive tutorial explores advanced features in Agisoft Metashape, including cloud processing, mesh creation, and more.

Conclusion

By following the steps outlined in this guide, you should be able to automate the image alignment process in Agisoft Metashape using Python, enhancing both efficiency and accuracy in your workflow.

Share the page:

Twitter Facebook Reddit LinkIn

-----------------------

Recent Post:

Samsung Galaxy Ring: A Game-Changer in Wearable Technology

Discover the revolutionary Samsung Galaxy Ring, a sleek wearable tech that elevates personal health monitoring and fitness tracking.

Embrace Discomfort: The Key to Achieving Your Goals

Discover how stepping out of your comfort zone can lead to personal growth and success in your pursuits.

Stop Comparing Yourself: 5 Steps to Embrace Personal Growth

Discover five key strategies to break the cycle of comparison and embrace personal growth and happiness.

Spotify's Web Diverts: The Intentional Friction Behind User Experience

Exploring the rationale behind Spotify's regional restrictions and their impact on user experience during workouts and travel.

Understanding ADHD: You're Not a Failure, You're Unique

A deep dive into ADHD, exploring self-control, diagnosis, and the transformative power of medication.

Balancing Work Ethic and Personal Well-being for True Success

Explore the importance of a strong work ethic while maintaining mental health and personal well-being.

# Utilizing Astronaut Blood for Concrete Production on Mars

Researchers discover that astronaut bodily fluids can be used to create concrete on Mars, potentially revolutionizing space construction.

Exploring the Power and Limitations of GPT-3

Discover the capabilities and challenges of GPT-3, the groundbreaking language model from OpenAI, and learn how to utilize it effectively.