Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: smescarzaga on July 03, 2019, 10:56:13 PM

Title: How to return total camera error
Post by: smescarzaga on July 03, 2019, 10:56:13 PM
For Metashape 1.5.2 python API, is there any easy way to simply return the "Total Error" value that is reported at the bottom of the camera reference window?

I'm having trouble getting some of the scripts I've seen in this forum posted for early versions of Photoscan that calculate the difference between actual and estimated camera positions to work in Metashape. It seems like value should be something that is directly access through the API without doing these calculations.
Title: Re: How to return total camera error
Post by: Alexey Pasumansky on July 04, 2019, 09:54:43 PM
Hello smescarzaga,

Error values are not stored in the project and they should be calculated with the script.

In the following script you can check how the estimates location and orientation values are calculated.
https://agisoft.freshdesk.com/support/solutions/articles/31000145016-how-to-calculate-estimated-exterior-orientation-parameters-for-the-cameras-using-python

To get the total error value for the aligned cameras I can suggest the following code:

Code: [Select]
import Metashape, math

chunk = Metashape.app.document.chunk #active chunk
T = chunk.transform.matrix
crs = chunk.crs
sums = 0
num = 0
for camera in chunk.cameras:
    if not camera.transform:
         continue
    if not camera.reference.location:
         continue

    estimated_geoc = chunk.transform.matrix.mulp(camera.center)
    error = chunk.crs.unproject(camera.reference.location) - estimated_geoc
    error = error.norm()
    sums += error**2
    num += 1
print(math.sqrt(sums / num))

Title: Re: How to return total camera error
Post by: smescarzaga on July 06, 2019, 06:09:50 AM
Great, thanks once again Alexey!