Forum

Author Topic: region resize script  (Read 1152 times)

chitty1989

  • Newbie
  • *
  • Posts: 20
    • View Profile
region resize script
« on: March 21, 2022, 09:18:49 AM »
Hey guys i have this script that resizes the region box, however it takes into account points that are outside of the original region box, making the result very large. All i want to do is take the region box the allignment has given me and scale it up by a factor of 2 or whatever scale i give it

Code: [Select]
import Metashape, math

doc = Metashape.app.document
chunk = doc.chunk
region = chunk.region
T = chunk.transform.matrix

m = Metashape.Vector([1E+1, 1E+1, 1E+1])
M = -m

for point in chunk.point_cloud.points:
if not point.valid:
continue
coord = T * point.coord
for i in range(3):
m[i] = min(m[i], coord[i])
M[i] = max(M[i], coord[i])

center = (M + m) / 2
size = M - m
region.center = T.inv().mulp(center)
region.size = size * (2 / T.scale())

region.rot = T.rotation().t()

chunk.region = region
print("Script finished.")

chitty1989

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: region resize script
« Reply #1 on: March 21, 2022, 04:15:48 PM »
Hey guys just checking if anyone was able to help on this? I simply just want to take whatever the default region box is and double its size

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14765
    • View Profile
Re: region resize script
« Reply #2 on: March 21, 2022, 04:31:43 PM »
Hello chitty1989,

If need only to modify the size of the box, but to preserve its center and rotation, then you should try the following:
Code: [Select]
doc = Metashape.app.document
chunk = doc.chunk
region = chunk.region
region.size *= 2
Best regards,
Alexey Pasumansky,
Agisoft LLC

chitty1989

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: region resize script
« Reply #3 on: March 22, 2022, 01:00:54 AM »
Thanks Alexey that worked perfectly!

Is it at all possible to add rotation so the region box isnt on an angle and is facing my front set of cameras?

In the image the red is where the region box is currently in orthographic view and green is where i kinda want the region box to be.

Sorry for asking so much!


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14765
    • View Profile
Re: region resize script
« Reply #4 on: March 22, 2022, 12:59:36 PM »
Hello chitty1989,

You can use the following script as a reference, that rotates the bounding box in order to make its sides parallel to the coordinate system axis:
https://github.com/agisoft-llc/metashape-scripts/blob/master/src/bounding_box_to_coordinate_system.py
Best regards,
Alexey Pasumansky,
Agisoft LLC