Forum

Author Topic: Filter photos by marker using Python API  (Read 4033 times)

aniket@aus.co.in

  • Newbie
  • *
  • Posts: 25
    • View Profile
Filter photos by marker using Python API
« on: August 03, 2022, 09:31:15 PM »
The filter photos by marker work very well on GUI. I need to get the same result of filtering photos using the python API. Is there any way to do it?

and also is there any way to find the approximate positions for the markers on the images?
« Last Edit: August 03, 2022, 09:44:52 PM by aniket@aus.co.in »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15067
    • View Profile
Re: Filter photos by marker using Python API
« Reply #1 on: August 15, 2022, 01:13:35 PM »
Hello aniket,

Here is the example, that applies a filter to the Photos pane, based on the existing projections of the marker:

Code: [Select]
chunk = Metashape.app.document.chunk
marker = chunk.markers[-1] #last marker
cameras_filtered = marker.projections.keys()
Metashape.app.photos_pane.setFilter(cameras_filtered)

As for the marker projections on the cameras, you can check the example in another thread, which shows how to access the existing projection (blue or green flag) and how to estimate the marker re-projected location based on the marker 3D position:
https://www.agisoft.com/forum/index.php?topic=14595.msg64114#msg64114
Best regards,
Alexey Pasumansky,
Agisoft LLC

sahil_rp

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Filter photos by marker using Python API
« Reply #2 on: June 21, 2024, 10:25:56 AM »
HI Alexey, tried the code you have stated, once the alignment was run.
I can see in the UI that filter photos by marker is providing images list, but when i tried the code cameras_filtered = marker.projections.keys() it returns an empty list, can help me understand whats the issue and probable fix?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15067
    • View Profile
Re: Filter photos by marker using Python API
« Reply #3 on: June 21, 2024, 03:35:39 PM »
Hello sahil_rp,

What version of Metashape you are using?

The script published above shows how to display only those cameras in the Photos pane  that have projection of the last added markers (i.e. have blue or green flags for that marker).

Maybe you need to solve a different task, then please provide additional details about it.
Best regards,
Alexey Pasumansky,
Agisoft LLC

sahil_rp

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Filter photos by marker using Python API
« Reply #4 on: June 24, 2024, 10:53:14 AM »
Hi Alexey Pasumansky,
Thanks for the quick response.

Please find the attached snapshots for better clarification, i'm trying to get the list of images in which the GCP might be present[approximate locations provided by metashape] through code, although the flag colour is white in UI.
version - 2.1
« Last Edit: June 24, 2024, 11:43:13 AM by sahil_rp »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15067
    • View Profile
Re: Filter photos by marker using Python API
« Reply #5 on: June 24, 2024, 01:13:51 PM »
Hello sahil_rp,

Please see the example of the script that filters cameras in the Photos pane based on the marker's location:

Code: [Select]
chunk = Metashape.app.document.chunk
marker = chunk.markers[-1] #last marker
cameras_filtered = []
if marker.position:
for camera in [c for c in chunk.cameras if c.transform and c.type ==  Metashape.Camera.Type.Regular]:
coord = camera.project(marker.position)
if 0 <= coord.x < camera.sensor.width and 0 <= coord.y < camera.sensor.height:
cameras_filtered.append(camera)
if len(cameras_filtered):
Metashape.app.photos_pane.setFilter(cameras_filtered)
print("Filtering done")
else:
print("Empty list, cannot filter")
Best regards,
Alexey Pasumansky,
Agisoft LLC