Hi!
hope I am not a little too late to the party. Here is a code I worked to get the info of the total, valid and invalid matches from the API as it appears in the GUI. Hope it helps.
Best,
Carlos
import Metashape
doc = Metashape.app.document
chunk = doc.chunk
#Define values
point_cloud = chunk.point_cloud #current cloud
point_proj = point_cloud.projections #collection of projections
points = point_cloud.points #collection of points
npoints = len(points)
#Define Data Collections
projection_matches = list() #here projections for total matches will be stored
photo_matches = dict() #here points for valid matches will be stored
total_matches = list() #here the result will be stored
#add projections to collection
for photo in chunk.cameras:
photo_proj = point_proj[photo] #get individual projection
total_projections = set()
for proj in photo_proj:
total_projections.add(proj.track_id)
projection_matches.append(total_projections)
#add points to collection
for photo in chunk.cameras:
total_points = set() #only valid
point_index = 0
proj = point_proj[photo]
for cur_point in proj:
track_id = cur_point.track_id
while point_index < npoints and points[point_index].track_id < track_id:
point_index += 1
if point_index < npoints and points[point_index].track_id == track_id:
if point_cloud.points[point_index].valid:
total_points.add(point_index)
photo_matches[photo] = total_points
#do calculation magic
for i in range(0, len(chunk.cameras) - 1):
for j in range(i + 1, len(chunk.cameras)):
projection_match = projection_matches[i] & projection_matches[j] # Get projections intersections for cameras
MatchesKeys = [] # needed to call into dictionary
for keys in photo_matches.keys(): #convert dictionary keys into list
MatchesKeys.append(keys)
point_match = photo_matches[MatchesKeys[i]] & photo_matches[MatchesKeys[j]] # Get points intersections for cameras
total = len(projection_match)
valid = len(point_match)
invalid = total - valid
total_matches.append((chunk.cameras[i].label, chunk.cameras[j].label, total, valid, invalid)) #the result - photo1, photo2, total, valid, invalid
print (total_matches)