Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: Fernando on July 07, 2014, 01:39:21 AM

Title: How to set region volume to 2 camera locations?
Post by: Fernando on July 07, 2014, 01:39:21 AM
Hi, I was wondering if I could manually set the region bounding box to 2 points in space: 2 camera locations.

So for example these are the camera locations:

cam1(0,0,0)
cam2(100,100,100)

Together they form the maximum / most outer points of the region volume.

How can I set the region to that volume?

Thanks!
Title: Re: How to set region volume to 2 camera locations?
Post by: Fernando on July 09, 2014, 02:19:17 PM
Hi, maybe someone could help me? Or is this a really dumb question? Sorry, I'm a total Python noob  :'(
Title: Re: How to set region volume to 2 camera locations?
Post by: Alexey Pasumansky on July 09, 2014, 03:03:44 PM
Hello Fernando,

Are region sides supposed to be parallel to the coordinate system planes?
Title: Re: How to set region volume to 2 camera locations?
Post by: Fernando on July 09, 2014, 05:05:05 PM
Hello Alexey,

No, that is not necessary.

Thanks
Title: Re: How to set region volume to 2 camera locations?
Post by: Alexey Pasumansky on July 09, 2014, 05:15:50 PM
Hello Fernando,

Please try the following:

Code: [Select]
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.activeChunk

p1 = PhotoScan.app.getInt("Specify first camera index:", 0)
p2 = PhotoScan.app.getInt("Specify second camera index:", len(chunk.cameras)-1)
p1 = chunk.cameras[p1]
p2 = chunk.cameras[p2]

region = PhotoScan.Region()
dist = p2.center - p1.center
region.size = PhotoScan.Vector([dist.x, dist.y, dist.z])
region.center = (p1.center + p2.center) / 2.
region.rot = PhotoScan.Matrix().diag([1,1,1])
chunk.region = region

PhotoScan.app.update()


On script run you'll be asked about camera indices you wish to use (leading zero).
Title: Re: How to set region volume to 2 camera locations?
Post by: Fernando on July 10, 2014, 06:57:01 PM
Thank you so much Alexey! I'll give this a try.