Forum

Author Topic: Generate XML from known X0 Y0 Z0 Phi Theta Kappa  (Read 13942 times)

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« on: May 27, 2015, 02:01:14 AM »
Hey Community!

I'm trying to create a PhotoScan XML with (exact known) external orientation of my pictures.

e.g. from the source-XML
Code: [Select]
<ExteriorOrientation ProjectionCenterX="2615026.7295406177" ProjectionCenterY="1264749.1027027234" ProjectionCenterZ="11.514140756119859" Phi="223.67397153859164" Theta="98.160773064550852" Kappa="0" />
Now I want to write the <transform>, the <orientation> and the <reference> tag to import the cameras later to PhotoScan.
Can anybody tell me how to calculate the coefficients of the matrix / tags?
Is the <reference> tag simply
Code: [Select]
<reference x="2.615027E+06" y="1.264749E+06" z="6.1856E-02" enabled="true"/>?

(I will fix the existing precision problem by myself)

Thanks for your help!

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #1 on: May 29, 2015, 03:24:11 PM »
FYI:

The phi is the azimut (in code a, clockwise), theta (in code b) is the elevation (top-down) and kappa (in code c) is the roll angle (=0) - the angles are exported from a tachymeter.
I tried to calculate the <transform> content by transforming 3 estimated angles from a photo an aligned PS project in python with
Code: [Select]
R = matrix([[cos(a)*cos(b),cos(a)*sin(b)*sin(c)-sin(a)*cos(c),cos(a)*sin(b)*cos(c)+sin(a)*sin(c)],[sin(a)*cos(b),sin(a)*sin(b)*sin(c)+cos(a)*cos(c),sin(a)*sin(b)*cos(c)-cos(a)*sin(c)],[-sin(b),cos(b)*sin(c),cos(b)*cos(c)]])Formula (wiki):


and compared it with the exported PhotoScan XML - wasn't the same :-(
How can I do this properly?
Is the problem here
Code: [Select]
<transform>
  <rotation>...</rotation>
  <translation>4.2707707729293248e+006 5.9220347817360156e+005 4.6838758843945879e+006</translation>
  <scale>1.6557499445208805e+001</scale>
</transform>
?
As I read here, the fourth row should contain the translation vector, but there aren't the estimated coordinates from the photo in the PS project


Second question is solved: <reference> only contains approx. coordinates e.g. from GPS data import.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #2 on: May 29, 2015, 03:47:59 PM »
Hello Jappert,

I've just posted a code to generate camera transformation matrix from XYZ + OPK data:

http://www.agisoft.com/forum/index.php?topic=3901.msg20329#msg20329
Best regards,
Alexey Pasumansky,
Agisoft LLC

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #3 on: May 29, 2015, 05:02:27 PM »
Thanks Alexey!

It will be necessary to create the full PhotoScan XML external, because there is a lot of parsing already done - just need the transformation matrix.
External means there is no PhotoScan module (in my PyCharm project). I do the matrix calculation with numpy.matrix

What I don't understand: Why is there a transform tag at the end of the PhotoScan XML and one for each picture? Are they transformed twice? Can I leave the CRS as local coordinates, fill in the right column of the transform tag of each picture the full coordinates and in the upper left 3x3 part the Rz*Ry*Rx from the omega phi kappa with forumla from before? The transform tag at the end will then be
Code: [Select]
<transform>
      <rotation>1 0 0 0 1 0 0 0 1</rotation>
      <translation>0e+000 0e+000 0e+000</translation>
      <scale>1e+000</scale>
</transform>

Sorry for annoying, I'm a bit under pressure

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #4 on: May 29, 2015, 06:24:18 PM »
Hello Jappert,

Each camera instance have transform matrix in XML that defines the camera position and orientation in the internal coordinate space.
In the end of the XML there's transform section related to the chunk.transform matrix that converts the coordinates from the internal coordinate system to geocentric (or local) coordinate system.

In your project do you have geographic coordinate system or local?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #5 on: May 29, 2015, 06:44:12 PM »
Hello Alexey

Thanks again for the quick response

Ah ok, that's what I thought with the "double transformation". It makes it for me much more difficult because while generating the PhotoScan XML I don't know the internal coorinate space information yet.

In this moment I haven't selected a geographic coordinate system, but the XYZ and Phi/Theta/Kappa are of course related to one. For the test of this application I think it's not necessary to take one.

Can you take a quick look at the files I attached?
  • HeXML2PhotoScanXML.py is the python script to translate
  • agi_xml.xml is the output XML written with the python script
  • ph-fass.xml is the XML conatining the external information of the cameras (search for "TPSImage" to get it)

I just opened a new PS project, added the photos and tried to "Import Cameras..." with the agi_xml.xml but except of detecting tie points nothing happened - the estimated X Y Z Yaw Pitch Roll are still empty
« Last Edit: May 29, 2015, 06:49:31 PM by Jappert »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #6 on: May 29, 2015, 08:20:02 PM »
Hello Jappret,

Could you please also send the project file saved after loading cameras to support@agisoft.com?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #7 on: May 29, 2015, 08:48:49 PM »
Also it seems that there's no information regarding camera calibration in the imported file, so I think it could be a problem.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #8 on: May 30, 2015, 01:54:55 AM »
Jappert,

it seems the sensor definition in your agi_XML file is wrong. As I can see from your input ph_fass input file all input linear units are in meters. So the pixel sensor size of the camera is 2.2e-006 m or 2.2 um.
In the agi_xml pixel width and height should be given in mm or 2.2e-003, so I think the correct sensor definition in your agi_xml  should be:

<sensor id="0" label="MS50 Wide" type="frame">
        <resolution width="2560" height="1920"/>
        <property name="pixel_width" value="2.2e-003"/>
        <property name="pixel_height" value="2.2e-003"/>
        <property name="focal_length" value="2.084425e+001"/>
        <property name="fixed" value="true"/>
        <calibration type="frame" class="adjusted">
          <resolution width="2560" height="1920"/>
          <fx>9.474659e+003</fx>
          <fy>9.474659e+003</fy>
          <cx>1.30924e+003</cx>
          <cy>9.07509e+002</cy>
          <skew>0e+000</skew>
          <k1>0e+000</k1>
          <k2>0e+000</k2>
          <k3>0e+000</k3>
          <p1>0e+000</p1>
          <p2>0e+000</p2>
        </calibration>
      </sensor>

also focal length is in mm in agi_xml which corresponds to CameraConstant 2.084425E-002m in ph-fass file.

Note that this sensor definition is only correct for pictures with InteriorOrientation uniqueID="3_3" in ph-fass file as other pictures have difereent Interior orientation (Zoom lens +10).

regards,
Best Regards,
Paul Pelletier,
Surveyor

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #9 on: May 30, 2015, 11:12:07 AM »
Thanks pap1956

Yeah the different definitions (um, mm, m) could be a problem. The XSD from ph-fass.xml also doesn't say anything about them. I just tried your sensor definition (where comes the fx/fy 9.47e+3 from?) and filtered all the photos with another camera calibration than the defined.
Still the same result (console) without any photos aligned or calibrated:
Code: [Select]
Detecting points...
photo 1: 9982 points
....
photo 26: 9985 points
points detected in 89.836 sec
Matching points...
198962 matches found in 65.989 sec
matches combined in 0.063 sec
matches filtered in 10.001 sec
setting point indices... 28314 done in 0.009 sec
generated 28314 tie points, 3.04143 average projections
removed 3655 multiple indices
removed 28 tracks
finished matching in 165.934 sec
selected 28286 tracks out of 28286 in 0.008 sec
adding 0 points, 0 far (10 threshold), 0 inaccurate, 0 invisible, 0 weak
coordinates applied in 0 sec
Finished processing in 166.059 sec (exit code 1)
>>>

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #10 on: May 30, 2015, 11:52:43 AM »
Hello Japper,

Thanks for providing the data.

Focal length in <sensor> section should be defined in pixels and can be calculated from mm using the following formula:

f (pix) = f (mm) / sensor_pixel_size (mm)

Principal point positions should be converted to pixels in the similar way. Note the in PhotoScan (0, 0) coordinates of the image are referred to the top-left corner.
« Last Edit: May 30, 2015, 11:54:21 AM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #11 on: May 30, 2015, 01:03:17 PM »
OK that's a bit tricky cause I dont know any units of my XML data (ph-fass.xml)
Finally I'm working with the now attached XML, it's quite similar.
From XML I got a focal length of 0.02084425m = 20.84425mm
The pixel size is 2.2um = 0.0022mm
The focal length in pixel is then 9.47e+6. Don't really know if this is the right or the calculated by pap1956 (9.47e+3)
In a new PS project to calculate the camera calibration I imported the 26 photos with the same internal orientation, aligned and optimised them and got these (screenshot, is approx. 9.47e+3)
Then I put these in the PS project where I try to import the cameras an put them as precalibrated and fixed. After the next try to "import cameras..." - still no aligned cameras :-(

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #12 on: May 30, 2015, 01:52:44 PM »
Maybe got a breakthrough: The ending in my PS XML was .JPG, in PS the name of the photos was .jpg  :-X
Now my cameras are all aligned, but the next problem is waiting for me.
There have not been any tie points created after importing the camera. Also with creating them manually later "Tie Points- Build Point Cloud" no tie points are created. From the console log I can see that there are points, but it seems PS could not match them.
After this I imported some more photos of the object without know external orientation, from a DSLR.
Still no tie points detectable..
I added btw. the PS XML after camera export
How could I get the tie points? I need them for the dense image matching.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #13 on: May 30, 2015, 02:12:20 PM »
Hello Jappert,

You need to input correct <calibration>  values in the XML that you are going to import. And another important thing is that the camera labels in XML are case sensitive, so you also need to change JPG to jpg, according to the labels in the project file.


It seems that something wrong is with the XYZ coordinates that doesn't allow to switch matching points to the valid state.
« Last Edit: May 30, 2015, 02:24:24 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

Marcoo

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Generate XML from known X0 Y0 Z0 Phi Theta Kappa
« Reply #14 on: May 30, 2015, 04:11:17 PM »
Hello Pasumansky

Yeah that's what I already changed. The case sensitive import is now fixed, the project looks like the one I attached (see link).
Photos and PS project (project_support2.psz) and PS XML to import the cameras are here:
https://cloud.kopa.ch/index.php/s/WG3XbQ3aMsWEvVC
As I import this XML, only fx, fy, pixel size and focal length get imported - but not cx, cy, skew, k1-3 and p1, p2.
What do you think is wrong with the XYZ coordinates? They are correct translated as I see in an export camera XML.  It's maybe because of the arrangement of the photos? I had twice an arrangement like on the screenshot left. I know it's not well done but I couldn't change while taking the photos.
Additionally, with the DSLR photos I could also not create any tie points.
« Last Edit: May 30, 2015, 04:13:11 PM by Jappert »