Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: jonathanH on May 06, 2016, 08:49:49 PM

Title: How to use PhotoScan.CameraReference
Post by: jonathanH on May 06, 2016, 08:49:49 PM
Hi, I am trying to retrieve the 'location' and 'rotation' attributes from the CameraReference class. How can one go about getting these? I have tried the following but it does not work:

camLocations = []
camRotations = []
count = 1
for cam in chunk.cameras:
    camLocations.append(str(count)+":"+str(cam.CameraReference.location))
    camRotations.append(str(count)+":"+str(cam.CameraReference.rotation))
    count+=1

Has anyone used this class before?
Title: Re: How to use PhotoScan.CameraReference
Post by: Alexey Pasumansky on May 06, 2016, 08:58:18 PM
Hello Jonathan,

To access source values for the cameras displayed in the Reference pane you need to use
Code: [Select]
cam.reference.location
cam.reference.rotation
In case any data is not available you'll be given "None".
Title: Re: How to use PhotoScan.CameraReference
Post by: jonathanH on May 06, 2016, 09:16:25 PM
Thanks Alexey,

I'm getting None values. Is there any way of calculating estimated values for a local coordinate system?
Title: Re: How to use PhotoScan.CameraReference
Post by: Alexey Pasumansky on May 06, 2016, 09:46:46 PM
Hello Jonathan,

camera.reference contain only source values.

If you have set the coordinate system to local coordinates (chunk is referenced) then coordinates of the camera center can be calculated in the following way:
Code: [Select]
x, y, z = chunk.transform.matrix.mulp(cam.center)to get the estimated yaw, pitch, roll you need to use the following:
Code: [Select]
m = chunk.transform.matrix * cam.transform * PhotoScan.Matrix().diag([1,-1,-1,1])
row = []
for i in range(3):
   row.append(m.row(i))
   row[i].size = 3
   row[i].normalize()
rotation = PhotoScan.Matrix([row[0], row[1], row[2]])
yaw, pitch, roll = PhotoScan.utils.mat2ypr(rotation)
the complex procedure of rotation component extraction will be much easier in the next update, it can be achieved using rotation = m.rotation()
Title: Re: How to use PhotoScan.CameraReference
Post by: jonathanH on May 06, 2016, 10:27:16 PM
Thank you so much Alexey!!!

I don't know if it works yet but I seem to be getting a tuple of what looks like angles. I've been searching for how to do this for absolutely ages!

 ;D ;D ;D ;D ;D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D ::) ::) ::) :'(  :) :) :) :) :) :)