Forum

Author Topic: Importing markers in project  (Read 2352 times)

Ingsayyad

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
Importing markers in project
« on: May 02, 2015, 12:38:52 PM »
I have a project with markers (old) added in it. Now I want to import addition markers (new) from other project. Importing new markers as xml deletes the existing one (old) and added only new. How can I have project with old and new markers.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14965
    • View Profile
Re: Importing markers in project
« Reply #1 on: May 03, 2015, 12:07:58 PM »
Hello Ingsayyad,

You can try the following script, hope it works:

Code: [Select]
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")

Best regards,
Alexey Pasumansky,
Agisoft LLC