Forum

Author Topic: Setting camera accuracy with Python  (Read 2756 times)

gordon.freeman

  • Newbie
  • *
  • Posts: 1
    • View Profile
Setting camera accuracy with Python
« 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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10302
    • View Profile
Re: Setting camera accuracy with Python
« Reply #1 on: December 18, 2015, 05:32:52 PM »
Hello Marcel,

If you wish to change the accuracy for all the cameras (change the default accuracy for the chunk), use the following line:
Code: [Select]
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:
Code: [Select]
camera.reference.accuracy = (x, y, z)
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jeroenvdborre

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Setting camera accuracy with Python
« Reply #2 on: October 13, 2016, 02:58:34 PM »
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()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10302
    • View Profile
Re: Setting camera accuracy with Python
« Reply #3 on: October 13, 2016, 10:33:32 PM »
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.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jeroenvdborre

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Setting camera accuracy with Python
« Reply #4 on: October 14, 2016, 10:04:33 AM »
Yes I was using an older version. Now it works indeed. Thanks.

jansawicki

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Setting camera accuracy with Python
« Reply #5 on: January 31, 2019, 06:35:15 PM »
Hello Marcel,

If you wish to change the accuracy for all the cameras (change the default accuracy for the chunk), use the following line:
Code: [Select]
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:
Code: [Select]
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.

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

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10302
    • View Profile
Re: Setting camera accuracy with Python
« Reply #6 on: January 31, 2019, 06:52:59 PM »
Hello Jan,

If you wish to define the accuracy globally for all the cameras:
Code: [Select]
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:
Code: [Select]
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.
Best regards,
Alexey Pasumansky,
AgiSoft LLC

jansawicki

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Setting camera accuracy with Python
« Reply #7 on: February 01, 2019, 11:28:43 AM »
It worked, thanks!

harrytwomey

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Setting camera accuracy with Python
« Reply #8 on: April 17, 2019, 11:23:03 AM »
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

harrytwomey

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Setting camera accuracy with Python
« Reply #9 on: April 17, 2019, 01:08:09 PM »
i think i did it
Code: [Select]
# 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))

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 10302
    • View Profile
Re: Setting camera accuracy with Python
« Reply #10 on: April 17, 2019, 01:42:31 PM »
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?
Best regards,
Alexey Pasumansky,
AgiSoft LLC

harrytwomey

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Setting camera accuracy with Python
« Reply #11 on: April 17, 2019, 01:58:59 PM »
yes..yes it does :(

today is the first we are hearing about this advanced preference settings