Hello,
I have a set of four images with which I use 15 GCPs to construct a dense cloud and then a DEM of my survey domain. I use these 15 GCPs to optimize my camera positions, view angles and lenses parameters.
I then wrote a python script to generate point cloud & DEM of the same domain using the exact same images, but instead of using GCPs, I use as inputs the optimized camera positions, view angles and lenses parameters. In doing so, I was thinking I would get the exact same results with and without GCPs, but this is not the case and whatever I've tried there's always a small shift remaining - I don't understand where this would come from, does anyone have an idea?
Here's the script I am using to process the images without GCPs:
import Metashape
import csv
global doc
doc = Metashape.app.document
path = 'path'
doc.save(path)
# Add chunk
chunk = doc.chunk
# load images to chunk
chunk.addPhotos(photo_list)
# Load camera position & view angles
chunk.importReference(path='path2ref.csv']),
format=Metashape.ReferenceFormatCSV,
columns='nxyzXYZabcABC',delimiter=",")
#define coordinate system
chunk.crs = Metashape.CoordinateSystem("EPSG::32646")
doc.save(path)
# Import calibration parameters of cameras (one group per camera since each has different parameters)
for camera in chunk.cameras:
Group = chunk.addCameraGroup()
filename = 'path2calibration'
calib = Metashape.Calibration()
calib.load(filename, format = Metashape.CalibrationFormatAustralis)
sensor = chunk.addSensor()
sensor.width = calib.width
sensor.height = calib.height
sensor.type = calib.type
sensor.user_calib = calib
sensor.fixed = True
camera.group = Group
camera.sensor = sensor
doc.save(path)
# Match photos
accuracy = 0 # equivalent to highest accuracy
keypoints = 200000 #align photos key point limit
tiepoints = 20000 #align photos tie point limit
chunk.matchPhotos(downscale=accuracy, generic_preselection = True,reference_preselection=False,\
filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
# Enable rotation angles for alignement
for camera in chunk.cameras:
camera.reference.rotation_enabled = True
# Align cameras
chunk.alignCameras(adaptive_fitting=False) #align cameras without adaptive fitting of distortion coefficients
## Optimize cameras - first optimization without GCPs
chunk.optimizeCameras(fit_f=False, fit_cx=False, fit_cy=False, fit_b1=False,\
fit_b2=False, fit_k1=True,fit_k2=False, fit_k3=False,\
fit_k4=False, fit_p1=False, fit_p2=False, fit_corrections=False,\
adaptive_fitting=False, tiepoint_covariance=False)
doc.save(path)
Cheers