Agisoft Metashape > Python and Java API

Rotate chunk by the orientation of markers

(1/2) > >>

Milderinne:
Hello everybody,
I would be happy to get some help with the following issue:

There is this idea to rotate a chunk by the orientation of markers.
Meaning that I have 3 "double or paired markers", where one marker is always up and the other one down. My point cloud is not georeferenced but scaled. Often it is upside down or somehow oblique. I want to rotate it by saying marker[0] should be up and marker [1] down and so on.
I am not quite sure about, how to do that at the moment.

Furthermore is it possible to "call" coded markers not by marker[0] and so on, but by its label? With label I mean the name of the marker assigned after using:

--- Code: ---chunk.detectMarkers(type = PhotoScan.TargetType.CircularTarget12bit, tolerance = tolerance)
--- End code ---

Any help is welcome.
Best regards!

Alexey Pasumansky:
Hello Milderinne,

Can you give an example? You wish to specify two pairs of markers according to their labels to set up the coordinate system rotation - would that we enough for the script?

Milderinne:
Hello Alexey,

I have 3 paired coded markers. And I can refer to them by the following:

--- Code: ---chunk.markers[0], chunk.markers[1]

--- End code ---
But I know that they have "labels"(?), for example: target13 - target14. How do I refer to them with their labels?
Or is there something I donĀ“t get correctly?

Then, I would like to set the coordinate system rotation by saying something like:
target13 should be upwards and target14 should be perpendicular to it (downwards). Everything should be rotated in that way. Is that possible?
Best regards.

Milderinne:
Any suggestions?

Alexey Pasumansky:
Hello Milderinne,

The following script sample takes two pairs of markers (defined by their labels in the script body) and rotates the bounding box and coordinate system accordingly. The first pair defines vertical direction, the second pair - horizontal direction (OX axis).

In the attached example you can see the relative position of the markers used and the result orientation of the axis applied by the script.


--- Code: ---import PhotoScan, math

def vect(a, b):
"""
Normalized vector product for two vectors
"""

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):
"""
Returns marker instance from chunk based on the label correspondence
"""

for marker in chunk.markers:
if label == marker.label:
return marker
print("Marker not found! " + label)
return False

chunk = PhotoScan.app.document.chunk
region = chunk.region

vertical = ["point 2", "point 1"]
horizontal = ["point 3", "point 4"]
vertical = get_marker(vertical[0], chunk).position - get_marker(vertical[1], chunk).position
horizontal = get_marker(horizontal[0], chunk).position - get_marker(horizontal[1], chunk).position


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

R = PhotoScan.Matrix ([horizontal, -normal, vertical])
print(R.det())
region.rot = R.t()
chunk.region = region
R = chunk.region.rot #Bounding box rotation matrix
C = chunk.region.center #Bounding box center vector

if chunk.transform.matrix:
T = chunk.transform.matrix
s = math.sqrt(T[0,0] ** 2 + T[0,1] ** 2 + T[0,2] ** 2) #scaling # T.scale()
S = PhotoScan.Matrix().Diag([s, s, s, 1]) #scale matrix
else:
S = PhotoScan.Matrix().Diag([1, 1, 1, 1])
T = PhotoScan.Matrix( [[R[0,0], R[0,1], R[0,2], C[0]], [R[1,0], R[1,1], R[1,2], C[1]], [R[2,0], R[2,1], R[2,2], C[2]], [0, 0, 0, 1]])
chunk.transform.matrix = S * T.inv() #resulting chunk transformation matrix

print("Script finished")
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version