Forum

Author Topic: Crop to GCPs in Sparse Cloud  (Read 1814 times)

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
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?

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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14853
    • View Profile
Re: Crop to GCPs in Sparse Cloud
« Reply #1 on: May 14, 2019, 12:43:02 PM »
Hello Leon,

Which task you are trying to solve with the script?

And what problem do you have with CUDA/OpenCL in the latest version? In Metashape you can switch between CUDA/OpenCL implementation for NVIDIA graphic cards with the tweak main/gpu_enable_cuda.
Best regards,
Alexey Pasumansky,
Agisoft LLC

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Crop to GCPs in Sparse Cloud
« Reply #2 on: May 14, 2019, 07:22:04 PM »
Hello Alexey,

Hello Leon,

Which task you are trying to solve with the script?

I have excess data that needs to be disposed of. An example is in the attached image. The red cross hatch area within the GCPs is what I'd like to keep, and get rid of all of the blank space surrounding. I have a large batch of data sets to do this to, so if I can achieve this through python scripting, it will save a lot of time.


Quote
And what problem do you have with CUDA/OpenCL in the latest version? In Metashape you can switch between CUDA/OpenCL implementation for NVIDIA graphic cards with the tweak main/gpu_enable_cuda
.

I run Linux and I'm using an AMD RX 570, I've found that it is faster using 1.4.5 than 1.5.x, I'm on older AMDGPU-Pro (OpenCL only) drivers too as the latest slow down processing (OpenCL 2+), and ROCm wasn't recognised by Photoscan/Metashape..but that could have been my fault due to installation error. I haven't tested since 1.5.0/1 as this is working very well for me. I haven't convereted my python script from PhotoScan to Metashape either, because this current set up is working well (I will do at some point, I'm just time constrained at the moment).

Cheers,

Leon

EDIT: I should probably add that all of my data sets have been manually prepared by doing an initial sparse build and meshing so that GCPs can be added, so the crop to selection is available in the model tab of the GUI.
« Last Edit: May 15, 2019, 04:50:12 PM by LDBL »