Forum

Move origin

Started by chr00t, August 19, 2016, 02:50:26 PM

Previous topic - Next topic

chr00t

Hello,

Would you complete that snippet on how to change the origin?

I want the first camera to become the new origin

import PhotoScan
import math
doc = PhotoScan.app.document
doc.open("project.psx")
chunk = doc.chunk
camera_becoming_origin = chunk.cameras[0];

then transform ?  :o

Alexey Pasumansky

#1
Hello chr00t,

import PhotoScan

chunk = PhotoScan.app.document.chunk
origin = chunk.cameras[0].center #first camera center

T = PhotoScan.Matrix().diag([1,1,1,1])
for i in range(3):
T[i,3] = -origin[i]
chunk.transform.matrix = chunk.transform.matrix * T


But you might need to perform check whether the camera is aligned and camera index is not out of range, in case you are including the script in some large automated pipeline.
Best regards,
Alexey Pasumansky,
Agisoft LLC

chr00t

I'll consider checking names and range later on for sure :)

But why is this happening?

2016-08-19 14:36:10   File "C:/Users/User/Desktop/Test/Origin.py", line 8, in <module>
2016-08-19 14:36:10     T[i,3] = -origin
2016-08-19 14:36:10 TypeError: 'PhotoScan.Camera' object does not support indexing

Alexey Pasumansky

Sorry, there was a typo, origin  = chunk.cameras[0].center
Best regards,
Alexey Pasumansky,
Agisoft LLC

chr00t

Working as a charm,

Thanks Alexey