Jon Hogins
4 年前
当前提交
20a475b5
共有 8 个文件被更改,包括 156 次插入 和 100 次删除
-
21com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
-
80com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs
-
39com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
-
9com.unity.perception/Runtime/GroundTruth/Labeling/LabelingConfiguration.cs
-
22com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
1com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
-
81com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs
-
3com.unity.perception/Runtime/GroundTruth/PerceptionCamera_InstanceSegmentation.cs.meta
|
|||
using System; |
|||
using Unity.Collections; |
|||
using Unity.Entities; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
#if HDRP_PRESENT
|
|||
using UnityEngine.Rendering.HighDefinition; |
|||
#endif
|
|||
#if URP_PRESENT
|
|||
using UnityEngine.Rendering.Universal; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Perception.GroundTruth |
|||
{ |
|||
partial class PerceptionCamera |
|||
{ |
|||
public event Action<int, NativeArray<uint>, RenderTexture> InstanceSegmentationImageReadback; |
|||
|
|||
/// <summary>
|
|||
/// Invoked when RenderedObjectInfos are calculated. The first parameter is the Time.frameCount at which the objects were rendered. This may be called many frames after the frame in which the objects were rendered.
|
|||
/// </summary>
|
|||
public event Action<int, NativeArray<RenderedObjectInfo>> RenderedObjectInfosCalculated; |
|||
|
|||
RenderedObjectInfoGenerator m_RenderedObjectInfoGenerator; |
|||
RenderTexture m_InstanceSegmentationTexture; |
|||
RenderTextureReader<uint> m_InstanceSegmentationReader; |
|||
#if HDRP_PRESENT
|
|||
InstanceSegmentationPass m_InstanceSegmentationPass; |
|||
#endif
|
|||
#if URP_PRESENT
|
|||
[NonSerialized] |
|||
InstanceSegmentationUrpPass m_InstanceSegmentationUrpPass; |
|||
#endif
|
|||
|
|||
void SetupInstanceSegmentation() |
|||
{ |
|||
var camera = PerceptionCamera.GetComponent<Camera>(); |
|||
var width = camera.pixelWidth; |
|||
var height = camera.pixelHeight; |
|||
m_InstanceSegmentationTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8)); |
|||
m_InstanceSegmentationTexture.name = "InstanceSegmentation"; |
|||
|
|||
m_RenderedObjectInfoGenerator = new RenderedObjectInfoGenerator(); |
|||
World.DefaultGameObjectInjectionWorld.GetExistingSystem<GroundTruthLabelSetupSystem>().Activate(m_RenderedObjectInfoGenerator); |
|||
|
|||
#if HDRP_PRESENT
|
|||
var customPassVolume = this.GetComponent<CustomPassVolume>() ?? gameObject.AddComponent<CustomPassVolume>(); |
|||
customPassVolume.injectionPoint = CustomPassInjectionPoint.BeforeRendering; |
|||
customPassVolume.isGlobal = true; |
|||
m_SegmentationPass = new InstanceSegmentationPass() |
|||
{ |
|||
name = "Instance segmentation pass", |
|||
targetCamera = myCamera, |
|||
targetTexture = m_SegmentationTexture |
|||
}; |
|||
m_SegmentationPass.EnsureInit(); |
|||
customPassVolume.customPasses.Add(m_SegmentationPass); |
|||
#endif
|
|||
#if URP_PRESENT
|
|||
AddScriptableRenderPass(new InstanceSegmentationUrpPass(camera, m_InstanceSegmentationTexture)); |
|||
#endif
|
|||
|
|||
m_InstanceSegmentationReader = new RenderTextureReader<uint>(m_InstanceSegmentationTexture, camera, (frameCount, data, tex) => |
|||
{ |
|||
InstanceSegmentationImageReadback?.Invoke(frameCount, data, tex); |
|||
}); |
|||
} |
|||
|
|||
void CleanUpInstanceSegmentation() |
|||
{ |
|||
if (m_InstanceSegmentationTexture != null) |
|||
m_InstanceSegmentationTexture.Release(); |
|||
|
|||
m_InstanceSegmentationTexture = null; |
|||
|
|||
m_InstanceSegmentationReader?.WaitForAllImages(); |
|||
m_InstanceSegmentationReader?.Dispose(); |
|||
m_InstanceSegmentationReader = null; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ee9eab40cf054cd6ad5da120c84881d7 |
|||
timeCreated: 1593126137 |
撰写
预览
正在加载...
取消
保存
Reference in new issue