Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: gordon.freeman on December 18, 2015, 04:52:47 PM
-
Hello!
I am working with Photoscan Professional Edition and would like to set the camera accuracy to 0.1m using a python script, in the same way, as I can change the camera accuracy in the reference pane using reference settings. Here I can change the camera accuracy from 10m to 0.1m. Can I do this in my python script as well, for all cameras?
Greetings Marcel
-
Hello Marcel,
If you wish to change the accuracy for all the cameras (change the default accuracy for the chunk), use the following line:
PhotoScan.app.document.chunk.accuracy_cameras = (x, y, z)
where x, y, z are values in corresponding direction. Could be the same number for all three, of course.
To change the accuracy for certain camera use:
camera.reference.accuracy = (x, y, z)
-
Dear,
I am using your suggestion, but I get the error message "TypeError: floating point value expected".
What could be the reason?
My code is:
import math
import PhotoScan
doc = PhotoScan.app.document
chunk = doc.chunk
for chunk in doc.chunks:
...
chunk.accuracy_cameras = (1, 1, 1)
PhotoScan.app.update()
-
Hello jeroenvdborre,
Which version you are using? It seems that you might be using some old version, so please update to the version 1.2.6.
-
Yes I was using an older version. Now it works indeed. Thanks.
-
Hello Marcel,
If you wish to change the accuracy for all the cameras (change the default accuracy for the chunk), use the following line:
PhotoScan.app.document.chunk.accuracy_cameras = (x, y, z)
where x, y, z are values in corresponding direction. Could be the same number for all three, of course.
To change the accuracy for certain camera use:
camera.reference.accuracy = (x, y, z)
Can someone pleasy verify my code? I am trying to itterate through cameras and set various accuracies for each camera, although I am having a problem to change even one of them. Below code brings no error messages but doesn't update the data in Reference tab.
import Metashape
doc = Metashape.app.document
chunk = doc.chunk
camera = chunk.cameras[0]
camera.Reference.accuracy = (5,5,5)
print(camera.Reference.accuracy)
Thanks,
Jan
-
Hello Jan,
If you wish to define the accuracy globally for all the cameras:
import Metashape
doc = Metashape.app.document
chunk = doc.chunk
chunk.camera_location_accuracy = Metashape.Vector([5,5,5])
to define accuracy individually for each camera:
import Metashape
doc = Metashape.app.document
chunk = doc.chunk
for camera in chunk.cameras:
camera.reference.location_accuracy = Metashape.Vector([5,5,5])
I just suggest to restart Metashape instance that you are working in, as camera.Reference assignment could break the proper work of Python API in the Console.
-
It worked, thanks!
-
Would it be possible to modify this to extract accuracy from exif of rtk-gps tagged photos and assign these values to each camera
We have a ebee drone with soda camera, example extracted exif using ExifTool by Phil Harvey http://owl.phy.queensu.ca/~phil/exiftool/
The images have all the useful info but photoscan does not read it in with the photos
I uploaded some images for reference
https://wetransfer.com/downloads/17fbb4c07ca291ea11c177ff3c3f178520190417082049/4bbe37c0487ce6e00e4c2dd0c714c82320190417082049/421c22
-
i think i did it
# Script to add exif for SODA Meta data for all cameras in the active chunk.
import PhotoScan
# Checking compatibility
compatible_major_version = "1.4"
found_major_version = ".".join(PhotoScan.app.version.split('.')[:2])
if found_major_version != compatible_major_version:
raise Exception("Incompatible PhotoScan version: {} != {}".format(found_major_version, compatible_major_version))
def sodaADD():
"""
Reads Soda/accuracy/YPR
"""
doc = PhotoScan.app.document
if not len(doc.chunks):
raise Exception("No chunks!")
print("Script started...")
chunk = doc.chunk
for camera in chunk.cameras:
vect = PhotoScan.Vector((10, 10, 10))
locationAccuracy = PhotoScan.Vector((10, 10, 10))
if 'Sensefly/Yaw' in camera.photo.meta.keys():
vect[0] = float(camera.photo.meta["Sensefly/Yaw"])
if 'Sensefly/Pitch' in camera.photo.meta.keys():
vect[1] = float(camera.photo.meta["Sensefly/Pitch"])
if 'Sensefly/Roll' in camera.photo.meta.keys():
vect[2] = float(camera.photo.meta["Sensefly/Roll"])
print(vect)
if 'Sensefly/GPSXYAccuracy' in camera.photo.meta.keys():
locationAccuracy[0] = float(camera.photo.meta["Sensefly/GPSXYAccuracy"])
if 'Sensefly/GPSXYAccuracy' in camera.photo.meta.keys():
locationAccuracy[1] = float(camera.photo.meta["Sensefly/GPSXYAccuracy"])
if 'Sensefly/GPSZAccuracy' in camera.photo.meta.keys():
locationAccuracy[2] = float(camera.photo.meta["Sensefly/GPSZAccuracy"])
print(locationAccuracy)
camera.reference.rotation = vect
camera.reference.location_accuracy = locationAccuracy
chunk.updateTransform()
PhotoScan.app.update()
print("Script finished")
label = "Custom menu/Add S.O.D.A Exif Data"
PhotoScan.app.addMenuItem(label, sodaADD)
print("To execute this script press {}".format(label))
-
Hello harrytwomey,
Which version of PhotoScan/Metashape you are using? In another thread you have posted a script to read the accuracy and orientation data from the XMP, but doesn't it work automatically on the image load, providing that the corresponding options are enabled in the Advanced preferences tab?
-
yes..yes it does :(
today is the first we are hearing about this advanced preference settings