|
|
|
|
|
|
using System.Linq; |
|
|
|
using NUnit.Framework; |
|
|
|
using Unity.Collections; |
|
|
|
using UnityEditorInternal; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Perception.GroundTruth; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
break; |
|
|
|
case SegmentationKind.Semantic: |
|
|
|
expectedPixelValue = k_SemanticPixelValue; |
|
|
|
cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.frameCount, a.data, a.sourceTexture)); |
|
|
|
cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.frameCount, a.data, a.sourceTexture), false); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
CollectionAssert.AreEqual(Enumerable.Repeat(expectedPixelValue, data.Length), data); |
|
|
|
} |
|
|
|
|
|
|
|
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data)); |
|
|
|
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data), false); |
|
|
|
|
|
|
|
AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(label: "non-matching")); |
|
|
|
yield return null; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[UnityTest] |
|
|
|
public IEnumerator SemanticSegmentationPass_WithEmptyFrame_ProducesBlack() |
|
|
|
public IEnumerator SemanticSegmentationPass_WithEmptyFrame_ProducesBlack([Values(false, true)] bool showVisualizations) |
|
|
|
{ |
|
|
|
int timesSegmentationImageReceived = 0; |
|
|
|
var expectedPixelValue = new Color32(0, 0, 0, 255); |
|
|
|
|
|
|
CollectionAssert.AreEqual(Enumerable.Repeat(expectedPixelValue, data.Length), data); |
|
|
|
} |
|
|
|
|
|
|
|
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data)); |
|
|
|
var cameraObject = SetupCameraSemanticSegmentation(a => OnSegmentationImageReceived(a.data), showVisualizations); |
|
|
|
TestHelper.LoadAndStartRenderDocCapture(out var gameView); |
|
|
|
yield return null; |
|
|
|
var segLabeler = (SemanticSegmentationLabeler)cameraObject.GetComponent<PerceptionCamera>().labelers[0]; |
|
|
|
var request = AsyncGPUReadback.Request(segLabeler.targetTexture, callback: r => |
|
|
|
|
|
|
AsyncGPUReadback.WaitAllRequests(); |
|
|
|
|
|
|
|
RenderDoc.EndCaptureRenderDoc(gameView); |
|
|
|
|
|
|
|
//request.WaitForCompletion();
|
|
|
|
Assert.IsTrue(request.done); |
|
|
|
Assert.IsFalse(request.hasError); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[UnityTest] |
|
|
|
public IEnumerator SemanticSegmentationPass_WithTextureOverride_RendersToOverride() |
|
|
|
public IEnumerator SemanticSegmentationPass_WithTextureOverride_RendersToOverride([Values(true, false)] bool showVisualizations) |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera); |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera, showVisualizations); |
|
|
|
var labelConfig = ScriptableObject.CreateInstance<SemanticSegmentationLabelConfig>(); |
|
|
|
labelConfig.Init(new List<SemanticSegmentationLabelEntry>() |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
var cameraObject = segmentationKind == SegmentationKind.Instance ? |
|
|
|
SetupCameraInstanceSegmentation(OnSegmentationImageReceived<uint>) : |
|
|
|
SetupCameraSemanticSegmentation((a) => OnSegmentationImageReceived<Color32>(a.frameCount, a.data, a.sourceTexture)); |
|
|
|
SetupCameraSemanticSegmentation((a) => OnSegmentationImageReceived<Color32>(a.frameCount, a.data, a.sourceTexture), false); |
|
|
|
|
|
|
|
object expectedPixelValue = segmentationKind == SegmentationKind.Instance ? (object) 1 : k_SemanticPixelValue; |
|
|
|
expectedLabelAtFrame = new Dictionary<int, object> |
|
|
|
|
|
|
|
|
|
|
GameObject SetupCameraInstanceSegmentation(Action<int, NativeArray<uint>, RenderTexture> onSegmentationImageReceived) |
|
|
|
{ |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera); |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera, false); |
|
|
|
GameObject SetupCameraSemanticSegmentation(Action<SemanticSegmentationLabeler.ImageReadbackEventArgs> onSegmentationImageReceived) |
|
|
|
GameObject SetupCameraSemanticSegmentation(Action<SemanticSegmentationLabeler.ImageReadbackEventArgs> onSegmentationImageReceived, bool showVisualizations) |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera); |
|
|
|
var cameraObject = SetupCamera(out var perceptionCamera, showVisualizations); |
|
|
|
var labelConfig = ScriptableObject.CreateInstance<SemanticSegmentationLabelConfig>(); |
|
|
|
labelConfig.Init(new List<SemanticSegmentationLabelEntry>() |
|
|
|
{ |
|
|
|
|
|
|
return cameraObject; |
|
|
|
} |
|
|
|
|
|
|
|
GameObject SetupCamera(out PerceptionCamera perceptionCamera) |
|
|
|
GameObject SetupCamera(out PerceptionCamera perceptionCamera, bool showVisualizations) |
|
|
|
{ |
|
|
|
var cameraObject = new GameObject(); |
|
|
|
cameraObject.SetActive(false); |
|
|
|
|
|
|
perceptionCamera = cameraObject.AddComponent<PerceptionCamera>(); |
|
|
|
perceptionCamera.captureRgbImages = false; |
|
|
|
perceptionCamera.showVisualizations = showVisualizations; |
|
|
|
|
|
|
|
AddTestObjectForCleanup(cameraObject); |
|
|
|
return cameraObject; |
|
|
|