agisoft-llc / metashape-scripts

Python scripts for Metashape (former PhotoScan)
MIT License
364 stars 203 forks source link

Automated script for multiple camera inputs without gui #90

Open luoshuiyue opened 1 month ago

luoshuiyue commented 1 month ago

Hi~ May I ask the export_for_gaussian_splatting.py and general_workflow.py scripts can support multiple camera input, because the default is the same camera parameter to estimate pose. Because I wanted to automate pose estimation using only this script without the need for human interaction gui.

PolarNick239 commented 1 month ago

Hi, what do you mean by multiple cameras input? Do you mean that some of the photos were taken with one camera and some of the photos were taken with another camera?

If so, it probably should work (just make sure that photos have the correct EXIF tags so general_workflow.py can guess camera groups correctly automatically). Have you tried to process such data? What problems do you encounter?

the default is the same camera parameter to estimate pose

What do you mean?

luoshuiyue commented 1 month ago

the default is the same camera parameter to estimate pose

What I mean is that my input data (a total of 388 images) is three cameras of the same type (the same type but made in slightly different), and the script will assume that the data set containing three cameras of the same type is from a camera and will only estimate one camera parameter (The algorithm should estimate three camera parameters if the dataset comes from three cameras). Below are images captured by three cameras : 023 138 255 And I performed a dedistortion operation then execute the script: 023_undistort 138_undistort 255_undistort And the execution result is below: 微信图片_20240719102518

PolarNick239 commented 1 month ago

Did I understand you correctly that if you were doing the processing in the interface, it would be fine to click Tools->Camera Calibration before aligning the photos, then right click on each group to split it into separate calibration groups (to optimize the internal parameters for each photo independently, since it's a separate camera)?

image

Can you please try doing that in the GUI, then proceed with Align Photos->export and see if the result works for you?

If everything OK - then you need to split cameras into separate calibration groups (for each photo - its own group) automatically via Python API like in this script - https://www.agisoft.com/forum/index.php?topic=4769.0

luoshuiyue commented 1 month ago

Hello, when running the automation script, how to make the image resolution does not change after the distortion

PolarNick239 commented 1 month ago

how to make the image resolution does not change after the distortion

Replace function compute_undistorted_calib(...) with:

def compute_undistorted_calib(sensor, zero_cxy):
    border = 0 # in pixels, can be increased if black margins are on the undistorted images

    if sensor.type != Metashape.Sensor.Type.Frame and sensor.type != Metashape.Sensor.Type.Fisheye:
        return (Metashape.Calibration(), Metashape.Matrix.Diag([1, 1, 1, 1]))

    calib_initial = sensor.calibration
    w = calib_initial.width
    h = calib_initial.height
    f = calib_initial.f

    calib = Metashape.Calibration()
    calib.f = f
    calib.width = w
    calib.height = h

    return (calib, Metashape.Matrix.Diag([1, 1, 1, 1]))

Note that without cropping, black pixels may appear at the edge of the image - and Gaussian splatting works poorly with them.