Forum

Author Topic: Render image from camera reference location  (Read 1722 times)

andrevall

  • Newbie
  • *
  • Posts: 13
    • View Profile
Render image from camera reference location
« on: March 18, 2021, 05:52:54 PM »
Hi everyone,

I am trying to render an image of a tiled model, using the tiled_model.renderImage method. I would like to render from the camera reference positions (not the estimated ones), of which I know the easting, northing, altitude and yaw, pitch, roll angles. The camera reference values and the tiled model are expressed in the same geographic CRS.

The question is: how can I construct the transformation matrix to use in the tiled_model.renderImage() function, using the reference X,Y,Z and Y,P,R values of the cameras?

I tried constructing a 4x4 transformation matrix by computing a rotation matrix from the euler angles, and concatenating it with the [X.Y.Z] column and adding a [0,0,0,1] row, but I am getting an all-black render...

Thank you in advance,

Andrea
« Last Edit: March 18, 2021, 05:54:44 PM by andrevall »

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: Render image from camera reference location
« Reply #1 on: March 18, 2021, 07:21:15 PM »
Hello,

you could use following to populate a list CT with camera transform matrices (4x4) built from reference location and rotation of each camera:

Code: [Select]
chunk = Metashape.app.document.chunk
T = chunk.transform.matrix
CT = list()
for camera in chunk.cameras:

R =  Metashape.utils.euler2mat(camera.reference.rotation, chunk.euler_angles)
coord = camera.reference.location
coord = chunk.crs.unproject(coord)
m = chunk.crs.localframe(coord)
R = Metashape.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]]).t() * R * PhotoScan.Matrix().Diag((1, -1, -1))

row = list()
for j in range(0, 3):
row.append(Metashape.Vector(R.row(j)))
row[j].size = 4
row[j].w = coord[j]
row.append(Metashape.Vector([0, 0, 0, 1]))
M = Metashape.Matrix([row[0], row[1], row[2], row[3]])
CT.append(T.inv() * M)

Hope this can help, :)
« Last Edit: March 18, 2021, 08:34:09 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

andrevall

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Render image from camera reference location
« Reply #2 on: March 18, 2021, 10:03:45 PM »
Thank you Paulo! That is really impressive, there is no way I could have come up with that. I just checked and it works flawlessly  :)
« Last Edit: March 19, 2021, 04:50:30 PM by andrevall »

Paulo

  • Hero Member
  • *****
  • Posts: 1301
    • View Profile
Re: Render image from camera reference location
« Reply #3 on: March 18, 2021, 11:55:58 PM »
Andreval,

I think thanks should go to Alexey from Agisoft who provided the original script to set adjusted camera EO from camera reference location + rotation....
Best Regards,
Paul Pelletier,
Surveyor