2
« on: September 13, 2023, 11:06:15 AM »
Hi there,
I'm using Metashape v1.7.6. We do repeat surveys of the same area each year. Permanent markers are used to create a transformation matrix that help us to align models, and the following code has been implemented to align the bounding boxes to ensure that the models are of an identical area from year to year:
import Metashape
doc = Metashape.app.document
chunk = doc.chunks[0]
region = chunk.region
T0 = Metashape.Matrix.diag((1, 1, 1, 1))
if chunk.transform != None:
T0 = chunk.transform
R0 = region.rot
C0 = region.center
s0 = region.size
C0.size = 4
C0.w = 1
chunk = doc.chunks[1]
if chunk.transform != None:
T = chunk.transform.inv() * T0
else:
T = T0
R = Metashape.Matrix( [[T[0,0],T[0,1],T[0,2]], [T[1,0],T[1,1],T[1,2]], [T[2,0],T[2,1],T[2,2]]])
scale = R.row(0).norm()
R = R * (1/scale)
region.rot = R * R0
c = T * C0
c = c / c[3] / 1.
c.size = 3
region.center = c
region.size = s0 * scale / 1.
chunk.region = region
The only issue appears to be that the reference chunk's region changes dramatically on execution of the code. The region for time point 2 aligns perfectly to the dimensions of time point 1's region, but then the original region changes. Is there something in the code that may be causing "chunk[0]"s region to change? This code was originially designed to work with photoscan.
Thanks