Hello,
I'm working on a Python pipeline to process large amounts of photos (1500-2000 per project) that is subdivided in two parts: the first part allows the user to add photos and define the number of chunks needed for the second part.
Since my images were taken with our UAV, some are a bit blurry in the set. I'd like to be able to estimate image quality and remove from the photo alignment images with a score below a user-defined threshold.
So far, I have the following code:
import os
import PhotoScan
print(">>> Initialisation du script <<<")
doc = PhotoScan.app.document
chunk = PhotoScan.Chunk()
chunk.label = "New Chunk"
doc.chunks.add(chunk)
path_photos = PhotoScan.app.getExistingDirectory("Spécifiez le dossier contenant les photos : ")
path_photos += "/"
# Vérification du chemin d'enregistrement
project_path = PhotoScan.app.getSaveFileName("Spécifiez le nom du projet à enregistrer : ")
if not project_path:
print("Annulation du script : pas de chemin d'enregistrement fourni")
return 0
if project_path[-4:].lower() != ".psz":
project_path += ".psz"
# Détermination du nombre de trous/chunks
nbTrous = input("Saisissez le nombre de trous dans le golf :")
print(nbTrous + "chunks seront créés, à l'issue de ce script, il faudra détourer chaque trou.")
# Ajout de photos
image_list = os.listdir(path_photos)
for photo in image_list:
if ("jpg" or "jpeg" or "tif" or "png") in photo.lower():
chunk.photos.add(path_photos + photo)
PhotoScan.app.update()
doc.save(project_path)
print("- Photos ajoutées")
# Estimation de la qualité des photos
chunk.estimateImageQuality()
# Alignement des photos
chunk.matchPhotos(accuracy = "medium", preselection = "reference", filter_mask = False, point_limit = 20000)
chunk.alignPhotos()
doc.save(project_path)
print("-- Photos alignées")
# Création de chunks pour chaque trou
chunkIter = 1
while chunkIter <= nbTrous:
chunk.copy()
chunk.label("Trou_" + chunkIter)
chunkIter += 1
print("--- " + nbTrous + " chunks créés.")
# Sauvegarde finale
doc.save(project_path)
print("Projet enregistré, vous pouvez maintenant adapter les Bounding Box de chaque chunk.")
print(">>> Script terminé <<<")
Don't mind the French comments, it's mostly there to be user-friendly as is it meant to be used by French people.
Here the interesting part is this one:
# Estimation de la qualité des photos
chunk.estimateImageQuality()
So estimateImageQuality returns a floating number, but I honestly don't know how to exploit it!
I'd like any photo with a quality score under 0.5 to be removed from the photo alignment process I'm running right after.
Any help would be appreciated!
Best regards