Forum

Author Topic: Accessing standard error value after optimizeCameras in python  (Read 7656 times)

w28

  • Newbie
  • *
  • Posts: 11
    • View Profile
Accessing standard error value after optimizeCameras in python
« on: February 22, 2018, 11:18:00 PM »
Is there a way to get the standard error of unit weight after you run the optimizeCameras method in python? 

I believe this is the value printed in the console when you run Optimize Cameras in the GUI, like this:
>>Optimizing camera locations ...
>>adjusting: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 0.489454 -> 0.489437

Is there a way to get this value (0.489437) through the python API? 

It seems like this would be returned from the chunk.optimizeCameras method, or it would be available in the chunk.meta object, but I don't see it anywhere.

Any help would be greatly appreciated.

Thanks.

macsurveyr

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #1 on: March 16, 2018, 01:41:05 AM »
I am also interested if this value can be accessed through python

Tom

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #2 on: March 22, 2018, 03:48:59 PM »
Hello,

The following code should calculate the reprojection error in pixels for the active chunk:
Code: [Select]
import PhotoScan, math

chunk = PhotoScan.app.document.chunk

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


err_sum = 0
num = 0

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

T = camera.transform.inv()
calib = camera.sensor.calibration
point_index = 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

coord = T * points[point_index].coord
coord.size = 3
dist = calib.error(coord, proj.coord).norm() ** 2
err_sum += dist
num += 1

sigma = math.sqrt(err_sum / num)
print(sigma)
Best regards,
Alexey Pasumansky,
Agisoft LLC

w28

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #3 on: May 09, 2018, 08:54:47 PM »
Thank you for the code snippet.  I placed your code into a script ('calcOptimizeCamerasError.py') and tried it out on a small test project.  Unfortunately it doesn't reproduce the error value printed in the console. 

Here's the console output from Optimize Cameras:

Code: [Select]
2018-05-09 10:50:07 OptimizeCameras: f, cx, cy, k1-k3, p1, p2
2018-05-09 10:50:07 Optimizing camera locations...
2018-05-09 10:50:07 adjusting: xxxxx- 0.922438 -> 0.922438
2018-05-09 10:50:07 coordinates applied in 0 sec
2018-05-09 10:50:07 Finished processing in 0.318 sec (exit code 1)

Here's the output from the script:
Code: [Select]
run calcOptimizeCamerasError.py
2018-05-09 10:50:20 0.4755864736517061

Is there any other way to access the standard error value from OptimizeCameras?

Thanks again for your help with this.


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #4 on: May 14, 2018, 12:15:46 PM »
Hello w28,

Sorry for confusion. My code example estimates only reprojection error, the value in the optimization log requires some additional calculations. I'll try to suggest the code sample for it, also we will consider adding this value to chunk meta information to be accessible via Python.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #5 on: May 22, 2018, 09:41:37 PM »
Hello w28,

It appeared to be easier to include the number to chunk.meta rather than recalculating it via script, so in the next version update this number will be available via chunk.meta.
Best regards,
Alexey Pasumansky,
Agisoft LLC

w28

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #6 on: May 24, 2018, 07:14:18 AM »
Fantastic.   I’ll look for this in the next update.  Thanks for the response.

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #7 on: February 12, 2019, 04:22:38 AM »
Any news about this feature in Metashape?
Luiz Fernando

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #8 on: February 12, 2019, 03:41:36 PM »
Hello Luiz,

Please check:
Code: [Select]
chunk.meta['optimize/sigma0']
Best regards,
Alexey Pasumansky,
Agisoft LLC

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #9 on: February 13, 2019, 03:54:02 PM »
Thank you Alexey!

Hello Luiz,

Please check:
Code: [Select]
chunk.meta['optimize/sigma0']
Luiz Fernando

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #10 on: November 14, 2019, 07:38:41 AM »
Hey there, Alexey!

In what units the sigma0 is present by accessing it by chunk.meta? Pixels, meters? Or is it unitless?
0.116893 -> 0.115939

Thanks!
« Last Edit: November 14, 2019, 07:41:02 AM by LFSantosgeo »
Luiz Fernando

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #11 on: November 21, 2019, 05:47:27 PM »
I'm guessing sigma0 is in pixels as Metashape weights tie point accuracy in pixels... Can anyone confirm it?
Luiz Fernando

3DWinter

  • Full Member
  • ***
  • Posts: 103
    • View Profile
Re: Accessing standard error value after optimizeCameras in python
« Reply #12 on: July 27, 2022, 05:58:22 PM »
@w28 or @Alexey,
Can one of you shed light on what sigma0 stands for and how is it calculated? I see that it is OptimizeCameras/sigma0. So does sigma0 represent the standard deviation of the camera parameters (f,cx,cy,k1,k2,k3) in pixels?

How do I interpret this value?
[/code]

Code: [Select]
2022-07-27 10:25:07 adjusting: xxx- 0.743908 -> 0.449964
Thanks
« Last Edit: July 27, 2022, 06:37:45 PM by 3DWinter »