Forum

Author Topic: Different cameras parameters between "agisoft XML" and "Bundler" formats ??  (Read 17011 times)

Alou

  • Newbie
  • *
  • Posts: 7
    • View Profile
Hi,

I am trying in an external C++ program to use the generated camera parameters to map vertices with texture coordinates. Is there somewhere I could find a doc for the XML format (how transform matrix is ordered in the XML??). And why is this transform matrix from the XML format different to the one in Bundler format?

Cheers,

Wishgranter

  • Hero Member
  • *****
  • Posts: 1202
    • View Profile
    • Museum of Historic Buildings
BUNDLER use undistorted images......   
----------------
www.mhb.sk

James

  • Hero Member
  • *****
  • Posts: 769
    • View Profile
I worked this out a while ago, can check when I get into the office later. It's something like in the XML format the matrix is inverted and the 3rd row is negated. Don't ask me why! Also it might be the other way round I will have to check my  incomprehensible scribblings, but that might get you started anyway!
« Last Edit: May 12, 2014, 12:54:49 PM by James »

James

  • Hero Member
  • *****
  • Posts: 769
    • View Profile
Also, if you have applied any transformation to your scene using markers or rotated the model, then that is reflected in the individual camera matrices in the bundler file, but not in the XML as it stored as a single transformation matrix.

Alou

  • Newbie
  • *
  • Posts: 7
    • View Profile
Many thanks James, yeah, this prune my search space :) . Any new finding will be welcome though

Alou

James

  • Hero Member
  • *****
  • Posts: 769
    • View Profile
Completely lost my original work, or at least the part that involved me working out the answer, but it was only a couple of months ago so managed to work through it again fairly quick! it was mainly brute force and only the minimum amount of mathematical knowledge of what i was doing...

it will do me good to write this down!

1. the XML format stores the matrix as a row of 16 numbers, so put a 'line break' after each 4th number to get a 4x4 matrix.

Code: [Select]
<transform>9.9979525172066075e-001 1.9951612434278700e-002 -3.3745811729752944e-003 9.2404807307462611e-001 -1.9937006769072906e-002 9.9979195775360141e-001 4.3077804390216183e-003 -3.2245823692836267e-001 3.4598262832987404e-003 -4.2396193807005631e-003 9.9998502750271023e-001 -1.0787526281678460e-002 0.0000000000000000e+000 0.0000000000000000e+000 0.0000000000000000e+000 1.0000000000000000e+000</transform>
becomes

Code: [Select]
9.9979525172066075e-001 1.9951612434278700e-002 -3.3745811729752944e-003 9.2404807307462611e-001
-1.9937006769072906e-002 9.9979195775360141e-001 4.3077804390216183e-003 -3.2245823692836267e-001
3.4598262832987404e-003 -4.2396193807005631e-003 9.9998502750271023e-001 -1.0787526281678460e-002
0.0000000000000000e+000 0.0000000000000000e+000 0.0000000000000000e+000 1.0000000000000000e+000

2. the OUT format stores the matrix as 4 rows of 3 numbers (after a row that encodes lens parameters). Transpose the 4th row to make the 4th column, and then create a 4th row of your own using 0.000 0.000 0.000 1.000 so you now have a 4x4 matrix too.

Code: [Select]
9.9979525172e-001 -1.9937006769e-002 3.4598262833e-003
-1.9951612434e-002 -9.9979195775e-001 4.2396193807e-003
3.3745811730e-003 -4.3077804390e-003 -9.9998502750e-001
-9.3025040491e-001 -3.0390916796e-001 -1.5294719281e-002

becomes

Code: [Select]
9.9979525172e-001 -1.9937006769e-002 3.4598262833e-003 -9.3025040491e-001
-1.9951612434e-002 -9.9979195775e-001 4.2396193807e-003 -3.0390916796e-001
3.3745811730e-003 -4.3077804390e-003 -9.9998502750e-001 -1.5294719281e-002
0.000 0.000 0.000 1.000

3. Now to convert from the XML form to the OUT form, you invert the 4x4 matrix from the XML file. I used the excel function MINVERSE because i love excel and because i'm still very much prototyping all this, which gives you:

Code: [Select]
9.9979525172E-01 -1.9937006769E-02 3.4598262833E-03 -9.3025040491E-01
1.9951612434E-02 9.9979195775E-01 -4.2396193807E-03 3.0390916796E-01
-3.3745811730E-03 4.3077804390E-03 9.9998502750E-01 1.5294719281E-02
0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 1.0000000000E+00

Which is identical to the OUT matrix, except that the 2nd and 3rd rows are negated.

I think that it is the bundler format that requires these rows to be negated, and seems to be something to do with what they refer to in their documentation as perspective division. I am using these matrices to perform triangulation using opencv and am using the matrix out of the bundler out file, but negating the 2nd and 3rd rows to get what i would have got if i'd inverted the photoscan xml matrix. I read in one of the forum posts here from long long ago that photoscan inverts the matrix so that was how i tracked it down.

Hope this helps!
« Last Edit: May 12, 2014, 09:24:46 PM by James »

Alou

  • Newbie
  • *
  • Posts: 7
    • View Profile
Thanks too much James, I think I wouldn't ve figured this inversion think out (or at least would ve taken me ages). I think Photoscan should ve mentioned these kind of stuff somewhere in the doc.

Will update on how these have worked out for me.

Cheers,
Alou

Alou

  • Newbie
  • *
  • Posts: 7
    • View Profile
Hi James,

My transform matrix seems now correct. But when I introduce distortion coefficients on my projection results go weird. Did you take into account distortions when you was doing triangulation.

Thanks,
Alou

James

  • Hero Member
  • *****
  • Posts: 769
    • View Profile
I ignored all the distortion coefficients, and instead used undistorted images in my external app.

I used Tools -> Export -> Undisort Photos... in photoscan