Forum

Author Topic: Accessing the number of projections per image  (Read 4081 times)

Wizyza

  • Newbie
  • *
  • Posts: 26
    • View Profile
Accessing the number of projections per image
« on: October 02, 2023, 10:46:58 PM »
Hello,

How do I access the number of projections per image such as what is displayed in the Reference panel? I'm using the Python API for Metashape 2.0.3.

I found a past post from a few years ago that asked this same question:

https://www.agisoft.com/forum/index.php?topic=12758.0

I haven't been able to get any of the code to work. I'm guessing because the API has changed since the time of the posting?

Thanks!

Paulo

  • Hero Member
  • *****
  • Posts: 1339
    • View Profile
Re: Accessing the number of projections per image
« Reply #1 on: October 03, 2023, 01:44:39 AM »
Hello Wizyza,

in the referenced post i put a code to do just this:

Code: [Select]
chunk = Metashape.app.document.chunk

point_cloud = chunk.point_cloud
projections = point_cloud.projections
points = point_cloud.points
npoints = len(points)
tracks = point_cloud.tracks
point_ids = [-1] * len(point_cloud.tracks)

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


for camera in chunk.cameras:
nprojections = 0

if camera.type == Metashape.Camera.Type.Keyframe:

continue # skipping Keyframes

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

nprojections += 1

print(camera, nprojections, len(projections[camera]))

In layest API, just change chunk.point_cloud to chunk.tie_points and it should work...
Best Regards,
Paul Pelletier,
Surveyor

Wizyza

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Accessing the number of projections per image
« Reply #2 on: October 23, 2023, 07:39:03 PM »
Thank you for the help Paulo! After the tweaks, it works as needed.