Forum

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

w28

  • Newbie
  • *
  • Posts: 9
    • 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: 50
    • 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: 9869
    • 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: 9
    • 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: 9869
    • 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: 9869
    • 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: 9
    • 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: 61
    • 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: 9869
    • 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: 61
    • 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