Forum

Author Topic: Filter photos by markers in python  (Read 1315 times)

adrian-var

  • Newbie
  • *
  • Posts: 4
    • View Profile
Filter photos by markers in python
« on: December 13, 2022, 11:10:13 AM »
With UI, I can right-click "Markers" and "Filter Photos By Markers" to get a list of photos with the markers.

I only know to get the green/blue flag by Marker.projections

However, is it possible to get the list of photos (white flag) by python?




Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Filter photos by markers in python
« Reply #1 on: December 14, 2022, 01:16:54 PM »
Hello adrian,

Please check the following script example that prints out for each marker either the existing projection coordinates (pinned = green flag, unpinned = blue flag) or expected projection location (undefined = gray flag):

Code: [Select]
import Metashape

def get_markers_projections(chunk):
print("Script started...")

for marker in chunk.markers:
if (not len(marker.projections.keys()) and not marker.position):
continue
for camera in chunk.cameras:
if camera in marker.projections.keys():
x, y, z = marker.projections[camera].coord
if marker.projections[camera].pinned:
print(marker.label, camera.label, "pinned", x, y)
else:
print(marker.label, camera.label, "unpinned", x, y)
else:
if not marker.position:
continue
if not camera.transform:
continue
point = marker.position
if camera.project(point):
x, y = camera.project(point)
if (0 <= x < camera.sensor.width) and (0 <= y < camera.sensor.height):
print(marker.label, camera.label, "undefined", x, y)

print("Script finished")
return 1

chunk = Metashape.app.document.chunk
get_markers_projections(chunk)

The sample output for such script will look like the following:
Code: [Select]
2022-12-14 13:14:52 Script started...
2022-12-14 13:14:52 point 2 DSC03649.JPG unpinned 1917.0135498046875 1528.13916015625
2022-12-14 13:14:52 point 2 DSC03650.JPG undefined 1647.1464515201335 349.7973120066963
2022-12-14 13:14:52 point 2 DSC03663.JPG unpinned 644.6650390625 945.0457153320312
2022-12-14 13:14:52 point 2 DSC03664.JPG unpinned 494.5836181640625 942.4381103515625
2022-12-14 13:14:52 point 2 DSC03683.JPG pinned 142.2118377685547 786.333251953125
2022-12-14 13:14:52 Script finished
Best regards,
Alexey Pasumansky,
Agisoft LLC

adrian-var

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Filter photos by markers in python
« Reply #2 on: December 16, 2022, 04:39:53 AM »
Hello adrian,

Please check the following script example that prints out for each marker either the existing projection coordinates (pinned = green flag, unpinned = blue flag) or expected projection location (undefined = gray flag):

Code: [Select]
import Metashape

def get_markers_projections(chunk):
print("Script started...")

for marker in chunk.markers:
if (not len(marker.projections.keys()) and not marker.position):
continue
for camera in chunk.cameras:
if camera in marker.projections.keys():
x, y, z = marker.projections[camera].coord
if marker.projections[camera].pinned:
print(marker.label, camera.label, "pinned", x, y)
else:
print(marker.label, camera.label, "unpinned", x, y)
else:
if not marker.position:
continue
if not camera.transform:
continue
point = marker.position
if camera.project(point):
x, y = camera.project(point)
if (0 <= x < camera.sensor.width) and (0 <= y < camera.sensor.height):
print(marker.label, camera.label, "undefined", x, y)

print("Script finished")
return 1

chunk = Metashape.app.document.chunk
get_markers_projections(chunk)

The sample output for such script will look like the following:
Code: [Select]
2022-12-14 13:14:52 Script started...
2022-12-14 13:14:52 point 2 DSC03649.JPG unpinned 1917.0135498046875 1528.13916015625
2022-12-14 13:14:52 point 2 DSC03650.JPG undefined 1647.1464515201335 349.7973120066963
2022-12-14 13:14:52 point 2 DSC03663.JPG unpinned 644.6650390625 945.0457153320312
2022-12-14 13:14:52 point 2 DSC03664.JPG unpinned 494.5836181640625 942.4381103515625
2022-12-14 13:14:52 point 2 DSC03683.JPG pinned 142.2118377685547 786.333251953125
2022-12-14 13:14:52 Script finished

Thanks! It works. I have a follow-up question.

With UI, after pinning 1-2 grey flags, it will correct other grey flags to a more accurate coordinate. But when I use
Code: [Select]
marker.projections[camera] = Metashape.Marker.Projection(Metashape.Vector([300, 1300]), True)
and run get_markers_projections() again, the markers' projection won't update?

I tried refineMarkers(marker), but it took a lot longer time(~2mins) than UI (instantly)


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: Filter photos by markers in python
« Reply #3 on: December 16, 2022, 01:14:13 PM »
Hello adrian,

Do you have get any difference in output for the "grey flags" (undefined projections), if you have at least two pinned/unpinned projections placed?

As for refineMarkers function, it works similar to the corresponding option in GUI: Tools Menu -> Markers -> Refine Markers, which tries to create new unpinned projections and move the existing unpinned projections, based on the existing marker projections and the image content.
Best regards,
Alexey Pasumansky,
Agisoft LLC