Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: jrjdavidson on April 13, 2021, 02:45:18 AM

Title: Possible to export fiducail location on each camera?
Post by: jrjdavidson on April 13, 2021, 02:45:18 AM
Hi,

We would like to export fiducial information for each camera that we've added to one project, in order to add them to a new one. Had a look around and couldn't find any information on the subject. How is the postion of markers stored on each camera? in the camera class?

We're trying to avoid having to hand pick fiducial location on each camera again. Any help appreciated!

cheers,
Title: Re: Possible to export fiducail location on each camera?
Post by: jrjdavidson on April 13, 2021, 04:06:34 AM
Ok I got it working with the code below. Now to figure out how to import fiducial markers

Code: [Select]
import Metashape

def find_marker(label, chunk):
for marker in chunk.markers:
if label == marker.label:
return marker
return None

def getCameras(name):

marker = find_marker(name, chunk)
if not marker:
print("Fiducial " + name + " not found.")
return

if not marker.position:
print("Fiducial " + name + " is not defined in 3D, skipping...")
return
return marker.projections.keys()

FILEPATH = "C:\\Temp\\raw_data.txt"
chunk = Metashape.app.document.chunk
print("Script started...")

fiducialCameras = getCameras("1") # get all cameras that have fiducial 1 in it, assume that other fiducials are located in camera too..

fid1=find_marker("1", chunk)
fid2=find_marker("2", chunk)
fid3=find_marker("3", chunk)
fid4=find_marker("4", chunk)
f = open(FILEPATH, 'w')
for camera in fiducialCameras:
f.write(camera.label + ',' + str(fid1.projections[camera].coord.x) + ',' + str(fid1.projections[camera].coord.y) + ',' + str(fid2.projections[camera].coord.x) + ',' + str(fid2.projections[camera].coord.y) + ','+ str(fid3.projections[camera].coord.x) + ','+ str(fid3.projections[camera].coord.y) + ','+ str(fid4.projections[camera].coord.x) + ',' + str(fid4.projections[camera].coord.y) +  '\n')
f.close
print("Script finished")