Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: nachogi73 on June 26, 2014, 05:43:46 PM

Title: Script to match Z axis
Post by: nachogi73 on June 26, 2014, 05:43:46 PM
Hi

I need to match the Z axis of my model (calculate via survey gpc) and the Region Box Z axis.

So I need to create the mesh in height field mode but the program uses the z axis of the Box and this is no the real vertical direction.

Does anyone know a script to do this action?
Title: Re: Script to match Z axis
Post by: Alexey Pasumansky on June 26, 2014, 05:51:20 PM
Hello nachogi73,

You can rotate the bounding box to align its Z-axis with the coordinate system vertical direction.

I think that the script has been posted somewhere here, but there's no problem to copy it once again:
Code: [Select]
import PhotoScan, math

doc = PhotoScan.app.document
chunk = doc.activeChunk

if chunk.transform:
       T = chunk.transform
else:
       T = PhotoScan.Matrix().diag([1,1,1,1])

v = PhotoScan.Vector( [0,0,0,1] )
v_t = T * v
v_t.size = 3

if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])
m = m * T

s = math.sqrt(m[0,0]*m[0,0] + m[0,1]*m[0,1] + m[0,2]*m[0,2]) #scale factor
R = PhotoScan.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]]])
R = R * (1. / s)

reg = chunk.region
reg.rot = R.t()
chunk.region = reg
Title: Re: Script to match Z axis
Post by: nachogi73 on April 07, 2015, 01:09:36 PM
Hi again:

This script  seems not work in newer versions of Photoscan.

There is another solution for this issue.

Sorry I´m complete ignorant in scripting
Title: Re: Script to match Z axis
Post by: Seb_B on April 07, 2015, 02:42:17 PM
Hello,

the script to rotate the bounding box is written in the wiki:
http://wiki.agisoft.com/wiki/Python