1
Python and Java API / Crop to GCPs in Sparse Cloud
« on: May 13, 2019, 11:42:48 PM »
Hello,
Agisoft 1.4.5 (still using the older version due to python script and OpenCL)
I've been trying to incorporate this into a larger script;
https://www.agisoft.com/forum/index.php?topic=8985.0
Unfortunately, it doesn't seem to crop to the markers I'm using?
Is there something missing, has something changed?
Thanks in advance.
Leon
Agisoft 1.4.5 (still using the older version due to python script and OpenCL)
I've been trying to incorporate this into a larger script;
https://www.agisoft.com/forum/index.php?topic=8985.0
Unfortunately, it doesn't seem to crop to the markers I'm using?
Code: [Select]
## load project
import PhotoScan
doc = PhotoScan.app.document
doc.open('XX.psz')
chunk = doc.chunk
## select GCPs
for marker in chunk.markers:
if marker.label == 'B1':
marker.reference.enabled = True
break
for marker in chunk.markers:
if marker.label == 'B2':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B3':
marker.reference.enabled = True
break
for marker in chunk.markers:
if marker.label == 'B4':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B5':
marker.reference.enabled = True
break
for marker in chunk.markers:
if marker.label == 'B7':
marker.reference.enabled = True
break
for marker in chunk.markers:
if marker.label == 'B8':
marker.reference.enabled = True
break
for marker in chunk.markers:
if marker.label == 'B9':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B10':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B11':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B12':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B13':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B14':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B15':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B16':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B18':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B19':
marker.reference.enabled = False
break
for marker in chunk.markers:
if marker.label == 'B20':
marker.reference.enabled = False
break
## rebuild sparse with selected GCPs
chunk.point_cloud = None
chunk.matchPhotos(accuracy=PhotoScan.LowAccuracy, generic_preselection=True, reference_preselection=True, keypoint_limit=40000, tiepoint_limit=4000)
for camera in chunk.cameras:
camera.transform = None
chunk.alignCameras(adaptive_fitting = False)
doc.save('XX.psz')
## crop
import PhotoScan
chunk = PhotoScan.app.document.chunk
T = chunk.transform.matrix
crs = chunk.crs
if not chunk.shapes:
chunk.shapes = PhotoScan.Shapes()
chunk.shapes.crs = chunk.crs
shape = chunk.shapes.addShape()
shape.label = "boundary"
shape.type = PhotoScan.Shape.Polygon
shape.boundary_type = PhotoScan.Shape.BoundaryType.OuterBoundary
coords = [crs.project(T.mulp(marker.position)) for marker in chunk.markers]
shape.vertices = [PhotoScan.Vector([coord.x, coord.y]) for coord in coords]
Is there something missing, has something changed?
Thanks in advance.
Leon