Forum

Author Topic: Setting bounding box via 2 markers  (Read 280 times)

ozbigben

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Setting bounding box via 2 markers
« on: July 18, 2018, 07:01:37 AM »
Hi all

I'm refining a workflow for doing high resolution scanning using photogrammetry and am at the stage of adding some more automation. Most of the generic processing stuff I can probably work my way through but I have one things that's a bit more complex that's similar to  http://www.agisoft.com/forum/index.php?topic=8060.msg38554.

I'm using an L-shaped target with coded CPs to set the orientation of the image. This is working nicely and I'm looking to add cropping to this.  Having looked through a few posts this might be best done by defining the bounding box after alignment so that only the required area is processed.  I detect markers and import cords prior to alignment so rotation of the model is not required. Bounding box would need to be aligned to the coordinate system (already a script for that) and then positioned/sized to match CPs defining the top/left and bottom right corners.  CP labels would be constant and named during detection "target NNN"  Height of bounding box is OK after alignment

Current setup is attached. Tope Left CP would be added to L-shaped scale bar, bottom right would be a single CP placed manually. I could hard -code the top/left cords but the script would be a little more re-useable getting the cords from a CP.


Any help would be greatly appreciated and happy to share details of the rest of the setup.  Using a Hasselblad H5D60 to scan at 600dpi up to ~2x4m including foldouts from very large books which don't lie flat.
« Last Edit: July 18, 2018, 07:11:15 AM by ozbigben »

ozbigben

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Setting bounding box via 2 markers
« Reply #1 on: July 18, 2018, 07:15:17 AM »
Previous steps:
Load image folders to chunks
Detect markers
Import reference
Align images

bigben

  • Sr. Member
  • ****
  • Posts: 404
    • View Profile
Re: Setting bounding box via 2 markers
« Reply #2 on: July 19, 2018, 05:51:52 PM »
Back to my normal profile... (not sure how how my work PC was still logging in with old profile)  As far as python goes I'm pretty much a noob but I've got a script working for most of the process.

Code: [Select]
import PhotoScan
import math

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

# Detect markers
chunk.detectMarkers(type=PhotoScan.CircularTarget12bit)

# Load reference
chunk.loadReference(path='markers.txt', format=PhotoScan.ReferenceFormatCSV, columns='nxyzXYZ', delimiter=',')

# Align images
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy)
chunk.alignCameras(adaptive_fitting=False)

# Rotate ROI to coordinate system: Bounding_Box_to_Coordinate_System.py

#rotates chunks' bounding box in accordance of coordinate system for active chunk
#bounding box size is kept
#compatibility: Agisoft PhotoScan Professional 1.1.0

T = chunk.transform.matrix

v_t = T * PhotoScan.Vector( [0,0,0,1] )
v_t.size = 3

if chunk.crs:
m = chunk.crs.localframe(v_t)
else:
m = PhotoScan.Matrix().diag([1,1,1,1])

m = m * T

s = math.sqrt(m[0,0] ** 2 + m[0,1] ** 2 + m[0,2] ** 2) #scale factor

R = PhotoScan.Matrix( [[m[0,0],m[0,1],m[0,2]], [m[1,0],m[1,1],m[1,2]], [m[2,0],m[2,1],m[2,2]]])

R = R * (1. / s)

reg = chunk.region
reg.rot = R.t()
chunk.region = reg
#END: Bounding_Box_to_Coordinate_System.py

Now I need to set the size/position of the bounding box between a CP for the top/left and bottom/right corners.. The steps after that I've got working (dense cloud, heightfield, orthomosaic).
« Last Edit: July 19, 2018, 05:54:18 PM by bigben »