Open3

ARDK Semantic Segmentationを理解する

さくたまさくたま

これでとりあえず任意のピクセルの分類が取れる(string)
Enumにしたりとかしよう

using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using Niantic.ARDK;
using Niantic.ARDK.AR;
using Niantic.ARDK.Extensions;
using Niantic.ARDK.AR.ARSessionEventArgs;
using Niantic.ARDK.AR.Configuration;
using Niantic.ARDK.AR.Awareness;
using Niantic.ARDK.AR.Awareness.Semantics;

using UnityEngine;
using UnityEngine.UI;

public class SemanticsQuery : MonoBehaviour
{
    //pass in our semantic manager
    public ARSemanticSegmentationManager _semanticManager;
    
    private ISemanticBuffer _semanticBuffer;
    
    // Channels we want to get semantic confidence data for
    private readonly string[] _channels = {
        "natural_ground", "artificial_ground", "building", "foliage", "grass"
    };

    void Start()
    {
        //add a callback for catching the updated semantic buffer
        _semanticManager.SemanticBufferUpdated += OnSemanticsBufferUpdated;
    }
    
    //will be called when there is a new buffer
    private void OnSemanticsBufferUpdated(ContextAwarenessStreamUpdatedArgs<ISemanticBuffer> args)
    {
        //get the buffer that has been surfaced.
        _semanticBuffer = args.Sender.AwarenessBuffer;
    }

    [CanBeNull]
    public string ExecuteSemanticsQueryAtPixel(Vector2 screenPosition)
    {
        foreach (var channel in _channels)
        {
            if (_semanticBuffer.DoesChannelExistAt((int)screenPosition.x, (int)screenPosition.y, channel))
            {
                return channel;
            }
        }

        return null;
    }
}