Forum

Author Topic: Import Calibration data from DJI XMP data  (Read 5352 times)

Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Import Calibration data from DJI XMP data
« on: March 02, 2020, 06:38:37 AM »
Hello all,

in latest release, the camera calibration data is imported from DJI XMP meta data. I tested on a Phantom 4 RTK data set and all calibration parameters are correctly imported into Metashape. The XMP data from first image in data set is:

Code: [Select]
---- XMP-drone-dji ----
Absolute Altitude               : +170.42
Relative Altitude               : +100.10
Gps Latitude                    : -36.41144502
Gps Longtitude                  : 174.63075195
Gimbal Roll Degree              : +0.00
Gimbal Yaw Degree               : -1.30
Gimbal Pitch Degree             : -90.00
Flight Roll Degree              : -6.00
Flight Yaw Degree               : +2.50
Flight Pitch Degree             : -15.00
Flight X Speed                  : +0.20
Flight Y Speed                  : +0.00
Flight Z Speed                  : +0.00
Cam Reverse                     : 0
Gimbal Reverse                  : 0
Self Data                       : Undefined
Calibrated Focal Length         : 3666.666504
Calibrated Optical Center X     : 2736.000000
Calibrated Optical Center Y     : 1824.000000
Rtk Flag                        : 16
Rtk Std Lon                     : 1.36853
Rtk Std Lat                     : 1.49256
Rtk Std Hgt                     : 3.18013
Dewarp Data                     :  2018-09-06;3684.480000000000,3677.570000000000,2.240000000000,22.050000000000,-0.263482000000,0.106788000000,0.000037110700,-0.000327247000,-0.030078300000
Dewarp Flag                     : 0

The dewarp data contains date;fx, fy, cx, cy, k1, k2, p1, p2, k3 parameters and these are correctly imported into MS calibration window, except b1 affinity parameter which should be equal to fx - fy = 6.91 (see screen capture). Why is this so?

It seems such high affinity value for b1 is unrealistic as after optimizing and adjusting alignment on 4 GCPs, I get adjusted b1 of 0.1499 which is far from calculated value from Dewarp data....see second attachment


« Last Edit: March 03, 2020, 12:13:31 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #1 on: March 02, 2020, 08:47:58 PM »
Hello Paul,

We have also noticed that the B1 value (as a difference between Fx and Fy) is quite high and we consider it unreliable and intentionally set to 0 when reading DJI calibration information from the XMP meta data.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ruyi7952

  • Full Member
  • ***
  • Posts: 104
    • View Profile
    • My Blog
Re: Import Calibration data from DJI XMP data
« Reply #2 on: March 03, 2020, 04:41:15 AM »
Hello,Alexey

Camera orientation is not obtained from EXIF information。
Real Scene Model Professional Contractor

Collect、Process、Publish

Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #3 on: March 03, 2020, 11:37:41 AM »
Hi again,

just n update on camera distorsion  parameters from DJI XMP Dewarp data.

These parameters are kept in a 1,5  distorsion vector = (k1, k2, p1, p2, k3) according to OpenCV definition from https://docs.opencv.org/master/d4/d94/tutorial_camera_calibration.html

Code: [Select]
For the distortion OpenCV takes into account the radial and tangential factors. For the radial factor one uses the following formula:

xdistorted=x(1+k1r2+k2r4+k3r6)
ydistorted=y(1+k1r2+k2r4+k3r6)
So for an undistorted pixel point at (x,y) coordinates, its position on the distorted image will be (xdistorted, ydistorted). The presence of the radial distortion manifests in form of the "barrel" or "fish-eye" effect.

Tangential distortion occurs because the image taking lenses are not perfectly parallel to the imaging plane. It can be represented via the formulas:

xdistorted=x+[2p1xy+p2(r2+2x2)]
ydistorted=y+[p1(r2+2y2)+2p2xy]
So we have five distortion parameters which in OpenCV are presented as one row matrix with 5 columns:

distortion_coefficients=(k1,k2,p1,p2,k3)

In this OpenCV definition, p1 is equal to p2 definition of Metashape and p2 is equal to p1 definition of Metashape (see appendix C camera models in User manual)....

So actually p2 from Dewarp data should be input to p1 in camera calibration window and p1 from Dewarp data input to p2....
« Last Edit: March 04, 2020, 03:19:55 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #4 on: March 03, 2020, 05:04:50 PM »
Hello Paul,

Thank you for additional input. We'll check that and fix if necessary in the next update.

However, since the values are quite similar I don't think that the current implementation would affect the processing, especially if the calibration parameters are not fixed.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #5 on: March 03, 2020, 10:33:03 PM »
Hi Alexey,

thanks for the update. Quite right that the tangential distorsion parameters are not very significant but as in case of Pix4D , in Dewarp data from DJI, p1, p2 definitions are inverted relative to Agisoft`s.
Best Regards,
Paul Pelletier,
Surveyor

mauroB

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #6 on: August 10, 2023, 06:39:34 PM »
Dear Paulo,

A quick question based on your wide knowledge and experience in photogrammetry and agisoft.

Do you know how agisoft actually compute the distorsion plots in the camera calibration section? I want to be able to directly compare "at the pixel scale" different distorsion profiles..

I tried to made a code, which basically computes the distorsion values along the upper-right semi-diagonal of the frame, strating from the frame center (see file .py attached).

After converting the k1,2,3 and p1,2 vaues (for the used convention see below), the plots computed according the equations in the user manual appendix fit well only for the radial distorsion. Conversely, the tangential distorsion plot differs from the one reported in the camera calibration section (see image attached).

Could you help me?

Thanks in advance,
Mauro

For the parameter values conversion I used the following formulas (from Luhmann et al., 2019):
k1 pixel units = k1 focal units / focal length^2
k2 pixel units = k2 focal units / focal length^4
k3 pixel units = k3 focal units / focal length^6
p1 pixel units = p1 focal units / focal length
p2 pixel units = -p2 focal units / focal length


Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #7 on: August 10, 2023, 08:47:32 PM »
Dear Paulo,

A quick question based on your wide knowledge and experience in photogrammetry and agisoft.

Do you know how agisoft actually compute the distorsion plots in the camera calibration section? I want to be able to directly compare "at the pixel scale" different distorsion profiles..

I tried to made a code, which basically computes the distorsion values along the upper-right semi-diagonal of the frame, strating from the frame center (see file .py attached).

After converting the k1,2,3 and p1,2 vaues (for the used convention see below), the plots computed according the equations in the user manual appendix fit well only for the radial distorsion. Conversely, the tangential distorsion plot differs from the one reported in the camera calibration section (see image attached).

Could you help me?

Thanks in advance,
Mauro

For the parameter values conversion I used the following formulas (from Luhmann et al., 2019):
k1 pixel units = k1 focal units / focal length^2
k2 pixel units = k2 focal units / focal length^4
k3 pixel units = k3 focal units / focal length^6
p1 pixel units = p1 focal units / focal length
p2 pixel units = -p2 focal units / focal length

Ciao Mauro,

it is probable that in your tangential calculation you must invert p1 and p2....

I would do the calculation with pixel based parameters from Agisoft camera calibration and use formulas from appendix of User manual. Plots should correspond....
Best Regards,
Paul Pelletier,
Surveyor

mauroB

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #8 on: August 11, 2023, 12:29:23 PM »
Dear Paulo,

Yes. Overall, I found a little bit of confusion between different formulas and conversion convention.

The formula from Brown is:
D_tang_x = 2P1xy + P2(r^2 + 2x^2)
D_tang_y = 2P2xy + P1(r^2 + 2y^2)

The formula from agisoft basically is just inverted:
D_tang_x = 2P2xy + P1(r^2 + 2x^2)
D_tang_y = 2P1xy + P2(r^2 + 2y^2)

So, since I'm using the formula from agisoft, in the parameter value conversion the values do not have to be inverted.

I don't understand where I'm wrong in this simple job.




Paulo

  • Hero Member
  • *****
  • Posts: 1324
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #9 on: August 11, 2023, 04:39:08 PM »
Hola Mauro,

it seems you are using the right formula from Agisoft. Now  how are u calculating the x, y values to input to tangential formula...they should be unitless. Ie for point at 100 pix in x and 100 pixel in y from Principal point then the values should be (100/fpix,100/fpix) where fpix is the focal in pixels...Then once you have calculated the tangential distorsion in x and y multiply by fpix to get values in pixels...

Hope this is helpful,
Best Regards,
Paul Pelletier,
Surveyor

mauroB

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Import Calibration data from DJI XMP data
« Reply #10 on: August 11, 2023, 08:45:21 PM »
Dear Paulo,

You are right.

Now it seems ok.

Please find attached the correct code, if you need it.

Thanks as usual.

Mauro