Jon Hogins
4 年前
当前提交
eb84fcf1
共有 7 个文件被更改,包括 133 次插入 和 102 次删除
-
29TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
-
6com.unity.perception/Runtime/GroundTruth/GroundTruthRendererFeature.cs
-
4com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
-
65com.unity.perception/Runtime/GroundTruth/Labelers/InstanceSegmentationLabeler.cs
-
70com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
26com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs
-
35com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
|
|||
using System; |
|||
using Unity.Collections; |
|||
using UnityEngine.Experimental.Rendering; |
|||
[RequireComponent(typeof(Camera))] |
|||
[RequireComponent(typeof(PerceptionCamera))] |
|||
public bool saveImages = false; |
|||
public string annotationId = "E657461D-B950-42E1-8141-BEC9B4810241"; |
|||
//Uncomment when we support saving instance segmentation labels
|
|||
//public bool saveImages = false;
|
|||
//public string annotationId = "E657461D-B950-42E1-8141-BEC9B4810241";
|
|||
|
|||
RenderTexture m_SegmentationTexture; |
|||
RenderTextureReader<uint> m_SegmentationReader; |
|||
|
|||
#if URP_PRESENT
|
|||
[NonSerialized] |
|||
InstanceSegmentationUrpPass m_InstanceSegmentationUrpPass; |
|||
#endif
|
|||
|
|||
public RenderTexture InstanceSegmentationRenderTexture => m_SegmentationTexture; |
|||
|
|||
public event Action<int, NativeArray<uint>, RenderTexture> InstanceSegmentationImageReadback; |
|||
|
|||
public void Start() |
|||
{ |
|||
var myCamera = GetComponent<Camera>(); |
|||
var perceptionCamera = GetComponent<PerceptionCamera>(); |
|||
var width = myCamera.pixelWidth; |
|||
var height = myCamera.pixelHeight; |
|||
m_SegmentationTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8)); |
|||
m_SegmentationTexture.name = "Segmentation"; |
|||
|
|||
#if HDRP_PRESENT
|
|||
var customPassVolume = this.GetComponent<CustomPassVolume>() ?? gameObject.AddComponent<CustomPassVolume>(); |
|||
customPassVolume.injectionPoint = CustomPassInjectionPoint.BeforeRendering; |
|||
customPassVolume.isGlobal = true; |
|||
m_SegmentationPass = new InstanceSegmentationPass() |
|||
{ |
|||
name = "Segmentation Pass", |
|||
targetCamera = myCamera, |
|||
targetTexture = segmentationTexture |
|||
}; |
|||
m_SegmentationPass.EnsureInit(); |
|||
customPassVolume.customPasses.Add(m_SegmentationPass); |
|||
#endif
|
|||
#if URP_PRESENT
|
|||
perceptionCamera.AddScriptableRenderPass(new InstanceSegmentationUrpPass(myCamera, m_SegmentationTexture)); |
|||
#endif
|
|||
|
|||
m_SegmentationReader = new RenderTextureReader<uint>(m_SegmentationTexture, myCamera, (frameCount, data, tex) => |
|||
{ |
|||
InstanceSegmentationImageReadback?.Invoke(frameCount, data, tex); |
|||
}); |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
if (m_SegmentationTexture != null) |
|||
m_SegmentationTexture.Release(); |
|||
|
|||
m_SegmentationTexture = null; |
|||
|
|||
m_SegmentationReader?.WaitForAllImages(); |
|||
m_SegmentationReader?.Dispose(); |
|||
m_SegmentationReader = null; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue