Forum

Author Topic: export projections & error (pix) for every camera  (Read 3958 times)

uop360

  • Newbie
  • *
  • Posts: 18
    • View Profile
export projections & error (pix) for every camera
« on: April 26, 2016, 04:53:50 PM »
Hello,
how can I export a number of projections and error (pix) for every camera?
Karol

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14004
    • View Profile
Re: export projections & error (pix) for every camera
« Reply #1 on: April 26, 2016, 05:29:52 PM »
Hello Karol,

You can use the following script to calculate the average reprojection error in pixels for each camera and the number of valid projections:

Code: [Select]
import math
import PhotoScan

def calc_reprojection(chunk):

point_cloud = chunk.point_cloud
points = point_cloud.points
npoints = len(points)
projections = chunk.point_cloud.projections

err_sum = 0
num = 0

photo_avg = {}

for camera in chunk.cameras:
if not camera.transform:
continue

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

point_index = 0
photo_num = 0
photo_err = 0
for proj in projections[camera]:
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

#dist = calib.error(T.mulp(points[point_index].coord), proj.coord).norm() ** 2
dist = camera.error(points[point_index].coord, proj.coord).norm() ** 2

err_sum += dist
num += 1
photo_num += 1
photo_err += dist

photo_avg[camera.label] = (math.sqrt(photo_err / photo_num), photo_num)

sigma = math.sqrt(err_sum / num)
rep_avg = sigma

return (rep_avg, photo_avg)


doc = PhotoScan.app.document
chunk = doc.chunk

total_error, ind_error = calc_reprojection(chunk)
print(total_error, ind_error)
Best regards,
Alexey Pasumansky,
Agisoft LLC

uop360

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: export projections & error (pix) for every camera
« Reply #2 on: April 26, 2016, 10:02:41 PM »
Hello Alexey,
thank you for your help.
can it be saved in a txt file?
What is the order of the file content?
I have such results:
Quote
'ladybug_panoramic_000573.png': (1.0790776553543695, 2451), 'ladybug_panoramic_000442.png': (0.9239556223568349, 2330), 'ladybug_panoramic_000614.png': (1.091195176850109, 1756), 'ladybug_panoramic_000615.png': (0.9050643234519736, 2102), 'ladybug_panoramic_000670.png': (1.2253694545436022, 2077), 'ladybug_panoramic_000565.png': (0.9877758236079004, 2614)}
regards
Karol

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14004
    • View Profile
Re: export projections & error (pix) for every camera
« Reply #3 on: April 27, 2016, 11:35:32 AM »
Hello Karol,

With the redirection to file it will be the following:
Code: [Select]
import math
import PhotoScan

def calc_reprojection(chunk):

point_cloud = chunk.point_cloud
points = point_cloud.points
npoints = len(points)
projections = chunk.point_cloud.projections

err_sum = 0
num = 0

photo_avg = {}

for camera in chunk.cameras:
if not camera.transform:
continue

T = camera.transform.inv()
calib = camera.sensor.calibration
point_index = 0
photo_num = 0
photo_err = 0
for proj in projections[camera]:
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

#dist = calib.error(T.mulp(points[point_index].coord), proj.coord).norm() ** 2
dist = camera.error(points[point_index].coord, proj.coord).norm() ** 2

err_sum += dist
num += 1
photo_num += 1
photo_err += dist

photo_avg[camera.label] = (math.sqrt(photo_err / photo_num), photo_num)

sigma = math.sqrt(err_sum / num)
rep_avg = sigma

return (rep_avg, photo_avg)

doc = PhotoScan.app.document
chunk = doc.chunk

path = PhotoScan.app.getSaveFileName("Specify the export path:")
file = open(path, "wt")

total_error, ind_error = calc_reprojection(chunk)

file.write("\t".join(["#label","error_pix","proj_num\n"]))
for camera in ind_error.keys():
file.write("\t".join([camera, str(ind_error[camera][0]), str(ind_error[camera][1])])+"\n")

file.close()
print(total_error, ind_error)

first column - camera label, second column - average reprojection error in pixels on the photo, third column - number of tie points on the image.
Best regards,
Alexey Pasumansky,
Agisoft LLC

uop360

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: export projections & error (pix) for every camera
« Reply #4 on: April 27, 2016, 03:38:56 PM »
thank you.