Forum

Author Topic: Export reprojection errors for each tie points  (Read 4076 times)

emi1975

  • Newbie
  • *
  • Posts: 2
    • View Profile
Export reprojection errors for each tie points
« on: April 28, 2016, 10:26:09 AM »
Hi all,
I would like to export the reprojection error of a sparse point cloud in order to perform accuracy assessment of my results.

There is a previous topic about it (http://www.agisoft.com/forum/index.php?topic=3771.msg20283#msg20283) but the script doesn't work with the new Photoscan release.

Can anyone help me?

Regards.
« Last Edit: April 28, 2016, 11:05:27 AM by emi1975 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13302
    • View Profile
Re: Export reprojection errors for each tie points
« Reply #1 on: May 10, 2016, 01:04:43 PM »
Hello emi1975,

Please use the updated script for these purposes:
Code: [Select]
# Compatibility - Agisoft PhotoScan Professional 1.2.4
# saves reprojection error for the tie points in the sparse cloud

# export format:
# point_index X-coord Y-coord Z-coord reproj_error

import PhotoScan
import math, time

doc = PhotoScan.app.document
chunk = doc.chunk
M = chunk.transform.matrix
crs = chunk.crs
point_cloud = chunk.point_cloud
projections = point_cloud.projections
points = point_cloud.points
npoints = len(points)
tracks = point_cloud.tracks

path = PhotoScan.app.getSaveFileName("Specify export path and filename:")
file = open(path, "wt")
print("Script started")

t0 = time.time()

points_coords = {}
points_errors = {}

for photo in chunk.cameras:

if not photo.transform:
continue

T = photo.transform.inv()
calib = photo.sensor.calibration

point_index = 0
for proj in projections[photo]:
track_id = proj.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 not points[point_index].valid:
continue

coord = T * points[point_index].coord
coord.size = 3
dist = calib.error(coord, proj.coord).norm() ** 2
v = M * points[point_index].coord
v.size = 3

if point_index in points_errors.keys():
point_index = int(point_index)
points_errors[point_index].x += dist
points_errors[point_index].y += 1
else:
points_errors[point_index] = PhotoScan.Vector([dist, 1])

for point_index in range(npoints):

if not points[point_index].valid:
continue

if chunk.crs:
w = M * points[point_index].coord
w.size = 3
X, Y, Z = chunk.crs.project(w)
else:
X, Y, Z, w = M * points[point_index].coord

error = math.sqrt(points_errors[point_index].x / points_errors[point_index].y)

file.write("{:6d}\t{:.6f}\t{:.6f}\t{:.6f}\t{:.6f}\n".format(point_index, X, Y, Z, error))

t1 = time.time()

file.flush()
file.close()
print("Script finished in " + str(int(t1-t0)) + " seconds.")
Best regards,
Alexey Pasumansky,
Agisoft LLC

Paulo

  • Hero Member
  • *****
  • Posts: 805
    • View Profile
Re: Export reprojection errors for each tie points
« Reply #2 on: May 10, 2016, 04:30:29 PM »
Thank you, Alexei.

However, I have a question. In the line calculating the reprojection error for each tie point, it seems that it sqares the error.

Quote
dist = calib.error(coord, proj.coord).norm() ** 2

Why is this so?
Best Regards,

Paul Pelletier

Paulo

  • Hero Member
  • *****
  • Posts: 805
    • View Profile
Re: Export reprojection errors for each tie points
« Reply #3 on: May 10, 2016, 04:34:11 PM »
Sorry, my fault ...

I saw that it does a sqroot of total error for each point at the end...

Disregard...
Best Regards,

Paul Pelletier

Daniele

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Export reprojection errors for each tie points
« Reply #4 on: August 25, 2021, 11:25:20 AM »
Hello emi1975,

Please use the updated script for these purposes:
Code: [Select]
# Compatibility - Agisoft PhotoScan Professional 1.2.4
# saves reprojection error for the tie points in the sparse cloud

# export format:
# point_index X-coord Y-coord Z-coord reproj_error

import PhotoScan
import math, time

doc = PhotoScan.app.document
chunk = doc.chunk
M = chunk.transform.matrix
crs = chunk.crs
point_cloud = chunk.point_cloud
projections = point_cloud.projections
points = point_cloud.points
npoints = len(points)
tracks = point_cloud.tracks

path = PhotoScan.app.getSaveFileName("Specify export path and filename:")
file = open(path, "wt")
print("Script started")

t0 = time.time()

points_coords = {}
points_errors = {}

for photo in chunk.cameras:

if not photo.transform:
continue

T = photo.transform.inv()
calib = photo.sensor.calibration

point_index = 0
for proj in projections[photo]:
track_id = proj.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 not points[point_index].valid:
continue

coord = T * points[point_index].coord
coord.size = 3
dist = calib.error(coord, proj.coord).norm() ** 2
v = M * points[point_index].coord
v.size = 3

if point_index in points_errors.keys():
point_index = int(point_index)
points_errors[point_index].x += dist
points_errors[point_index].y += 1
else:
points_errors[point_index] = PhotoScan.Vector([dist, 1])

for point_index in range(npoints):

if not points[point_index].valid:
continue

if chunk.crs:
w = M * points[point_index].coord
w.size = 3
X, Y, Z = chunk.crs.project(w)
else:
X, Y, Z, w = M * points[point_index].coord

error = math.sqrt(points_errors[point_index].x / points_errors[point_index].y)

file.write("{:6d}\t{:.6f}\t{:.6f}\t{:.6f}\t{:.6f}\n".format(point_index, X, Y, Z, error))

t1 = time.time()

file.flush()
file.close()
print("Script finished in " + str(int(t1-t0)) + " seconds.")





Hi Alexey,
I have started a new post here https://www.agisoft.com/forum/index.php?topic=13675.0 concerning this subject...Maybe I was wrong and I should add a reply here...Let me know if it's ok and in case I will remove the other similar post...In the meanwhile, I run this script and a text file is generated so the script still works also for methashape. However, I checked that the reproject error is not my target because I would need precision estimates (sigma) of each point for X,Y and Z components (sigmaX, sigmaY and sigmaZ).

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 13302
    • View Profile
Re: Export reprojection errors for each tie points
« Reply #5 on: August 25, 2021, 12:14:01 PM »
Hello Daniele,

I have posted the script for Sigma export to your original thread.
Best regards,
Alexey Pasumansky,
Agisoft LLC