Forum

Author Topic: Focal length differences in xml and chan export  (Read 9519 times)

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Focal length differences in xml and chan export
« on: December 16, 2014, 11:01:47 PM »
Hi,

first sorry for being a rookie.
I have to appologize for my questions, I'm sure that some of you will probably answer them easily and help me.

I'm trying to help a friend who wants to use photoscan in his work but can't import correctly the alignement done in photoscan in another software.
The xml export is very interesting because it keeps bg image informations for each camera (I want to use this), and also the transformation matrix of each cam. But I can't get a correct focal lenght from it.
On the other hand, in the chan export, I have everything i need but the name of bg images for each cam.

So, I'm trying to understand how I can calculate the focal length that is exported in a chan file, from the data that I have in the xml export of the same photoscan alignement. They are differents.
In the xml, I have a focal recalculated, in some units that I don't understand, distorsions factors, etc... and in the chan export, I have just what I need.
But, I can't figure out, how you get the value that is stored in the chan file with some magic formula applied to the values I can get from the xml export.

Can you help me to help my friend? :)

Thank you,
T.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #1 on: December 18, 2014, 04:43:52 PM »
Hello tcherno,

In .chan format vertical field of view is saved and not focal length.

To calculate this value from the values saved in .xml file you need to do the following:
fov = 2 *atan(height/2 / fy) * 180 / Pi,
here height is vertical dimensions of image frame,
fy - focal length in pixels.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #2 on: December 19, 2014, 12:48:25 PM »

Thank you very much for your very useful answer!

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #3 on: December 19, 2014, 05:29:59 PM »
Hi again,

I tried the formula you gave me but my english and my camera science are not as accurate as I need to make it work.
I don't  have the same result than in the chan file...

I tried this to test it :


## Values I just copy from the xml manually for the test
fy =7.9821037943715528e+03
foc = 5.0000000000000000e+01

import math
fov = 2.0 * math.atan( (fy-foc)/2 /fy) * 180.0 / 3.1415926535897932384626433832795
print fov
# >>> 52.8426216048
 
and in the chan I have a fov = 27.2532

It must be the height that I didn't understand well in your reply.
Sorry about that, could you tell me more about it please?

Thanks again very much for your help.




Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #4 on: December 19, 2014, 05:34:31 PM »
Hello tcherno,

Height is the y-resolution of the image in pixels. Also you can use math.pi in your code line.

According to the output in your case it should be something close to 3872 pix.
« Last Edit: December 19, 2014, 06:05:28 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #5 on: January 14, 2015, 05:29:46 PM »
Hi again.

I don't understand why the formula doesn't give me the same result than in a fbx export.
Please, can you tell me how to extract these two values from the xml to match exactly the values in a fbx export?

focal lenght
camera aperture (inches or mm, I don't care)

In the xml I have this :

    <sensors>
      <sensor id="0" label="Canon EOS 5D Mark II (50 mm)" type="frame">
        <resolution width="5616" height="3744"/>
        <property name="pixel_width" value="6.5490028490028532e-003"/>
        <property name="pixel_height" value="6.5490028490028532e-003"/>
        <property name="focal_length" value="5.0000000000000000e+001"/>
        <property name="fixed" value="false"/>
        <calibration type="frame" class="adjusted">
          <resolution width="5616" height="3744"/>
          <fx>8.5637711649369339e+003</fx>
          <fy>8.5637711649369339e+003</fy>
          <cx>2.8211809761145587e+003</cx>
          <cy>1.8677934082374925e+003</cy>
          <k1>-5.3464376564462150e-003</k1>
          <k2>-2.1316748876923912e-002</k2>
          <k3>2.0992605355326971e-001</k3>
        </calibration>
      </sensor>
    </sensors>

In the relative fbx I have these values (that's what I would like to be able to calculate):
focal length : 58.098
camera aperture in mm : 38.100 and 25.400


and when I try to calculate them with the formula I get (wrong result):
focal length : 50.000
camera aperture : 36.992 and 24.661


I'm probably wrong, so could you give me the good formulas to get the good values please (fbx values works fine)?

Thank you again!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #6 on: January 14, 2015, 05:36:48 PM »
Hello tcherno,

focal length in mm = (fy * sensor_pixel_height + fx *sensor_pixel_width) / 2 = 56.08 according to your example data.
Best regards,
Alexey Pasumansky,
Agisoft LLC

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #7 on: January 14, 2015, 07:22:02 PM »
Ok, thank you very much.

And what about the camera aperture?

How do you get the 38.100 and 25.400 values from the xml?
Do I miss something else?


EDIT :

Ok, I found how to calculate the camera aperture values that are exported (fbx) :
camera aperture W = imageWidth * 25.4 / imageHeight
camera aperture H = 25.4
(I guess the 25.4 factor comes from the unit conversion mm to inches)

I'm not sure this is correct, because I thought that these values depends on the sensor size of the camera, which is not 38.1 and 25.4 on the Canon 5D Mark II my friend is using.
Maybe you can enlight me here too.


« Last Edit: January 19, 2015, 05:18:51 AM by tcherno »

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #8 on: January 18, 2015, 03:13:05 AM »
Hi.
Thank you very much for your answers Alexey.

It seems to be almost good with the focal length, but the result of the formula you gave me :

focal = (fy*sensor_pixel_height + fx*sensor_pixel_width)/2
focal = 56.084

is unfortunately not the same than the focal I have in the fbx file (=58.098).

The fbx export is correct, and the camera matches the model and the image Plane in Maya. So I really need to get the same exact formula you applie to export the cameras to a fbx file.

I'm stuck with this problem, and I know that it's probably nothing.
Please, can you help me?




Dmitry Semyonov

  • Agisoft Technical Support
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #9 on: January 19, 2015, 02:27:16 PM »
Hello tcherno,

Currently PhotoScan normalizes all camera parameters to the effective film height equal to 25.4 mm during FBX export.

All properties that describe metric properties of the sensor (FilmWidth, FilmHeight and FocalLength) are multiplied by the same factor, so that FilmHeight written to final FBX file equals to 25.4 mm.

Such multiplication doesn’t change camera projection in any way, as it depends only on the ratios of those values (for example, using a camera with 1.5 crop factor you can take exactly the same photo as you could do with a full frame camera,  as far as you adjust the focal length 1.5 times as well). So there should not be any mismatch when using FBX exported from PhotoScan in Maya.

Because of such normalization FilmWidth, FilmHeight and FocalLength values written to FBX doesn’t depend on pixel size values configured in Camera Calibration dialog.

Please let us know if such normalization introduces any problems, or if it is not convenient in any way.
With best regards,
Dmitry Semyonov
Agisoft

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #10 on: January 19, 2015, 02:51:31 PM »
Hello Dmitry and thank you for your answer.

Yes I understand perfectly your explanation about the sensor size height and width.
It works when the ratio is correct, even if the values are not in a "real scale".

But I need to calculate the focal_length that you export in the fbx file, and I can't reach the good value with the formula Alexey gave me.
As you can see, I get a more than 2 deg difference...

fbx focal : 58.098
formula focal : 56.084

This is my big problem.
I unfortunately can't solve it alone.

I give you the values exported in the xml (the crop factor of the camera = 1) :

       <sensor id="0" label="Canon EOS 5D Mark II (50 mm)" type="frame">
        <resolution width="5616" height="3744"/>
        <property name="pixel_width" value="6.5490028490028532e-003"/>
        <property name="pixel_height" value="6.5490028490028532e-003"/>
        <property name="focal_length" value="5.0000000000000000e+001"/>
        <property name="fixed" value="false"/>
        <calibration type="frame" class="adjusted">
          <resolution width="5616" height="3744"/>
          <fx>8.5637711649369339e+003</fx>
          <fy>8.5637711649369339e+003</fy>
          <cx>2.8211809761145587e+003</cx>
          <cy>1.8677934082374925e+003</cy>
          <k1>-5.3464376564462150e-003</k1>
          <k2>-2.1316748876923912e-002</k2>
          <k3>2.0992605355326971e-001</k3>
        </calibration>
      </sensor>

I try this :

fx = 8.5637711649369339e+003
fy = 8.5637711649369339e+003
pixelHeight = 6.5490028490028532e-003
pixelWidth = 6.5490028490028532e-003

focal = (fx*pixelHeight+fy*pixelWidth)/2
focal = 56.0841617574

and in the fbx openend in Maya 2015, I have a value of 58.098, which seems to be correct and match the model.

Can you tell me where is the problem in the calculation please?








Dmitry Semyonov

  • Agisoft Technical Support
  • Full Member
  • *****
  • Posts: 200
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #11 on: January 19, 2015, 03:03:14 PM »
Hello tcherno,

If we normalize sensor height to 25.4 mm, we will obtain the following effective pixel size:
pixelSize = 25.4 / 3744

after this normalization:
filmWidth = pixelSize * 5616 = 38.1
filmHeight = pixelSize * 3744 = 25.4
focalLength = pixelSize * (fx + fy) / 2 = 58.098

Please let us know if it helps.
With best regards,
Dmitry Semyonov
Agisoft

tcherno

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Focal length differences in xml and chan export
« Reply #12 on: January 19, 2015, 03:16:38 PM »
Okay!
I get it.
Thank you very much for your very fast answers.
I can do everything that I need.

You rock.

;)