Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: Mg_Stray on May 15, 2015, 01:54:10 AM
-
Hi guys,
I would create a script that make me import a reference.xml with GCP' coordinate and then re-align my set of photo. Someone can help me?
thank you
Vincenzo
-
Hello Vincenzo,
Does the following work for you? providing that path is a path to the xml file.
chunk.loadReference(path, "xml")
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.NoPreselection, filter_mask=False, keypoint_limit=40000, tiepoint_limit=0)
chunk.alignCameras()
-
Hi Alexely,
I've create a base project where I've insert the marker and their references ( gcp.txt). after that I've align and then I've export the relative marker.xml. Now i want to load this xml in a new project where I only have imported new photos.
I've tried your suggestion but it doesen't work infact appears this error: SyntaxError: Invalid syntax. Some suggestions?
Thank you so much.
Vincenzo
-
Sorry, I've wrong. when I write the string chunk.loadReference(path, "xml")
the message is "False" why?
Thanks a lot
-
Hello Vincenzo,
So you wish to import marker positions from xml file that was saved via Tools Menu -> Export Markers command?
Does the new set of images contain the same cameras as original project?
The script line fails, because I've thought that you wish to load Reference information from xml format.
-
2So you wish to import marker positions from xml file that was saved via Tools Menu -> Export Markers command?"
yes, this my case.
"Does the new set of images contain the same cameras as original project? "
the new project have the same cameras position.
Can you help me please? I am new in the Photoscan's Python script.
Thanks again :)
Vincenzo
-
Hello Vincenzo,
Could you please try the following script on any existing XML and related photos?
#compatibility PhotoScan Pro 1.1.6
import PhotoScan
from xml.dom import minidom
path = PhotoScan.app.getOpenFileName("Specify input XML file:")
doc = PhotoScan.app.document
chunk = doc.chunk
xml = minidom.parse(path)
main = xml.childNodes[0]
xml_markers_reference = xml.childNodes[0].childNodes[1].childNodes[5]
xml_markers_proj = xml.childNodes[0].childNodes[1].childNodes[7].childNodes[1].childNodes[1]
xml_camera = xml.childNodes[0].childNodes[1].childNodes[3]
cameras = dict()
markers = dict()
marker_proj = dict()
for i in range(1, len(xml_camera.childNodes) - 1, 2):
camera_id = xml_camera.childNodes[i].getAttribute("id")
camera_label = xml_camera.childNodes[i].getAttribute("label")
cameras[camera_label] = camera_id
for i in range(1, len(xml_markers_reference.childNodes) - 1, 2):
marker_id = xml_markers_reference.childNodes[i].getAttribute("id")
marker_label = xml_markers_reference.childNodes[i].getAttribute("label")
x = float(xml_markers_reference.childNodes[i].childNodes[1].getAttribute("x"))
y = float(xml_markers_reference.childNodes[i].childNodes[1].getAttribute("y"))
z = float(xml_markers_reference.childNodes[i].childNodes[1].getAttribute("z"))
marker_position = PhotoScan.Vector([x, y, z])
markers[marker_id] = (marker_label, marker_position)
for i in range(1, len(xml_markers_proj.childNodes) - 1, 2):
cam_list = dict()
marker_id = xml_markers_proj.childNodes[i].getAttribute("marker_id")
for j in range(1, len(xml_markers_proj.childNodes[i].childNodes) - 1, 2):
camera_id = xml_markers_proj.childNodes[i].childNodes[j].getAttribute("camera_id")
x = float(xml_markers_proj.childNodes[i].childNodes[j].getAttribute("x"))
y = float(xml_markers_proj.childNodes[i].childNodes[j].getAttribute("y"))
cam_list[camera_id] = PhotoScan.Vector([x, y])
marker_proj[marker_id] = cam_list
for marker_id in marker_proj.keys():
chunk.addMarker()
m = chunk.markers[-1]
m.label = markers[marker_id][0]
m.reference.location = markers[marker_id][1]
for camera in chunk.cameras:
if camera.label in cameras.keys():
if cameras[camera.label] in marker_proj[marker_id].keys():
m.projections[camera] = marker_proj[marker_id][cameras[camera.label]]
print("Script finished")