Hello.
When I reconstruct, I also import a camera position CSV file as reference. This properly scales and orients the scene to the Agisoft grid axes reliably.
My issue is that I want programmatically scale and orient the build region after this step. My script below is run after alignment and importing the CSV file (which does correctly scale and orient the entire camera rig).
It appears that the region parameters are always in relation to one of the aligned cameras, and doesn't seem to be the same camera every time, so I'm having trouble reliably placing the build region box at the center of the rig on the ground plane where I need it. I can offset and rotate the box, but since its relative to some camera each build, it's not reliable.
How can I best place the region in my chunk at an absolute position in world space (for instance, at 0.0,0.0,2.0 and scaled to 3.5,3.5,4.0)?
Thank you!
My script: (apologies, the code tag button is not working in Edge browser)
<code>
#load CSV reference file
try:
#import csv reference for scale and orientation
csvFilePath = (path+"/CameraData/CamData.csv")
print("Loading references from "+csvFilePath)
chunk.loadReference(csvFilePath,PhotoScan.ReferenceFormat.ReferenceFormatCSV,'nxyzXYZ',',')
chunk.updateTransform()
print("loaded references!")
except:
print("couldn't load references")
#set volume bounding box
print("===Setting Bounding Box Volume===")
new_region = PhotoScan.Region()
new_center = PhotoScan.Vector([0.0,0.0,2.0]) #this offsets relative to some cameras Z axis, undesired
#new_center = offset + new_rot * new_center
x_scale = 3.5
y_scale = 3.5
z_scale = 4.0
new_size = PhotoScan.Vector([x_scale, y_scale, z_scale])
T = PhotoScan.app.document.chunk.transform.matrix
v_t = T * PhotoScan.Vector( [0,0,0,1] )
m = PhotoScan.Matrix.Diag( (1,1,1,1) )
m = m * T
s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 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.0 / s)
new_region.size = new_size
new_region.center = new_center
new_region.rot = R.t()
PhotoScan.app.document.chunk.region = new_region
PhotoScan.app.update()
</code>