Forum

Author Topic: Aligning regions unexpectedly changes the original  (Read 3967 times)

eastonmbio

  • Newbie
  • *
  • Posts: 13
    • View Profile
Aligning regions unexpectedly changes the original
« 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:

Code: [Select]

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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15122
    • View Profile
Re: Aligning regions unexpectedly changes the original
« Reply #1 on: September 13, 2023, 05:01:56 PM »
Hello eastonmbio,

According to the code the script should adjust the size of the region in the second chunk of the project according to the side of the region in the first chunk.

It is assumed, that the chunks are aligned or are referenced in the same coordinate system.
Best regards,
Alexey Pasumansky,
Agisoft LLC

eastonmbio

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Aligning regions unexpectedly changes the original
« Reply #2 on: September 20, 2023, 12:26:17 PM »
Thank you for your reply Alexey. I'm not sure why the original was changing but it seems to have been some kind of visual glitch, and the region for the reference chunk was in fact preserved.