/// <summary>
/// Whether semantic segmentation images should be generated
/// </summary>
public bool produceSegmentationImages = true ;
[FormerlySerializedAs("produceSegmentationImages")]
public bool produceSemanticSegmentationImages = true ;
/// <summary>
/// Whether object counts should be computed
/// </summary>
/// </summary>
public event Action < int , NativeArray < RenderedObjectInfo > > renderedObjectInfosCalculated ;
internal event Action < int , NativeArray < uint > > segmentationImageReceived ;
internal event Action < int , NativeArray < uint > > in stanceS egmentationImageReceived;
internal event Action < NativeSlice < uint > , IReadOnlyList < LabelEntry > , int > classCountsReceived ;
internal RenderTexture segmentationTexture ;
internal RenderTexture instanceSegmentationTexture ;
RenderTextureReader < short > m_ClassLabelingTextureReader ;
RenderTextureReader < uin t> m_SegmentationReader ;
RenderTextureReader < shor t> m_SemanticSe gmentationTexture Reader ;
RenderTextureReader < uint > m_InstanceSegmentationReader ;
RenderedObjectInfoGenerator m_RenderedObjectInfoGenerator ;
Dictionary < string , object > m_PersistentSensorData = new Dictionary < string , object > ( ) ;
public int pixel_value ;
}
[SuppressMessage("ReSharper", "InconsistentNaming")]
struct ObjectCountSpec
{
[UsedImplicitly]
public int label_id ;
[UsedImplicitly]
public string label_name ;
}
/// <summary>
/// Add a data object which will be added to the dataset with each capture. Overrides existing sensor data associated with the given key.
/// </summary>
var width = myCamera . pixelWidth ;
var height = myCamera . pixelHeight ;
if ( ( produceSegmentationImages | | produceObjectCountAnnotations | | produceBoundingBoxAnnotations ) & & LabelingConfiguration = = null )
if ( ( produceSemanticSe gmentationImages | | produceObjectCountAnnotations | | produceBoundingBoxAnnotations ) & & LabelingConfiguration = = null )
produceSegmentationImages = false ;
produceSemanticSe gmentationImages = false ;
segmentationTexture = new RenderTexture ( new RenderTextureDescriptor ( width , height , GraphicsFormat . R8G8B8A8_UNorm , 8 ) ) ;
segmentationTexture . name = "Segmentation" ;
in stanceS egmentationTexture = new RenderTexture ( new RenderTextureDescriptor ( width , height , GraphicsFormat . R8G8B8A8_UNorm , 8 ) ) ;
in stanceS egmentationTexture. name = "Segmentation" ;
labelingTexture = new RenderTexture ( new RenderTextureDescriptor ( width , height , GraphicsFormat . R8G8B8A8_UNorm , 8 ) ) ;
labelingTexture . name = "Labeling" ;
SetupPasses ( customPassVolume ) ;
#endif
#if URP_PRESENT
instanceSegmentationUrpPass = new InstanceSegmentationUrpPass ( myCamera , segmentationTexture ) ;
instanceSegmentationUrpPass = new InstanceSegmentationUrpPass ( myCamera , in stanceS egmentationTexture) ;
if ( produceSegmentationImages )
if ( produceSemanticSe gmentationImages )
{
var specs = LabelingConfiguration . LabelEntries . Select ( ( l ) = > new SemanticSegmentationSpec ( )
{
m_SegmentationAnnotationDefinition = SimulationManager . RegisterAnnotationDefinition ( "semantic segmentation" , specs , "pixel-wise semantic segmentation label" , "PNG" ) ;
m_ClassLabelingTextureReader = new RenderTextureReader < short > ( labelingTexture , myCamera ,
m_SemanticSegmentationTextureReader = new RenderTextureReader < short > ( labelingTexture , myCamera ,
var labelingMetricSpec = LabelingConfiguration . LabelEntries . Select ( ( l ) = > new ObjectCountSpec ( )
{
label_id = l . id ,
label_name = l . label ,
} ) . ToArray ( ) ;
var labelingMetricSpec = LabelingConfiguration . GetAnnotationSpecification ( ) ;
if ( produceObjectCountAnnotations )
{
if ( produceBoundingBoxAnnotations )
{
m_BoundingBoxAnnotationDefinition = SimulationManager . RegisterAnnotationDefinition ( "bounding box" , labelingMetricSpec , "Bounding box for each labeled object visible to the sensor" , id : new Guid ( boundingBoxId ) ) ;
}
if ( produceRenderedObjectInfoMetric )
m_RenderedObjectInfoMetricDefinition = SimulationManager . RegisterMetricDefinition ( "rendered object info" , labelingMetricSpec , "Information about each labeled object visible to the sensor" , id : new Guid ( renderedObjectInfoId ) ) ;
m_SegmentationReader = new RenderTextureReader < uint > ( segmentationTexture , myCamera , ( frameCount , data , tex ) = >
m_InstanceSegmentationReader = new RenderTextureReader < uint > ( instanceSegmentationTexture , myCamera , ( frameCount , data , tex ) = >
if ( segmentationImageReceived ! = null )
segmentationImageReceived ( frameCount , data ) ;
instanceSegmentationImageReceived ? . Invoke ( frameCount , data ) ;
m_RenderedObjectInfoGenerator . Compute ( data , tex . width , boundingBoxOrigin , out var renderedObjectInfos , out var classCounts , Allocator . Temp ) ;
RenderPipelineManager . beginCameraRendering + = OnBeginCameraRendering ;
SimulationManager . SimulationEnding + = OnSimulationEnding ;
}
// ReSharper disable InconsistentNaming
struct RenderedObjectInfoValue
void ReportAsyncAnnotations ( )
{
if ( produceSegmentationImages | | produceObjectCountAnnotations | | produceBoundingBoxAnnotations | | produceRenderedObjectInfoMetric )
if ( produceSemanticSe gmentationImages | | produceObjectCountAnnotations | | produceBoundingBoxAnnotations | | produceRenderedObjectInfoMetric )
if ( produceSegmentationImages )
if ( produceSemanticSe gmentationImages )
captureInfo . SegmentationAsyncAnnotation = SensorHandle . ReportAnnotationAsync ( m_SegmentationAnnotationDefinition ) ;
if ( produceObjectCountAnnotations )
void OnSimulationEnding ( )
{
m_ClassLabeling TextureReader ? . WaitForAllImages ( ) ;
m_ClassLabeling TextureReader ? . Dispose ( ) ;
m_ClassLabeling TextureReader = null ;
m_SemanticSegmentation TextureReader ? . WaitForAllImages ( ) ;
m_SemanticSegmentation TextureReader ? . Dispose ( ) ;
m_SemanticSegmentation TextureReader = null ;
m_SegmentationReader ? . WaitForAllImages ( ) ;
m_SegmentationReader ? . Dispose ( ) ;
m_SegmentationReader = null ;
m_Instance SegmentationReader ? . WaitForAllImages ( ) ;
m_Instance SegmentationReader ? . Dispose ( ) ;
m_Instance SegmentationReader = null ;
RenderPipelineManager . beginCameraRendering - = OnBeginCameraRendering ;
}
OnSimulationEnding ( ) ;
m_ClassLabeling TextureReader ? . Dispose ( ) ;
m_ClassLabeling TextureReader = null ;
if ( segmentationTexture ! = null )
segmentationTexture . Release ( ) ;
m_SemanticSegmentation TextureReader ? . Dispose ( ) ;
m_SemanticSegmentation TextureReader = null ;
if ( in stanceS egmentationTexture ! = null )
in stanceS egmentationTexture. Release ( ) ;
segmentationTexture = null ;
in stanceS egmentationTexture = null ;
if ( labelingTexture ! = null )
labelingTexture . Release ( ) ;
{
public bool enabled ;
public bool foldout ;
protected PerceptionCamera PerceptionCamera { get ; private set ; }
protected SensorHandle SensorHandle { get ; private set ; }
public abstract void Setup ( ) ;
public virtual void Update ( ) { }
public virtual void OnInstanceSegmentationRead ( int frameCount ) { }
internal void Init ( PerceptionCamera perceptionCamera )
{
PerceptionCamera = perceptionCamera ;
SensorHandle = perceptionCamera . SensorHandle ;
}
}
}