Forum

Author Topic: Use of Non-Agisoft Markers  (Read 934 times)

kkobaya

  • Newbie
  • *
  • Posts: 2
    • View Profile
Use of Non-Agisoft Markers
« on: September 13, 2020, 04:19:39 AM »
I am trying to use ARUCO markers in order to align and scale my model of an infant's head.
What data do I need to import these markers into Agisoft? Is there a set Python script that I can use?

Any help regarding this topic would be useful!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 12742
    • View Profile
Re: Use of Non-Agisoft Markers
« Reply #1 on: September 13, 2020, 04:19:37 PM »
Hello kkobaya,

I have some rather old script (related to the version 1.5) that allows to import the marker data to the project from the text file, where each line contains the following information:
marker label, full path to the related image file, x-coord, y-coord.

If it doesn't work straight away, please let me know, which error you are getting and I'll adjust the script to the latest Python API.

Code: [Select]
#markers batch import script
import Metashape

def batch_import_markers():

doc = Metashape.app.document

path = Metashape.app.getOpenFileName("Select markers import file:")
if not path:
print("Empty path. Script aborted.")
return 0
print("\nScript started...")  #informational message

file = open(path, "rt") #input file

eof = False
line = file.readline()
if len(line) == 0:
eof = True
else:
cur_label = line.rstrip()

while not eof:

for chunk in doc.chunks:

if chunk.label == cur_label:

end = False
while not end:
photos_total = len(chunk.cameras) #number of photos in chunk
markers_total = len(chunk.markers) #number of markers in chunk

line = file.readline() #reading the line in input file

if line.rstrip() == "#":
end = True
break

sp_line = line.rsplit(",", 3)   #splitting read line by four parts

y = float(sp_line[3]) #x- coordinate of the current projection in pixels
x = float(sp_line[2]) #y- coordinate of the current projection in pixels
path = sp_line[1] #full path to the photo
marker_name = sp_line[0] #marker label

flag = 0
for i in range (0, photos_total):

if chunk.cameras[i].photo.path == path: #searching for the image (comparing with all the photo paths in chunk)

for j in range (0, markers_total): #searching for the marker (comparing with all the marker labels in chunk)
if chunk.markers[j].label == marker_name:
chunk.markers[j].projections[chunk.cameras[i]] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True) #setting up marker projection of the correct photo)
flag = 1
break

if flag == 0:
chunk.addMarker()
markers_total = len(chunk.markers)
chunk.markers[markers_total-1].label = marker_name
chunk.markers[markers_total-1].projections[chunk.cameras[i]] =  Metashape.Marker.Projection(Metashape.Vector([x,y]), True)
break
else:
continue

line = file.readline() #reading the line in input file
if len(line) == 0:
eof = True
break # EOF
else:
cur_label = line.rstrip()
#Metashape.app.messageBox("1" + cur_label + "1")


file.close()
#Metashape.app.messageBox("Processing finished.\n\nClick OK.")  #information message
print ("Markers import finished.")
return 1

Metashape.app.addMenuItem("Custom menu/Batch import markers", batch_import_markers)
Best regards,
Alexey Pasumansky,
Agisoft LLC