Greetings all,
I am working on testing the importance of ground control density and configuration in model creation. To do this I would like to create a model with GCPs then use some python script to withhold several different GCP configurations and have different exports, such as camera OPK, and DEMs.
I am pretty new to python but have experience with program R and Matlab. I am able to run basic model with Agisoft in Python, but am unsure how to go about a few things.
How does one turn on and off markers in python code?
I would like a script to load a *.psz, turn off a few gcps, optimize, and run the model again, so I see this heading towards a loop of sorts.
Any tips would be great. Thanks!
import os
import PhotoScan
# Define: Home directory (later this is referred as ".")
HomeDirectory = "F:\\Backyard_Experiment\\time1"
# Set home folder
os.chdir(HomeDirectory)
doc = PhotoScan.app.document
doc.open("time1.psz")
chunk = doc.chunk
# Remove markers
???? something along the lines of
M.projections[P] = None #but I don’t know which images the GCPs are in. This ideally will be randomly generated points.
Could one have the markers set in Agisoft, then import different csv’s with a subset of the points, so not all GCPs would have a xyz with them.
# If I wanted to have k4=TRUE how do I add that?
chunk.optimizeCameras()
# RUN MODEL
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection)
chunk.alignCameras()
chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)
chunk.buildModel(surface=PhotoScan.Arbitrary, interpolation=PhotoScan.EnabledInterpolation)
chunk.buildUV(mapping=PhotoScan.GenericMapping)
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=4096)
# Define: Cameras output file – loop to create dynamic names needed….
CamerasOPKFile = ".\\CameraOrientations_PhotoScan.opk"
# I am doing something wrong here……?
chunk.exportCameras(CamerasOPKFile, "opk", chunk.projection, 'xyz')
#…..Export DEM?
GroundAlt = GroundAlt / N_points
# calculate Ground sampling distance
GroundSamplingDistance = math.fabs(CamAlt-GroundAlt) / focal_length
# round it to next millimeter
GroundSamplingDistance = math.ceil(GroundSamplingDistance * 1000)/1000
# EXPORT DSM(S)
print("---Exporting Digital Surface Model(s)...")
for Resolution in DSMResolutions:
if Resolution == 0:
Resolution = GroundSamplingDistance
FileName = ".\\DSM_PixelSize=" + str(Resolution) + "m.tif"
print("File: " + FileName)
if not(chunk.exportDem(FileName, format="tif", dx=Resolution, dy=Resolution, projection=chunk.projection)):
app.messageBox("Exporting DSM failed: " + FileName)
doc.save()