1
Python and Java API / TiePoint Filtering
« on: May 09, 2023, 03:50:44 PM »
Dear Metashape Community,
I am writing an algorithm to keep only a percentage of the tiepoints after sort them by filtering.
For example, I want to filter tiepoints by ReprojectionError and keep the 80% best
then filter tiepoints by ReconstructionUncertainty and keep the 80% best
then filter tiepoints by ProjectionAccuracy and keep the 80% best
For example, if I first have 10 000 000 points and I want to keep each time 80%, then it should become :
10 000 000 -> 8 000 000
8 000 000 -> 6 400 000
6 400 000 -> 5 120 000
The problem is that it works for the first filter, and then it removes more than 80% ( for example I get 5 500 000 points instead of 6 400 000)
Does someone have an idea why ? You'll find my script attached to this message.
Thanks a lot,
Best regards,
Etienne
I am writing an algorithm to keep only a percentage of the tiepoints after sort them by filtering.
For example, I want to filter tiepoints by ReprojectionError and keep the 80% best
then filter tiepoints by ReconstructionUncertainty and keep the 80% best
then filter tiepoints by ProjectionAccuracy and keep the 80% best
For example, if I first have 10 000 000 points and I want to keep each time 80%, then it should become :
10 000 000 -> 8 000 000
8 000 000 -> 6 400 000
6 400 000 -> 5 120 000
The problem is that it works for the first filter, and then it removes more than 80% ( for example I get 5 500 000 points instead of 6 400 000)
Does someone have an idea why ? You'll find my script attached to this message.
Thanks a lot,
Best regards,
Etienne
Code: [Select]
import Metashape
import glob
import os
import time
import math
def Tie_Points_Filtering():
doc = Metashape.app.document
# Demande à l'utilisateur du nom du chunk
chunk_name = Metashape.app.getString("What is the chunk's name ?")
# Itération au sein des chunks pour travailler dans celui sélectionner par l'utilisateur
for chunk_it in doc.chunks:
if chunk_name == chunk_it.label:
chunk = chunk_it
# Demande de combien de pourcent de tie points à garder
TARGET_PERCENT = Metashape.app.getFloat("What percent of tie points would you like to keep after the alignement ?")
########################## Filtre des tie points #######################
# Fonction pour supprimer les mauvais tie points
def remove_tie_points(critere,TARGET_PERCENT):
points = chunk.tie_points
num_points = len(chunk.tie_points.points)
target = num_points * TARGET_PERCENT / 100
# Trie des Tiepoints selon leur erreur
list_values = []
f = Metashape.TiePoints.Filter()
f.init(points, criterion = critere)
list_values = f.values
list_values.sort()
# Threshold à appliquer
threshold = list_values[int(target)]
f.selectPoints(threshold)
f.removePoints(threshold)
# Suppresion des tie points pour selon les 3 différentes manières
critere = Metashape.TiePoints.Filter.ReprojectionError
remove_tie_points(critere,int(TARGET_PERCENT))
critere = Metashape.TiePoints.Filter.ReconstructionUncertainty
remove_tie_points(critere,int(TARGET_PERCENT))
critere = Metashape.TiePoints.Filter.ProjectionAccuracy
remove_tie_points(critere,int(TARGET_PERCENT))
chunk.optimizeCameras(fit_f=True, fit_cx=True, fit_cy=True, fit_b1=False, fit_b2=False, fit_k1=True,
fit_k2=True, fit_k3=True, fit_k4=True, fit_p1=True, fit_p2=True, fit_corrections=True,
adaptive_fitting=True, tiepoint_covariance=True)
label = "Scripts/[02] Tie Points Filtering"
Metashape.app.addMenuItem(label, Tie_Points_Filtering)