Forum

Author Topic: Export Gradual Selection Attributes  (Read 2994 times)

Martin_idk

  • Newbie
  • *
  • Posts: 3
    • View Profile
Export Gradual Selection Attributes
« on: August 15, 2016, 01:50:50 PM »
Hello Alexey and everyone else!

For my current research in the scope of my master thesis i want to export the attributes given in the graduate selection menu for each point to a text file. I've already found the script which allows me to calculate and export the reprojection error, but i don't know how to do that for the reconstruction uncertainty, image count and projection accuracy.

I hope you can help me!

Best regards

Martin

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15029
    • View Profile
Re: Export Gradual Selection Attributes
« Reply #1 on: October 21, 2016, 06:08:02 PM »
Hello Martin,

Here's the script sample that saves among other the requested information (except the reconstruction uncertainty):

Code: [Select]
# Compatibility - Agisoft PhotoScan Professional 1.2.6
# saves the information about the tie points in the sparse cloud according to the following format

# export format:
# point_index X-coord Y-coord Z-coord R_color G_color B_color reproj_error proj_acc image_count

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")
file.write("index\tX-coord\tY-coord\tZ-coord\tR\tG\tB\treproj_error\tproj_acc\timage_count\n")

t0 = time.time()

points_coords = {}
points_errors = {}
points_colors = {}

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
points_errors[point_index].z += proj.size
else:
points_errors[point_index] = PhotoScan.Vector([dist, 1, proj.size])

if not (point_index in points_colors.keys()):
points_colors[point_index] = tracks[track_id].color

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)
count = int(points_errors[point_index].y)
accuracy = points_errors[point_index].z / points_errors[point_index].y
R, G, B = points_colors[point_index]

file.write("{:6d}\t{:.6f}\t{:.6f}\t{:.6f}\t{:3d}\t{:3d}\t{:3d}\t{:.6f}\t{:.2f}\t{:2d}\n".format(point_index, X, Y, Z, R, G, B,error, accuracy, count))

t1 = time.time()

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

Please let me know if you have any comments on the script. You can check it on the very small number of points in the cloud and compare to the values in the Chunk Info dialog.
Best regards,
Alexey Pasumansky,
Agisoft LLC