Forum

Author Topic: Set calibration data by script (contain code)  (Read 5778 times)

Centomini

  • Newbie
  • *
  • Posts: 3
    • View Profile
Set calibration data by script (contain code)
« on: May 05, 2023, 05:57:44 PM »
Hi everyone,

I have written this script to set "pixel size" and "focal length" values in the entire project without having to re-enter them by hand in Metashape's camera calibration tool.

It works perfectly.

However, I would also like to integrate into this script a set of instructions to write in the "initial" tab the type = precalibrated, set "f" to a certain number and finally lock "f" (in fixed parameters), but I am having great difficulty getting this desired part of the script to work; can you give me a hand? Thanks.

Code: [Select]
import Metashape

# Desired values
pixel_size = (set pixel size)
focal_length = (set focal length)

# Access the current project
doc = Metashape.app.document

# Iterate through all chunks
for chunk in doc.chunks:
    # Iterate through all chunks
    for camera in chunk.cameras:
        if camera.sensor is not None:
            # Set the pixel size and focal length
            camera.sensor.pixel_size = Metashape.Vector([pixel_size, pixel_size])
            camera.sensor.focal_length = focal_length

# Save the document
doc.save()
« Last Edit: May 05, 2023, 06:03:48 PM by Centomini »

Paulo

  • Hero Member
  • *****
  • Posts: 1350
    • View Profile
Re: Set calibration data by script (contain code)
« Reply #1 on: May 05, 2023, 06:47:40 PM »
Hi Centomini,

Code: [Select]
camera.sensor.fixed_params = ['F'] # fix f
Then define a calibration instance and set f to desired value and assign to user_calib

Code: [Select]
calib = Metashape.Calibration()
calib.f = (value in pixels) # aprox = focal_length / pixel_size
camera.sensor.user_calib = calib # set user calibration

Hope this is useful
« Last Edit: May 05, 2023, 06:49:40 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Centomini

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Set calibration data by script (contain code)
« Reply #2 on: May 05, 2023, 07:28:51 PM »
Ok Paulo, it's work.
« Last Edit: May 05, 2023, 08:20:02 PM by Centomini »