Forum

Author Topic: Resize bounding box  (Read 4649 times)

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
Resize bounding box
« on: February 11, 2019, 12:35:46 AM »
Hello,

I've incorporated the code from here;

https://www.agisoft.com/forum/index.php?topic=7543.0

In to a script I'm putting together, that also utilises the MC32 script found here;

https://www.lancaster.ac.uk/staff/jamesm/software/sfm_georef.htm

I'm trying to automate the process of ensuring the bounding box is larger than the point cloud for the Monte Carlo analysis to run successfully (both python scripts runs flawlessly within Photoscan/Metashape) but when I'm running the analysis through SfM_Georef, anywhere between 50-90% of the Monte Carlo iterations are rejected due to the bounding box being too small.

Is there a way to say, add 20% or 20m in the X,Y, and Z of the box within this?;

Code: [Select]
import PhotoScan, math

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

m = PhotoScan.Vector([10E+10, 10E+10, 10E+10])
M = -m

for point in chunk.point_cloud.points:
if not point.valid:
continue
coord = T * point.coord
coord.size = 3
coord = chunk.crs.project(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(chunk.crs.unproject(center))
region.size = size * (1 / T.scale())

v_t = T * PhotoScan.Vector( [0,0,0,1] )
v_t.size = 3
R = chunk.crs.localframe(v_t) * T
region.rot = R.rotation().t()

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

Report to moderator   Logged

Cheers,

Leon

LDBL

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Resize bounding box
« Reply #1 on: February 13, 2019, 03:04:21 PM »
So I've found an answer in this thread;

https://www.agisoft.com/forum/index.php?topic=8679.0

By modifying this line;

Code: [Select]
new_size = PhotoScan.Vector([2.5*side2g.norm()/s, 2.5*side1g.norm()/s, 1.5*side1g.norm()/s]) ##
This has the desired effect of being able to create a bounding box of the necessary dimensions for the Monte Carlo to run successfully.