Forum

Author Topic: Error in the script when selecting confidence points.  (Read 1026 times)

JulioPereira

  • Newbie
  • *
  • Posts: 9
    • View Profile
Error in the script when selecting confidence points.
« on: January 02, 2025, 11:10:36 PM »
"When I manually apply the filter between 0 and 2, many points appear to be selected, but when automated, only 4 are estimated. Why does this happen?

2025-01-02 16:21:54 SelectPoints: point_cloud = 4
2025-01-02 16:21:54 Selecting points...
2025-01-02 16:21:55 Finished processing in 0.902 sec (exit code 1)
2025-01-02 16:21:55 Finished processing in 0.001 sec (exit code 0)
2025-01-02 16:21:55 Error applying the confidence filter: Null point cloud selection"

import Metashape

def filter_by_confidence(min_confidence=1, max_confidence=2):
    # Acessar o documento atual
    doc = Metashape.app.document

    # Verificar se existem chunks no projeto
    if not doc.chunks:
        print("Nenhum chunk encontrado no projeto.")
        return

    chunk = doc.chunk
    if not chunk:
        print("Nenhum chunk ativo.")
        return

    if not chunk.point_cloud:
        print("Nenhuma nuvem de pontos ativa.")
        return

    point_cloud = chunk.point_cloud

    # Verificar se o atributo 'setConfidenceFilter' existe
    if not hasattr(point_cloud, 'setConfidenceFilter'):
        print("Atributo 'setConfidenceFilter' não está disponível na nuvem de pontos.")
        return

    # Verificar e obter as câmeras habilitadas no chunk
    cameras = [camera for camera in chunk.cameras if camera.enabled]
    if not cameras:
        print("Nenhuma câmera habilitada encontrada.")
        return

    # Aplicar o filtro de confiança
    try:
        # Configurar o filtro de confiança
        point_cloud.setConfidenceFilter(min_confidence, max_confidence)

        # Selecionar pontos fora do intervalo de confiança
        point_cloud.selectMaskedPoints(cameras)

        # Remover os pontos selecionados
        point_cloud.removeSelectedPoints()

        print(f"Pontos com confiança fora do intervalo [{min_confidence}, {max_confidence}] foram removidos.")
    except Exception as e:
        print(f"Erro ao aplicar o filtro de confiança: {e}")

# Exemplo de uso
filter_by_confidence(min_confidence=1, max_confidence=2)
« Last Edit: January 02, 2025, 11:47:39 PM by JulioPereira »

Paulo

  • Hero Member
  • *****
  • Posts: 1529
    • View Profile
Re: Error in the script when selecting confidence points.
« Reply #1 on: January 03, 2025, 09:22:45 AM »
Bom dia,

acho que o selectMaskedPoints nao é adequado pra você. Isto só seleciona pontos com projecçao nas mascaraa de imagene.

O seguinte código vai remover todos os ponto com nível de confiança no intervalo  0 a 2:

Code: [Select]
chunk.point_cloud.setConfidenceFilter(0, 2)  # configuring point cloud filter so that only point with low-confidence currently active
all_points_classes = list(range(128))
chunk.point_cloud.removePoints(all_points_classes)  # removes all active points of the point cloud, i.e. removing all low-confidence points
chunk.point_cloud.resetFilters()  # resetear o filtro

Espero que possa ajudar...
« Last Edit: January 03, 2025, 09:24:33 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor