Forum

Author Topic: Filtering photos by shape from Python API  (Read 3016 times)

jurijs.jeshkins

  • Newbie
  • *
  • Posts: 8
    • View Profile
Filtering photos by shape from Python API
« on: April 09, 2020, 02:09:01 PM »
Hi!

I have a layer with points, which I imported into the chunk as shapes. I want to filter my photos by this points and get at least list of photos used for point cloud generation under the shapes. The bonus would be to get the coordinates of the point on each photo as well. I see, that it is possible to do it from the interface, but I have thousands of points. Is it somehow possible from Python API?

jurijs.jeshkins

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Filtering photos by shape from Python API
« Reply #1 on: April 09, 2020, 04:08:59 PM »
I found a workaround through placing markers on the shape and looking at projections. Seems to work.

Code: [Select]
import Metashape
import csv

chunk = Metashape.app.document.chunk
T = chunk.transform.matrix

dir_path = "C:/"


with open(dir_path + 'shape_cameras.txt', "w") as f:
fwriter = csv.writer(f, dialect='excel-tab', lineterminator='\n', delimiter = ";")

for shape in chunk.shapes:
marker = chunk.addMarker(T.inv().mulp(shape.vertices[0]))
projections = marker.projections.items()
for proj in projections:
camera = proj[0]
vector = proj[1]
fwriter.writerow([shape.label, camera.photo.path, vector.coord.x, vector.coord.y])
chunk.remove(marker)
f.close()
print("Finished")