Forum

Author Topic: Marker - Region Alignemnt  (Read 2683 times)

Julian1919

  • Newbie
  • *
  • Posts: 2
    • View Profile
Marker - Region Alignemnt
« on: November 28, 2017, 07:54:45 PM »
Hello, I‘m having a problem with the bounding box/ region. Is it possible to align the region with your markers? I have different models with markers always in the same locations and if i want to compare the models, they need to have the same  bbox/ region alignment. It doesn’t really matter how they’re aligned as long as it is the same for every model. Is this possible or do I need a python script for that? If yes how would it look like; I don’t really speak python  :-\

Thank you for your help

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Marker - Region Alignemnt
« Reply #1 on: November 28, 2017, 08:11:51 PM »
Hello Julian1919,

Some additional information would be required: how you are planning to define the box size/position/orientation? For example, should there be some kind of selection from the list of markers for the box origin, and same for the markers defining the corners of the box side?

Maybe you can post a screenshot or sketch, demonstrating the markers' positions and name those, that should or could be selected by the user?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Julian1919

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Marker - Region Alignemnt
« Reply #2 on: November 29, 2017, 01:45:16 PM »
The outer markers P1,P5,P6,P10 could be the upper corners of the box for example.  But do u still need to define a marker for the origin then?
« Last Edit: November 29, 2017, 03:22:18 PM by Julian1919 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Marker - Region Alignemnt
« Reply #3 on: November 30, 2017, 08:18:38 PM »
Hello Julian,

Please try the following script:

Code: [Select]
#compatibility PhotoScan Professional version 1.3.4
#sets up the bounding box according to four markers

import PhotoScan, math
CORNERS = ["P5", "P6", "P10", "P1"]

def vect(a, b):

result = PhotoScan.Vector([a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y *b.x])
return result.normalized()

def get_marker(label, chunk):

for marker in chunk.markers:
if marker.label.lower() == label.lower():
return marker
return None

doc = PhotoScan.app.document
chunk = doc.chunk #active chunk
region = chunk.region
if chunk.transform.matrix:
T = chunk.transform.matrix
s = chunk.transform.scale
else:
T = PhotoScan.Matrix().Diag([1,1,1,1])
s = 1

points2 = [get_marker(x, chunk).position for x in CORNERS]

new_region = chunk.region
new_center = (points2[0] + points2[1] + points2[2] + points2[3]) / 4.

side1 = points2[0] - points2[1]
side2 = points2[0] - points2[-1]
side1g = T.mulp(points2[0]) - T.mulp(points2[1])
side2g = T.mulp(points2[0]) - T.mulp(points2[-1])

new_size = PhotoScan.Vector([side2g.norm()/s , side1g.norm()/s, new_region.size.z])

horizontal = side2
vertical = side1
normal = vect(vertical, horizontal)
horizontal = -vect(vertical, normal)
vertical = vertical.normalized()

R = PhotoScan.Matrix ([horizontal, vertical, -normal])
new_region.rot = R.t()

new_region.center = new_center
new_region.size = new_size
chunk.region = new_region
print("Finished")

It will use the markers P5, P6, P10, P1 to define the origin of the box and vectors P5 -> P6, P5 -> P1 to define the sides of the box. The vertical size of the box would remain unchanged compared to the original box size.

Let me know which kind of modifications are required for the script, if it works more or less as expected.
Best regards,
Alexey Pasumansky,
Agisoft LLC