Forum

Author Topic: Error: load() argument 2 must be Metashape.CalibrationFormat, not str  (Read 1799 times)

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Hello Everyone,

I tried to run the script but I am getting this error. My calibration file is .xml format and I have done this before in the same way but now I am getting this error. Help me with this problem. I have attached the code with this.

Code: [Select]

import glob
try:
    import Metashape as env
    doc = Metashape.app.document
    env_type = 1
except:
    import PhotoScan as env
    doc = PhotoScan.app.document
    env_type = 2
   
load_images = True
load_thermal = True
# Thermal data
path_calib = 'C:\\Program Files\\Agisoft\\Metashape Pro'
path_images = 'C:\\Program Files\\Agisoft\Metashape Pro\\flir'
path_subdir = 'flir\\'
fileext = '*.tiff'
chunk_name = 'FLIR'
calib_fname = 'xt2_flir_20190206.xml'
flength = 13
psize = 0.017

ch = env.app.document.addChunk()
ch.label = chunk_name

# initiate images list
imgList = []
imgListNames = []
# construct flight directory
dir_srs = path_subdir
# reset file counter
cnt = 0

# go over all images
for filename in glob.glob(dir_srs + fileext):
# add image to list
    imgList.append(filename)
    fname = filename.split('\\')
    # add file name
    imgListNames.append(fname[-1])
    #' increment counter
    cnt += 1
   
if load_images == 1:
    # add images to chunk
    ch.addPhotos(imgList)
# create calibration instance
calibData = env.Calibration()
# load calibration data from file
calibData.load(calib_fname, format="xml")
# load camera calibration params
ch.sensors[0].user_calib = calibData
# assign camera focal length
ch.sensors[0].focal_length = flength
# assign camera pixel size
ch.sensors[0].pixel_size = env.Vector([psize,psize])
# do not optimise camera intrinsics
if env_type == 1:
    ch.sensors[0].fixed_calibration = True
else:
    ch.sensors[0].fixed = True

# ch = Metashape.app.document.chunk
path = '20191220_gcp_coordinates.txt'
ch.loadReference(path, format = Metashape.ReferenceFormatCSV, delimiter=",", columns="nxyz")

for frame in ch.frames:
    frame.matchPhotos(accuracy=Metashape.HighestAccuracy, generic_preselection=True,reference_preselection=True)

# ch.matchPhotos(accuracy=Metashape.LowAccuracy, generic_preselection=True,reference_preselection=True)
ch.alignCameras()


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14816
    • View Profile
Re: Error: load() argument 2 must be Metashape.CalibrationFormat, not str
« Reply #1 on: January 03, 2020, 10:21:05 PM »
Hello Aravinth,

please, try
Code: [Select]
calibData.load(calib_fname, format=Metashape.CalibrationFormatXML)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Error: load() argument 2 must be Metashape.CalibrationFormat, not str
« Reply #2 on: January 04, 2020, 03:54:40 PM »
Thank you Alexey. Its working now. But Why the same format worked before and not now ??

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14816
    • View Profile
Re: Error: load() argument 2 must be Metashape.CalibrationFormat, not str
« Reply #3 on: January 04, 2020, 05:03:04 PM »
Hello Aravinth,

In the version 1.6.0 of Python API some enums have been added, including CalibrationFormat and ReferencePreselectionMode.

You can refer to the change log in the chapter three of API reference document: https://www.agisoft.com/pdf/metashape_python_api_1_6_0.pdf
Best regards,
Alexey Pasumansky,
Agisoft LLC

Aravinth

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Error: load() argument 2 must be Metashape.CalibrationFormat, not str
« Reply #4 on: January 04, 2020, 11:04:54 PM »
Hello Alexy, I have another doubt

1. How to calculate the Ground sampling distance GSD for the optical and thermal camera. I have the front and side overlap of the images relative to thermal camera and the altitude of the flight.

2.How to calculate the distance between flight strips for each flight.

Kindly help me.
« Last Edit: January 04, 2020, 11:27:38 PM by Aravinth »