I am writing a script that follows the general workflow guide laid out in the user manual. I have gotten everything to work except for camera calibration. Ideally I would like to load in all of the photos and then calibrate a specific camera model associated with many photos as opposed to calibrating a new camera connected to each photo added. I was wondering if this was possible and if so how this can be implemented.
Here is my in progress script:
# Import Metashape
try:
import Metashape
except ImportError:
import sys
print("This library requires Agisoft Metashape")
sys.exit(1)
# Import other libraries
from pathlib import Path
# Checking Version Compatibility
print("--- Checking version compatibility...")
compatible_major_version = "1.6"
found_major_version = ".".join(Metashape.app.version.split('.')[:2])
if found_major_version != compatible_major_version:
raise Exception("Incompatible Metashape version: {} != {}".format(found_major_version, compatible_major_version))
# DEFINE PROCESSING SETTINGS
print("--- Defining processing settings...")
# Define: Source Path
SourcePath = Path.home().joinpath('Documents', 'A3M')
# Define: Project Prefix
ProjectPrefix = "Scripted"
# Define: Project Name
ProjectName = "Test1"
# Define: Image pattern
ImagePattern = "*.dng"
# INITIALIZE ENVIRONMENT
# Main app objects
doc = Metashape.app.document
chunk = doc.chunk
# Method to save project
def saveproject():
print("--- Saving project...")
doc.save()
# LOAD AND CALIBRATE PHOTOS
print("--- Loading images...")
# Find paths to photos
PhotoPaths = SourcePath.joinpath("Images", ProjectPrefix).rglob(ImagePattern)
# Load photos
Photos = list(map(str, PhotoPaths))
chunk.addPhotos(Photos)
# Calibrate cameras
# Psuedocode <------------------------------------------------------------------------------ Change this
# chunk.cameramodel.sensor = Metashape.Sensor.Fisheye
saveproject()
# ALIGN PHOTOS
print("--- Aligning photos...")
# print("Accuracy: " + AlignPhotosAccuracy)
chunk.matchPhotos()
chunk.alignCameras()
saveproject()
# BUILD DENSE CLOUD
print("--- Building Depth Maps...")
chunk.buildDepthMaps()
print("--- Building Dense Cloud...")
chunk.buildDenseCloud()
saveproject()
# BUILD MODEL
print("--- Building Model...")
chunk.buildModel()
saveproject()
# EXPORT MODEL
ModelPath = SourcePath.joinpath("Models", ProjectPrefix)
try:
ModelPath.mkdir()
except FileExistsError:
print("Duplicate directory found, no new directory made")
chunk.exportModel(path=str(ModelPath.joinpath(ProjectName + ".obj")))