Forum

Author Topic: Image alignment affected by placing marker and adding scale bar  (Read 1473 times)

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Image alignment affected by placing marker and adding scale bar
« on: October 09, 2020, 12:20:45 AM »
Hello
I am trying to align the turn table pictures. I  place a marker (12bit circular targets),
Code: [Select]
chunk.detectMarkers(Metashape.TargetType.CircularTarget12bit, 50) this code is detecting the markers.

When scalebars between markers  hard code. My 360 image alignments are coming  as expected.
Code: [Select]
scalebars = chunk.addScalebar(chunk.markers[0], chunk.markers[1])
scalebars.reference.accuracy = accuracy
scalebars.reference.distance = 0.1765

scalebars = chunk.addScalebar(chunk.markers[1], chunk.markers[2])
scalebars.reference.accuracy = accuracy
scalebars.reference.distance = 0.1765

scalebars = chunk.addScalebar(chunk.markers[2], chunk.markers[3])
scalebars.reference.accuracy = accuracy
scalebars.reference.distance = 0.1765


Instate of hard coding i try to make this addition bit dynamic  like below. My image aligments if going every where. Not sure why this is happening. Or what I am doing wrong. 
Code: [Select]

accuracy = 0.0001
pairings = ['1_2','2_3','3_4']
scale_values = {
'1_2': 0.1765, '2_3': 0.1765, '3_4': 0.1765}
markers_name = {}
for marker in chunk.markers:
markers_name.update({marker.label.replace('target ',''): marker})

print(markers_name)
for pair in pairings:
    a, b = pair.split('_')
    if (a in markers_name.keys()) and b in markers_name.keys():
        scalebars = chunk.addScalebar(chunk.markers[int(a)-1],chunk.markers[int(b)-1])
        scalebars.reference.accuracy = accuracy
        scalebars.reference.distance = scale_values[pair]

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Image alignment affected by placing marker and adding scale bar
« Reply #1 on: October 09, 2020, 12:48:16 PM »
Hello ppant,

I think the problem is with the addressing to the marker indices when you are creating scale bars: marker index in the list of chunk.markers does not necessarily correspond to the target number. So you may need to create an auxiliary function, that will return the object from Metashape.Marker class based on the label passed to it. Something like that:
Code: [Select]
def get_marker(chunk, label):
    for marker in chunk.markers:
        if marker.label == label:
             return marker
    return None

#....

m1 = get_marker(chunk, a)
m2 = get_marker(chunk, b)
if m1 and m2:
    chunk.addScalebar(m1, m2)
Best regards,
Alexey Pasumansky,
Agisoft LLC