# Forum

### Author Topic: Exporting TPs with RMS error in xyz  (Read 3170 times)

#### Paulo

• Hero Member
• Posts: 806
##### Exporting TPs with RMS error in xyz
« on: July 31, 2019, 01:08:41 AM »
Hi all,

I am trying to write a script to export to a file the coordinates of all Tie points (after optimizing cameras with Estimate Tie point covariance option) along with the RMSe for X, Y and Z...

from each tie point covariance matrix, I extract diagonal values to calculate X, Y , Z  RMSe as in:
Code: [Select]
`chunk = Metashape.app.document.chunkM = chunk.transform.matrixs = chunk.transform.scalepoints = chunk.point_cloud.pointsnpoints = len(points)for point_id in range(npoints): if not points[point_id].valid: continue if chunk.crs: V = M * (points[point_id].coord) V.size = 3 #print (V) X = chunk.crs.project(V) else: V = M * (points[point_id].coord) X = V rmsXYZ = s * Metashape.Vector([math.sqrt(points[point_id].cov[0,0]), math.sqrt(points[point_id].cov[1,1]), math.sqrt(points[point_id].cov[2,2])])   `
However, I think this represents RMSe along internal X, Y , Z coordinate system....

How do I get the RMSe values corresponding to X, Y, Z of CRS projected coordinate system?

Any help will be greatly appreciated...
« Last Edit: August 01, 2019, 08:08:56 PM by Paulo »
Best Regards,

Paul Pelletier

#### Paulo

• Hero Member
• Posts: 806
##### Re: Exporting TPs with RMS error in xyz
« Reply #1 on: August 03, 2019, 05:42:36 PM »
Any help on this topic?

Best Regards,

Paul Pelletier

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 13309
##### Re: Exporting TPs with RMS error in xyz
« Reply #2 on: August 05, 2019, 06:57:47 PM »
Hello Paulo,

Do you intend to save the variance values as XYZ components for each tie point with this code?
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### Paulo

• Hero Member
• Posts: 806
##### Re: Exporting TPs with RMS error in xyz
« Reply #3 on: August 05, 2019, 07:11:49 PM »
Yes Alexey,

i would like to save in a TPs file, the X, Y, Z, and Error X, Error Y, Error Z for each point of course related to crs projected system as in
Code: [Select]
`Coordenadas de puntos de enlace con sus errores RMS en X,Y,Z, error de reproyeccion promedio y numero de proyeccionesSistema de coordenadas WGS 84 / UTM zone 16N + GGM2010 geoid heightIndex X Y Z Error_X(cm) Error_Y(cm) Error_Z(cm) Error_total(cm) num_obs errrep(pix)0 236376.294 2325813.957 8.117 2.649 3.897 5.733 7.421 2 0.508`
Right now I am using this piece of code to transform error components from internal CS to projected CRS:
Code: [Select]
`M = chunk.transform.matrixs = chunk.transform.scalepoints = chunk.point_cloud.pointsnpoints = len(points)....for point_id in range(npoints): if not points[point_id].valid: continue if chunk.crs: V = M * (points[point_id].coord) V.size = 3 #print (V)                X = chunk.crs.project(V) m = chunk.crs.localframe(V) R = m.rotation() * M.rotation() rmsXYZ = s * Metashape.Vector([math.sqrt(points[point_id].cov[0,0]), math.sqrt(points[point_id].cov[1,1]), math.sqrt(points[point_id].cov[2,2])]) rmsXYZ = R * rmsXYZ rmsXYZ = Metashape.Vector([abs(rmsXYZ.x),abs(rmsXYZ.y),abs(rmsXYZ.z)]) rmsXYZ = 100 * rmsXYZ`
« Last Edit: August 06, 2019, 03:36:47 AM by Paulo »
Best Regards,

Paul Pelletier

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 13309
##### Re: Exporting TPs with RMS error in xyz
« Reply #4 on: August 18, 2019, 07:55:45 PM »
Hello Paul,

The following script should save XYZ coordinates for the tie points, variance vector length and it's XYZ components:
Code: [Select]
`import Metashape, mathpath = Metashape.app.getSaveFileName("Specify the export file path:", filter = "Text file (*.txt);;All formats (*.*)")file = open(path, "wt")file.write("Id\tX\tY\tZ\tvar\tcov_x\tcov_y\tcov_z\n")chunk = Metashape.app.document.chunkT = chunk.transform.matrixif chunk.transform.translation and chunk.transform.rotation and chunk.transform.scale: T = chunk.crs.localframe(T.mulp(chunk.region.center)) * TR = T.rotation() * T.scale()for point in chunk.point_cloud.points: if not point.valid: continue cov = point.cov coord = point.coord coord = T * coord cov = R * cov * R.t() u, s, v = cov.svd() var = math.sqrt(sum(s)) #variance vector length vect = (u.col(0) * var) file.write(str(point.track_id)) file.write("\t{:.6f}\t{:.6f}\t{:.6f}\t{:.6f}".format(coord[0], coord[1], coord[2], var)) file.write("\t{:.6f}\t{:.6f}\t{:.6f}".format(vect.x, vect.y, vect.z)) file.write("\n") file.close()`
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### Paulo

• Hero Member
• Posts: 806
##### Re: Exporting TPs with RMS error in xyz
« Reply #5 on: August 19, 2019, 03:37:12 AM »
Thanks a thousand, Alexey.

the only detail is that it prints out the X,Y,Z coordinates of TiePts in LRS (East, North, Up) with origin at region center as seen in:

Code: [Select]
`Id X Y Z var cov_x cov_y cov_z21 -174.021457 -396.605524 640.282965 0.033728 -0.006520 -0.002776 0.032975`
so I changed
Code: [Select]
`coord = T * point.coord `with
Code: [Select]
`V = chunk.transform.matrix * point.coordV.size = 3X, Y, Z = chunk.crs.project(V)`
also I use directly point.id instead of point.track_id and absolute value of each vect component...

and resulting first lines of export file is (RMSe values in cm)
Code: [Select]
`Coordenadas de puntos de enlace con sus errores RMS en X,Y,Z, numero de proyecciones y error de reproyeccion promedio Sistema de coordenadas WGS 84 / UTM zone 14N +  GGM2010 geoid heightIndex X Y Z Error X(cm) Error Y(cm) Error Z(cm) Total(cm) num_obs errrep(pix)0 346248.403 2852992.029 659.232 0.652 0.278 3.298 3.373 8 0.380`
« Last Edit: August 20, 2019, 08:04:01 AM by Paulo »
Best Regards,

Paul Pelletier

#### antoine billault

• Newbie
• Posts: 4
##### Re: Exporting TPs with RMS error in xyz
« Reply #6 on: July 26, 2021, 10:21:10 AM »
Hello Paul
I need to perform the same task
I wanted to ask if you can clarify your modification you pointed out in your last post
Quote
so I changed
Code: [Select]

coord = T * point.coord

with
Code: [Select]

V = chunk.transform.matrix * point.coord
V.size = 3
X, Y, Z = chunk.crs.project(V)

As you introduce
Code: [Select]
`V = chunk.transform.matrix * point.coordV.size = 3X, Y, Z = chunk.crs.project(V)`
I was wondering if  you still use

Code: [Select]
`T = chunk.crs.localframe(T.mulp(chunk.region.center)) * T`
THANKS

antoine

#### Paulo

• Hero Member
• Posts: 806
##### Re: Exporting TPs with RMS error in xyz
« Reply #7 on: July 26, 2021, 11:06:37 AM »
Hello Antoine,

the code change was to print out the coordinates of each tiepoint in chunk crs....

the line T = chunk.crs.localframe(T.mulp(chunk.region.center)) * T is still used to calculate the matrix R that lets you transform the covariance matrix from internal CS to LSE  CS....

Best Regards,

Paul Pelletier

#### antoine billault

• Newbie
• Posts: 4
##### Re: Exporting TPs with RMS error in xyz
« Reply #8 on: July 27, 2021, 01:39:35 AM »
thank you Paul