Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Etienne_U

Pages: [1]
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

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)

2
Python and Java API / Iterate through camera sensors within a chunk
« on: March 07, 2023, 01:57:50 PM »
Dear Metashape Community,

I have a project with multiple sensors ( let say sensor1, sensor2, sensor3 ...).
I would like to iterate through each sensor, to create a camera group for each sensor, but the messge error I get is "sensor is not iterable".

How can I solve it ?

Thanks a lot for your answers,

Best regards,

Etienne

Pages: [1]