image :

PhotoScan Scale Bars

Recently have taken to using custom scalebars with coded targets when photogrammetric modelling with Agisoft Photoscan.

Detecting targets is automatic, importing coordinates is automatic. Currently, importing scalebars is not.

Here’s a very basic Python script from importing scalebars and setting their value.

 

# script for automatically creating and importing scalebars from a csv file.
# format must be
# modified from script for making scale bars from the camera
# pair with the following naming convention: "NM_links..." + "NM_rechts..." by Alexey

#compatibility PhotoScan Pro 1.3.2

import PhotoScan
from PySide2 import QtCore, QtGui

doc = PhotoScan.app.document
chunk = doc.chunk
print("Create and import scalebars")

msg = "Choose a scalebar csv file"

path = PhotoScan.app.getOpenFileName("Select input text file:")
file = open(path, "rt")

eof = False
line = file.readline()

while not eof:
 #split the line and load into variables
 point1, point2, dist, acc = line.split(",")

 #iterate through chunk markers and see if there is a match for point 1
 if (len(chunk.markers) > 0):
 for marker in chunk.markers:
 if (marker.label == point1):
 scale1 = marker
 #iterate through chunk markers and see if there is a match for point 2
 for marker in chunk.markers:
 if (marker.label == point2):
 scale2 = marker

 #create a new scale bar between points if they exist and set distance
 scalebar = chunk.addScalebar(scale1,scale2)
 scalebar.reference.distance = float(dist)
 nopair = 0
 else:
 nopair = 1
 else:
 nopair = 0
 if nopair:
 print("Missing one or other end of point")

 else:
 print("no markers")

 #reading the next line in input file
 line = file.readline()
 if not len(line):
 eof = True
 break

file.close()
PhotoScan.app.update()
print("Script finished")