Forum

Author Topic: Computing and Exporting Image Quality to csv File  (Read 2629 times)

KurriR

  • Newbie
  • *
  • Posts: 8
    • View Profile
Computing and Exporting Image Quality to csv File
« on: October 02, 2019, 12:25:18 AM »
Hi All,

Would anyone have a script for computing and export the image quality assessment in photoscan to a CSV file for post-processing?

I'm currently working on a degree of tests of "how bad can an image be before photogrammetry becomes unfeasable".



Thanks All!



KR

Paulo

  • Hero Member
  • *****
  • Posts: 1321
    • View Profile
Re: Computing and Exporting Image Quality to csv File
« Reply #1 on: October 02, 2019, 02:07:52 AM »
Hello,

try this code

Code: [Select]
# Compatibility - Agisoft PhotoScan Professional 1.5 or 1.6
# Estimates Image quality and saves to csv file

# export format:
# label, quality 

import Metashape as PhotoScan
import time

print("Estimating image quality and export to CSV file")
found_major_version = ".".join(Metashape.app.version.split('.')[:2])
doc = PhotoScan.app.document
chunk = doc.chunk

path = PhotoScan.app.getSaveFileName("Specify export path and filename:", filter = "CSV file (*.csv);;All formats (*.*)")

file = open(path, "wt")
print("Script started")

t0 = time.time()

file.write(",".join(["Label","Quality\n"]))

cameras = chunk.cameras
cameras = [camera for camera in cameras
                    if camera.type != Metashape.Camera.Type.Keyframe]

camerasniq = [camera for camera in cameras
                    if 'Image/Quality' not in camera.meta]

if len(camerasniq) > 0:
if found_major_version == '1.6':
chunk.analyzePhotos(camerasniq)
else:
chunk.estimateImageQuality(camerasniq)


for camera in cameras:

quality = float(camera.meta['Image/Quality'])
       
file.write("{},{:.3f}\n".format(camera.label, quality))


t1 = time.time()

file.flush()
file.close()
print("Script finished in " + str(int(t1-t0)) + " seconds.")
Best Regards,
Paul Pelletier,
Surveyor

KurriR

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Computing and Exporting Image Quality to csv File
« Reply #2 on: October 03, 2019, 09:51:22 PM »
Hi Paulo,

Thank you for this code. However, I'm running into the issue "  'Metashape.Camera' object has no attribute 'type' ". When looking through the Python API it seems there is no application for "Camera.type" like found in your code below on line 25.

Could you please provide any guidance on this?

Thanks,


KR

Paulo

  • Hero Member
  • *****
  • Posts: 1321
    • View Profile
Re: Computing and Exporting Image Quality to csv File
« Reply #3 on: October 03, 2019, 11:25:21 PM »
Hi KR,

Camera.type attribute was introduced in Metashape version 1.5.2... so if your version is anterior to 1.5.2, you can just comment out the line
Code: [Select]
# cameras = [camera for camera in cameras
                    if camera.type != Metashape.Camera.Type.Keyframe]
Best Regards,
Paul Pelletier,
Surveyor

KurriR

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Computing and Exporting Image Quality to csv File
« Reply #4 on: October 04, 2019, 12:02:00 AM »
Thank you, Paulo, very much appreciated!

- It works great!