Agisoft Metashape

Agisoft Metashape => General => Topic started by: MaciekK on May 03, 2021, 02:14:30 PM

Title: Gradual selection
Post by: MaciekK on May 03, 2021, 02:14:30 PM
Hi guys,
can I use gradual selection only for selected photos from the project? I know that this tool works on a sparse cloud and not in photos, but I mean the situation that in some photos, e.g. with a forest, I have few points (e.g. 30) and I would not want to delete them anymore, while others have a lot of them (e.g. 10,000 ). I think that such a disproportion has a negative effect on the aligment results. Maybe there is another way? except of course manual.

MK
Title: Re: Gradual selection
Post by: Paulo on May 03, 2021, 04:19:53 PM
Hi MK,

i have a workaround for this problem. You can move all fotos with low number of tie points in a group (in example I grouped all images with less than 75 projections). Select that group and then proceed to do a gradual selection on certain criteria. You then obtain a certain number of selected points (in example  24 840). then run following code:
Code: [Select]
"""
 deselects tpts that have projections in a  selected camera group
 """
 import Metashape as ps
 chunk = ps.app.document.chunk
 point_cloud = chunk.point_cloud
 points = point_cloud.points
 projections = point_cloud.projections
 npoints = len(points)

 selected_group = list()
 if not [group for group in chunk.camera_groups if group.selected]:
  raise Exception("No camera group selected!")
 for camera in chunk.cameras:
  if not camera.group:
  continue
  if camera.group.selected:
  selected_group.append(camera)
 nselpts = 0
 for point in  points:
  if point.selected:
  nselpts += 1
 ndsel = 0
 for camera in selected_group:
  point_index = 0
  for proj in projections[camera]:
  track_id = proj.track_id
  while point_index < npoints and points[point_index].track_id < track_id:
  point_index += 1
  if point_index < npoints and points[point_index].track_id == track_id:
  if not points[point_index].valid:
  continue
  else:
  if points[point_index].selected  :
  points[point_index].selected = False
  ndsel += 1
 print("Number pts unselected: ",ndsel,"Number remaining: ",nselpts-ndsel)
 print("done")
This will deselect all tie points that have projections in the selected group (in example 28 points had projections in the selected group). You can then delete the remaining selected points without affecting points in selected group....

Hope this makes sense!
Title: Re: Gradual selection
Post by: MaciekK on May 04, 2021, 01:08:43 AM
that's exactly what I meant, I will test it soon
thanks Paul