Forum

Author Topic: Howto get world-2-pixel coordinate correctly  (Read 4173 times)

william.nguatem

  • Newbie
  • *
  • Posts: 5
    • View Profile
Howto get world-2-pixel coordinate correctly
« on: April 17, 2015, 11:11:16 AM »
Hi folks,

I got stuck a few days ago on how to get the 2D-Image-Coordinates from 3D-World-Cordinates.

I'll like to project the 3D points to the image.
So far, I've used the standard formular from computer vision's opencv community.

s(x,y) = K[R|T]X    , where s is just a scale which would be removed by normalization.

K ist made up of fx, fy, and cx, cy int the standard constellation.

[R|T] are just the 16 values from the transformation tag within the xml file.

When I plug in the values from the xml file, since these seems to be self explanatory, I get completely weird and wrong results . I really must be doing something wrong ?
Below is a section of my xml file after an alignment using Photoscan.

Would be greatful for any feedback on what can be done or what am doing wrong.
Thanks in advance.

William


<?xml version="1.0" encoding="UTF-8"?>
<document version="1.1.0">
  <chunk>
    <sensors>
      <sensor id="0" label="Canon EOS 350D DIGITAL (18 mm)" type="frame">
        <resolution width="3456" height="2304"/>
        <property name="pixel_width" value="6.4198206018518476e-03"/>
        <property name="pixel_height" value="6.4198206018518476e-03"/>
        <property name="focal_length" value="1.8000000000000000e+01"/>
        <property name="fixed" value="false"/>
        <calibration type="frame" class="adjusted">
          <resolution width="3456" height="2304"/>
          <fx>2.8513916770064407e+03</fx>
          <fy>2.8513916770064407e+03</fy>
          <cx>1.7142977803506899e+03</cx>
          <cy>1.1750826746576211e+03</cy>
          <k1>-1.6031160926301238e-01</k1>
          <k2>1.4987646942943705e-01</k2>
          <k3>-2.4719484671678366e-02</k3>
        </calibration>
      </sensor>
    </sensors>
    <cameras>
      <camera id="0" label="IMG_8722.JPG" sensor_id="0" enabled="true">
        <transform>9.9227184007569458e-01 -1.2185523303064348e-01 2.3407212047629491e-02 -2.2351721513990133e+00 1.0925472409197114e-01 9.4743195751412834e-01 3.0072594025879151e-01 -1.2025190386881018e+01 -5.8821770258828301e-02 -2.9584453360505847e-01 9.5342331169298722e-01 -4.6528962969246628e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 1.0000000000000000e+00</transform>
        <orientation>6</orientation>
      </camera>
      <camera id="1" label="IMG_8723.JPG" sensor_id="0" enabled="true">
        <transform>9.8995202075345468e-01 -1.4018894610390745e-01 -1.8494755916944709e-02 -2.0944413279691725e+00 1.3781084771662525e-01 9.2721466653058471e-01 3.4825440761345960e-01 -1.1349541060350331e+01 -3.1672809439277042e-02 -3.4730393254446790e-01 9.3721759030727281e-01 -4.3615241444329396e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 1.0000000000000000e+00</transform>
        <orientation>6</orientation>
      </camera>



nomino

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Howto get world-2-pixel coordinate correctly
« Reply #1 on: April 20, 2015, 12:03:00 PM »
Hi, it seems I am not the only one experiencing this issue...
I've done a ton of tests and checked different file formats, but I could not find a solution. I even tried to use the .fbx file to export both data points and parameters but got no solution...

Here you find another topic I opened:
http://www.agisoft.com/forum/index.php?topic=3646.msg19074#msg19074

In my humble opinion the problem is in how photoscan exports external parameters or eventually 3D points...

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: Howto get world-2-pixel coordinate correctly
« Reply #2 on: April 20, 2015, 01:59:19 PM »
This may help?:

http://www.agisoft.com/forum/index.php?topic=2351.msg12556#msg12556

I found the bundler output format to be more useful than the photoscan xml format, but both needed manipulating to be of use for what i was doing in opencv. It was a lot of trial and error and i didn't know what i was doing mostly!

As for distortion, i didnt even attempt to account for that so in my opencv application i used the 'undistorted' photos exported from photoscan.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14855
    • View Profile
Re: Howto get world-2-pixel coordinate correctly
« Reply #3 on: April 21, 2015, 12:20:56 PM »
Hello William,

To get 2D coordinates on the image for the 3D point in world coordinates you can use the following script lines:

Code: [Select]
chunk = PhotoScan.app.document.chunk #active chunk
T = chunk.transform.matrix #4x4 transformation matrix

camera = chunk.cameras[0] #first camera in the chunk
point = PhotoScan.Vector([40.4543, 54.03443, 114])  #point in world coordinates

point_geocentric = chunk.crs.unproject(point) #points in geocentric coordinates
point_internal = T.inv().mulp(point_geocentric)

point_2D = camera.project(point_internal) #2D image coordinates for the point

Best regards,
Alexey Pasumansky,
Agisoft LLC

william.nguatem

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Howto get world-2-pixel coordinate correctly
« Reply #4 on: April 21, 2015, 03:10:22 PM »
Thanks Alexey,

I've got the picture. Everything is now working perfectly as I'd expected,

@Dmitry, thank you too for the feedback.

Cheers
William