Forum

Author Topic: Assign pixel_size and focal_length to imported photos  (Read 518 times)

PierreB

  • Newbie
  • *
  • Posts: 11
    • View Profile
Assign pixel_size and focal_length to imported photos
« on: February 25, 2022, 05:44:15 PM »
Hi. I need to build a point cloud using 5 simultaneous sets of aerial photos (1 nadir view and 4 oblique views) with Python.
I'm stuck at the camera calibration step as I can't manage to assign the pixel_size and focal_length to the imported photos.
Below is the part of the script that should do it but when I run it and open the project in the GUI, the pixel_size and focal_length are blank. What is missing?

Code: [Select]
import Metashape
import os

data = "D:\Data"
project = Metashape.Document()
project.save(os.path.join(data, "project.psx"))
chunk = project.addChunk()
chunk.crs = Metashape.CoordinateSystem("EPSG::32616")
project.save()
views = ["nadir", "oblique1", "oblique2", "oblique3", "oblique4"]
sens = dict()
for view in views:
    sens[view] = chunk.addSensor()
    sens[view].label = view
    sens[view].pixel_size = Metashape.Vector([0.00520, 0.00520])
    if "oblique" in view:
        sens[view].focal_length = 123.0
    else:
        sens[view].focal_length = 82.0
photos = [os.path.join(data, f) for f in os.listdir(data) if f.endswith(".tif")]
chunk.addPhotos(photos)
project.save()
for camera in chunk.cameras:
    for view in views:
        if view in camera.label:
            camera.sensor = sens[view]
project.save()

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13995
    • View Profile
Re: Assign pixel_size and focal_length to imported photos
« Reply #1 on: February 25, 2022, 07:00:34 PM »
Hello Pierre,

Can you please confirm, it is the only issue with the script and it assigns the sensors to the cameras as expected?

If not, please try to add sens[view].width and sens[view].height definition to the part, where the sensors are created.
Best regards,
Alexey Pasumansky,
Agisoft LLC

PierreB

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Assign pixel_size and focal_length to imported photos
« Reply #2 on: February 25, 2022, 11:34:10 PM »
Yes, the sensors seem to be assigned to the photos but the parameters are not changed, as you can see in this screen capture.
I added the height and width but it didn't appear to change anything.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13995
    • View Profile
Re: Assign pixel_size and focal_length to imported photos
« Reply #3 on: February 26, 2022, 05:56:08 PM »
Hello Pierre,

The following code works at my side, the script is adding the photos at first, then creating the sensors (taking height and width from the default calibration group, based on loaded images):

Code: [Select]
import Metashape
import os

data = "D:\\Data"
project = Metashape.Document()
project.save(os.path.join(data, "project.psx"))
chunk = project.addChunk()
chunk.crs = Metashape.CoordinateSystem("EPSG::32616")
project.save()
photos = [os.path.join(data, f) for f in os.listdir(data) if f.endswith(".tif")]
chunk.addPhotos(photos)
views = ["nadir", "oblique1", "oblique2", "oblique3", "oblique4"]
sens = dict()
for view in views:
    sens[view] = chunk.addSensor()
sens[view].height = chunk.sensors[0].height
sens[view].width = chunk.sensors[0].width
    sens[view].label = view
    sens[view].pixel_size = Metashape.Vector([0.00520, 0.00520])
    if "oblique" in view:
        sens[view].focal_length = 123.0
    else:
        sens[view].focal_length = 82.0
project.save()
for camera in chunk.cameras:
    for view in views:
        if view in camera.label:
            camera.sensor = sens[view]
project.save()
Best regards,
Alexey Pasumansky,
Agisoft LLC