Forum

Author Topic: Script to reorganize calibration groups forces all image resolutions to 0x0  (Read 1980 times)

jslyder

  • Newbie
  • *
  • Posts: 24
    • View Profile
Hello,
I have many thousands of images that I wanted to organize into different calibration groups based on the date they were collected, which is reflected in the label.  I wrote the script below to accomplish this.  While the script works for this purpose, it also forces the resolution of all images to 0x0 (screenshot attached).  If I try to align the images, it goes through one batch where 0 points are detected for each image, and I get the error "Error: Can't select tile size."  If I click on the image in the workspace, it still shows the appropriate dimensions,17588 x 16039. 

Is this a bug, or am I doing something wrong in the script? 
Thank you

Code: [Select]

chunk = Metashape.app.document.chunk

# Make list of dates to create calibration groups
calGroups = []
for camera in chunk.cameras:
    yr = camera.label[:2]
    if yr not in calGroups:
        calGroups.append(yr)

#Create the calibration groups
for i in calGroups:
    sensor = chunk.addSensor()
    sensor.label = i
    sensor.type = Metashape.Sensor.Type.Frame
    sensor.focal_length = 208.047
    sensor.pixel_height = 0.0125
    sensor.pixel_width = 0.0125

#Assign cameras to calibration groups. 
for camera in chunk.cameras:
    for s in chunk.sensors:
        if s.label == camera.label[:2]:
            camera.sensor = s




Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Hello jslyder,

Please check how the new sensors are created in the following script:
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/split_calibration_by_order.py

In your code you are missing sensor.width and sensor.height assignment that should correspond to the dimensions of the images that will be assigned to this sensor.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jslyder

  • Newbie
  • *
  • Posts: 24
    • View Profile
Got it, thanks Alexey.