Forum

Author Topic: Import scale bars into photoscan  (Read 16426 times)

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Import scale bars into photoscan
« on: February 07, 2015, 12:31:32 AM »
Hello can i import scale bars into photoscan ?

I have a stereo system with fix base and saw the function of scale bars of two cameras in photoscan.

Is there a function to define automatically the left an right image of the same number as a stereo base and set also the scale bar between the base ?

greetings andreas

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #1 on: February 07, 2015, 12:33:20 AM »
Hello AS_mining,

I think that the easiest way is use Python scripting.

What is the naming convention for the cameras? NN_links....jpg and NN_rechts...jpg?
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Import scale bars into photoscan
« Reply #2 on: February 07, 2015, 12:39:38 AM »
Hello Alexey,

yes thats the wright naming convention.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #3 on: February 09, 2015, 01:46:28 PM »
Hello AS_mining,

Could you please try the following script on your project without any scale bars:

Code: [Select]
#creates scale bars from the camera pair with the following naming convention: "NM_links..." + "NM_rechts..."

#compatibility PhotoScan Pro 1.1.2

import PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk
print("Script started...")

links, rechts = {}, {}

for camera in chunk.cameras:

if camera.label[0:2].isdecimal() and len(camera.label) > 8:
if "_links" == camera.label[2:8]:
links[int(camera.label[0:2])] = camera
elif "_rechts"  == camera.label[2:9]:
rechts[int(camera.label[0:2])] = camera

processed = 0
for num in links.keys():
if num in rechts.keys():
chunk.addScalebar(links[num], rechts[num])
processed += 1

if processed:
print("Script finished, " + str(processed) + " scale bars created.")
else:
print("No matching pairs!")

In principle, if it is working properly, it will be possible to implement distances import from the text file according to the pair number.
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Import scale bars into photoscan
« Reply #4 on: February 09, 2015, 10:21:24 PM »
Hello Alexey,

that works properly ! Thanks !!! :) :) :)

But where i can import the distances from the text file according to the pair number ?

Greetings !!!

Andreas

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #5 on: February 10, 2015, 01:00:11 PM »
Hello Andreas,

Here's modified script:
Code: [Select]
#creates scale bars from the camera pair with the following naming convention: "NM_links..." + "NM_rechts..."

#compatibility PhotoScan Pro 1.1.2

import PhotoScan
from PySide import QtCore, QtGui

doc = PhotoScan.app.document
chunk = doc.chunk
print("Script started...")

links, rechts = {}, {}

for camera in chunk.cameras:

if camera.label[0:2].isdecimal() and len(camera.label) > 8:
if "_links" == camera.label[2:8]:
links[int(camera.label[0:2])] = camera
elif "_rechts"  == camera.label[2:9]:
rechts[int(camera.label[0:2])] = camera

processed = 0
for num in links.keys():
if num in rechts.keys():
chunk.addScalebar(links[num], rechts[num])
processed += 1

if processed:
print(str(processed) + " scale bars created.")
else:
print("No matching pairs!")

app = QtGui.QApplication.instance()
parent = app.activeWindow()

msg = "Do you wish to import distance values?"
reply = QtGui.QMessageBox.question(parent, 'Message', msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

if (reply == QtGui.QMessageBox.Yes)  and chunk.scalebars:

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

scalebars = {}
for scalebar in chunk.scalebars:
scalebars[scalebar.label] = scalebar

eof = False
line = file.readline()
while not eof:

label, dist = line.split()[0], line.split()[1]

if label in scalebars.keys():
scalebars[label].reference.distance = float(dist)

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

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

The first part is the same, then after the scalebars are created you'll be asked if you wish to import the distances, if you choose Yes, you'll be asked to specify the path to the text file.
In such file on each line you need to have the scalebar label (the same as in Reference pane) and the corresponding distance. I suggest to use "tab" or "space" delimiter.
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Import scale bars into photoscan
« Reply #6 on: February 10, 2015, 11:28:46 PM »
Hello Alexey,

the script works fine!

In this project the scalebar for all left and right cameras has the same dimension.
Perhaps there´s a way to set the same length to all scalebars direct in the script.

Thanks !

Andreas

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #7 on: February 10, 2015, 11:33:09 PM »
Hello Andreas,

Sure, it's possible, I can change the script a little bit.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #8 on: February 11, 2015, 03:27:09 PM »
Please check the following one:

Code: [Select]
#creates scale bars from the camera pair with the following naming convention: "NM_links..." + "NM_rechts..."

#compatibility PhotoScan Pro 1.1.2

import PhotoScan
from PySide import QtCore, QtGui

doc = PhotoScan.app.document
chunk = doc.chunk
print("Script started...")

links, rechts = {}, {}

for camera in chunk.cameras:

if camera.label[0:2].isdecimal() and len(camera.label) > 8:
if "_links" == camera.label[2:8]:
links[int(camera.label[0:2])] = camera
elif "_rechts"  == camera.label[2:9]:
rechts[int(camera.label[0:2])] = camera

processed = 0
scalebars = list()
for num in links.keys():
if num in rechts.keys():
chunk.addScalebar(links[num], rechts[num])

scalebars.append(chunk.scalebar[-1])
processed += 1

if processed:
print(str(processed) + " scale bars created.")
else:
print("No matching pairs!")

app = QtGui.QApplication.instance()
parent = app.activeWindow()

msg = "Do you wish to input distance values?"
reply = QtGui.QMessageBox.question(parent, 'Message', msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

if reply == QtGui.QMessageBox.Yes and len(scalebars):

dist = PhotoScan.app.getFloat("Please input the distance value:", 0.25)

for scalebar in scalebars:
scalebar.reference.distance = float(dist)

PhotoScan.app.update()
print("Script finished")
else:
print("Script finished")

Instead of prompting for the input file, the script will ask you to input the reference distance for newly created scalebars.
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Import scale bars into photoscan
« Reply #9 on: February 12, 2015, 09:49:51 PM »
Hello Alexey,

i get an error at line 28

Script started...
Traceback (most recent call last):
  File "F:/00_RAG/IPS/0007/create_basis_and_import_basis_length_python.txt", line 28, in <module>
    scalebars.append(chunk.scalebar[1])
AttributeError: 'PhotoScan.Chunk' object has no attribute 'scalebar'

Thanks

Andreas

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #10 on: February 12, 2015, 11:29:30 PM »
chunk.scalebars :)
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Import scale bars into photoscan
« Reply #11 on: February 12, 2015, 11:52:21 PM »
Thanks ! That´s it !

 :) It works now very fine.

Andreas

Anja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Import scale bars into photoscan
« Reply #12 on: October 24, 2022, 03:44:01 PM »
Hello!
I would like to ask you if you can rewrite this script for metashape?
Unfortunately I couldn't find it on Github.
Or is there another posibility to import scalebars when using stereocameras now?

Thank you very much,
Anja

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15471
    • View Profile
Re: Import scale bars into photoscan
« Reply #13 on: October 27, 2022, 04:36:29 PM »
Hello Anja,

What kind of information you are planning to have on input for the scale bars: pairs of markers (labels in the texture file) or pairs of camera labels?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Anja

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Import scale bars into photoscan
« Reply #14 on: October 28, 2022, 11:55:32 AM »
Hello!

I have a stereo camera and the base between the pairs of cameras is 12 cm.
I would like to import this base/scale bar for every pair of cameras automatically.

Thanks,
Anja