Forum

Author Topic: Reset camera alignment and remove corresponding tie points?  (Read 6327 times)

neta

  • Newbie
  • *
  • Posts: 2
    • View Profile
Reset camera alignment and remove corresponding tie points?
« on: February 11, 2020, 09:56:22 AM »
I have an automated script that creates mosaics using images taken from an airplane. In some cases I know that the camera alignment is wrong - for example the pitch is really far from zero or the camera estimated center is far from the GPS location. If I reset those cameras in the GUI (right click -> reset camera alignment), it also removes their corresponding tie points.
I'd like to do the same thing in code. Setting camera transform to None resets that camera's alignment but the tie points remain. So how can I replicate the GUI command in code?
Thank you.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Reset camera alignment and remove corresponding tie points?
« Reply #1 on: February 11, 2020, 02:54:11 PM »
Hello neta,

Currently there's no built-in method in API to update the point cloud and disable tie points with less than two projections on the aligned images.

So if you want to reproduce the GUI behavior, you should disable tie points with custom code. Basically, just check the number of projections on aligned cameras for each tie point and if it is less than 2, then set enabled flag to False. Let me know, if any assistance with scripting this method is required.
Best regards,
Alexey Pasumansky,
Agisoft LLC

neta

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Reset camera alignment and remove corresponding tie points?
« Reply #2 on: February 11, 2020, 05:30:16 PM »
Thank you Alexey for the speedy reply.
Where can I find the list of tiepoints and their associated cameras?
A code snippet would be really helpful.
Neta

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Reset camera alignment and remove corresponding tie points?
« Reply #3 on: February 11, 2020, 08:09:38 PM »
Hello Neta,

I would suggest the following code:

Code: [Select]
import Metashape
chunk = Metashape.app.document.chunk
point_cloud = chunk.point_cloud
points = point_cloud.points
projections = chunk.point_cloud.projections
n_proj = dict()
point_ids = [-1] * len(point_cloud.tracks)


for point_id in range(0, len(points)):
point_ids[points[point_id].track_id] = point_id

for camera in chunk.cameras:
if camera.type != Metashape.Camera.Type.Regular:
continue
if not camera.transform:
continue

for proj in projections[camera]:
track_id = proj.track_id
point_id = point_ids[track_id]
if point_id < 0:
continue
if not points[point_id].valid:
continue

if point_id in n_proj.keys():
n_proj[point_id] += 1
else:
n_proj[point_id] = 1

for i in n_proj.keys():
if n_proj[i] < 2:
points[i].valid = False

print("Script finished")

It should remove (mark as invalid) the tie points which have less than 2 projections on the aligned cameras.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15366
    • View Profile
Re: Reset camera alignment and remove corresponding tie points?
« Reply #4 on: February 17, 2020, 03:14:51 PM »
In the next version update a point_cloud.cleanup() method will be available.
Best regards,
Alexey Pasumansky,
Agisoft LLC