1

**Python Scripting / Reprojection error**

« **on:**March 10, 2019, 01:46:14 PM »

Hello,

I got the following code to calculate max and rms reprojection errors:

Sometimes it doesn't work at all at getting the values and sometimes it does. I haven't manage to figure out why. Can anyone help out?

I got the following code to calculate max and rms reprojection errors:

Code: [Select]

def RMS_MAX_reprojection_error(chunk):

cameras = chunk.cameras

point_cloud = chunk.point_cloud

points = point_cloud.points

projections_per_camera = point_cloud.projections

tracks = point_cloud.tracks

point_squared_errors = [[] for i in range(len(points))]

point_key_point_size = [[] for i in range(len(points))]

track_cameras = [[] for i in range(len(tracks))]

track_projections = [[] for i in range(len(tracks))]

for camera_id, camera in enumerate(cameras):

if camera not in projections_per_camera:

continue

projections = projections_per_camera[camera]

for projection_id, projection in enumerate(projections):

track_id = projection.track_id

track_cameras[track_id].append(camera_id)

track_projections[track_id].append(projection_id)

for i, point in enumerate(points):

if point.valid is False: # se válido faz a estatística abaixo

continue

track_id = point.track_id

for idx in range(len(track_cameras[track_id])):

camera_id = track_cameras[track_id][idx]

projection_id = track_projections[track_id][idx]

camera = cameras[camera_id]

projections = projections_per_camera[camera]

projection = projections[projection_id]

key_point_size = projection.size

error = camera.error(point.coord, projection.coord) / key_point_size

point_squared_errors[i].append(error.norm() ** 2)

total_squared_error = sum([sum(el) for el in point_squared_errors])

# nº projeções

total_errors = sum([len(el) for el in point_squared_errors])

max_squared_error = max([max(el+[0])

for i, el in enumerate(point_squared_errors)])

rms_reprojection_error = math.sqrt(total_squared_error/total_errors)

max_reprojection_error = math.sqrt(max_squared_error)

return rms_reprojection_error, \

max_reprojection_error

Sometimes it doesn't work at all at getting the values and sometimes it does. I haven't manage to figure out why. Can anyone help out?