Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: eduardoestrada85 on October 19, 2012, 07:03:36 PM

Title: coordinates modificate script
Post by: eduardoestrada85 on October 19, 2012, 07:03:36 PM
Could someone help me with a script to flip a model that appears when you charge headlong into other software.
It appears that with the head pointing to the ground and need otherwise.
Sorry for the obviousness of my query, but do not understand the process of Ground control pane.

Having the script is not necessary to add markers right?

tnx in advance.
Eduardo.
Title: Re: coordinates modificate script
Post by: Alexey Pasumansky on October 20, 2012, 10:34:18 AM
Hello Eduardo,

We can provide a simple script that brings chunk coordinate system in accordance of Bounding Box - coordinate system axis parallel to the Bounding Box ribs.
Title: Re: coordinates modificate script
Post by: eduardoestrada85 on October 20, 2012, 10:00:01 PM

Hi Alexey and tnx for your response.

Ideally, the idea is that the model remains standing. and even better if you can coordinate with the tool  Bounding box.

tnx again.

Eduardo.
Title: Re: coordinates modificate script
Post by: Alexey Pasumansky on October 30, 2012, 04:35:01 PM
Hello Eduardo,

Here is a sample script that rotates model coordinate system in accordance of bounding box for active chunk

Code: [Select]
#scale is kept
#compatibility: Agisoft PhotoScan Professional 0.9.0


import PhotoScan
import math

doc = PhotoScan.app.document

chunk = doc.activeChunk

R = chunk.region.rot #Bounding box rotation matrix
C = chunk.region.center #Bounding box center vector

if chunk.transform:
T = chunk.transform
s = math.sqrt(T[0,0]*T[0,0] + T[0,1]*T[0,1] + T[0,2]*T[0,2]) #scaling
S = PhotoScan.Matrix( [[s, 0, 0, 0], [0, s, 0, 0], [0, 0, s, 0], [0, 0, 0, 1]] ) #scale matrix
else:
S = PhotoScan.Matrix( [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] )

T = PhotoScan.Matrix( [[R[0,0],R[0,1],R[0,2], C[0]], [R[1,0],R[1,1],R[1,2],C[1]], [R[2,0],R[2,1],R[2,2],C[2]], [0,0,0,1]])

chunk.transform = S * T.inv() #resulting chunk transformation matrix
Title: Re: coordinates modificate script
Post by: eduardoestrada85 on November 06, 2012, 06:13:24 AM
tnx Alexey.
Title: Re: coordinates modificate script
Post by: vanselm66 on January 06, 2014, 02:15:29 PM
Hello.
I tried using this script to align a model, but it did't work. I copied the sample script text and created a .py file with it. After aligning the model using Ctrl and Select tool, I run the script using Tool/Run script... without arguments. Is there something I'm missing?