public IEnumerator ProducesCorrectBoundingBoxes([ValueSource(nameof(ProducesCorrectBoundingBoxesTestCases))] ProducesCorrectBoundingBoxesData producesCorrectBoundingBoxesData) { var label = "label"; var label2 = "label2"; var labelingConfiguration = ScriptableObject.CreateInstance <LabelingConfiguration>(); labelingConfiguration.LabelEntries = new List <LabelEntry> { new LabelEntry { id = 1, label = label, value = 500 }, new LabelEntry { id = 2, label = label2, value = 500 } }; var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(labelingConfiguration); var groundTruthLabelSetupSystem = World.DefaultGameObjectInjectionWorld.GetExistingSystem <GroundTruthLabelSetupSystem>(); groundTruthLabelSetupSystem.Activate(renderedObjectInfoGenerator); //Put a plane in front of the camera AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label)); AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label2)); yield return(null); var dataNativeArray = new NativeArray <uint>(producesCorrectBoundingBoxesData.data, Allocator.Persistent); renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, producesCorrectBoundingBoxesData.boundingBoxOrigin, out var boundingBoxes, out var classCounts, Allocator.Temp); CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.boundingBoxesExpected, boundingBoxes.ToArray()); CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.classCountsExpected, classCounts.ToArray()); dataNativeArray.Dispose(); boundingBoxes.Dispose(); classCounts.Dispose(); groundTruthLabelSetupSystem.Deactivate(renderedObjectInfoGenerator); renderedObjectInfoGenerator.Dispose(); }
public IEnumerator ProducesCorrectBoundingBoxes([ValueSource(nameof(ProducesCorrectBoundingBoxesTestCases))] ProducesCorrectObjectInfoData producesCorrectObjectInfoData) { var label = "label"; var label2 = "label2"; var labelingConfiguration = ScriptableObject.CreateInstance <IdLabelConfig>(); labelingConfiguration.Init(new List <IdLabelEntry> { new IdLabelEntry { id = 1, label = label }, new IdLabelEntry { id = 2, label = label2 } }); var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(); //Put a plane in front of the camera AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label)); AddTestObjectForCleanup(TestHelper.CreateLabeledPlane(.1f, label2)); yield return(null); var dataNativeArray = new NativeArray <Color32>(producesCorrectObjectInfoData.data, Allocator.Persistent); var cache = labelingConfiguration.CreateLabelEntryMatchCache(Allocator.Persistent); renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectObjectInfoData.stride, producesCorrectObjectInfoData.boundingBoxOrigin, out var boundingBoxes, Allocator.Temp); CollectionAssert.AreEqual(producesCorrectObjectInfoData.renderedObjectInfosExpected, boundingBoxes.ToArray()); dataNativeArray.Dispose(); boundingBoxes.Dispose(); cache.Dispose(); }
public IEnumerator SemanticSegmentationPass_WithLensDistortion() { GameObject cameraObject = null; PerceptionCamera perceptionCamera; var fLensDistortionEnabled = false; var fDone = false; var frames = 0; #if false var dataBBox = new Color32[] { Color.blue, Color.blue, Color.blue, Color.blue }; #endif var boundingBoxWithoutLensDistortion = new Rect(); var boundingBoxWithLensDistortion = new Rect(); void OnSegmentationImageReceived(int frameCount, NativeArray <Color32> data, RenderTexture tex) { frames++; if (frames < 10) { return; } // Calculate the bounding box if (fLensDistortionEnabled == false) { fLensDistortionEnabled = true; var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(); renderedObjectInfoGenerator.Compute(data, tex.width, BoundingBoxOrigin.TopLeft, out var boundingBoxes, Allocator.Temp); boundingBoxWithoutLensDistortion = boundingBoxes[0].boundingBox; // Add lens distortion perceptionCamera.OverrideLensDistortionIntensity(0.715f); frames = 0; } else { var renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(); renderedObjectInfoGenerator.Compute(data, tex.width, BoundingBoxOrigin.TopLeft, out var boundingBoxes, Allocator.Temp); boundingBoxWithLensDistortion = boundingBoxes[0].boundingBox; Assert.AreNotEqual(boundingBoxWithoutLensDistortion, boundingBoxWithLensDistortion); Assert.Greater(boundingBoxWithLensDistortion.width, boundingBoxWithoutLensDistortion.width); fDone = true; } } cameraObject = SetupCamera(out perceptionCamera, false); perceptionCamera.InstanceSegmentationImageReadback += OnSegmentationImageReceived; cameraObject.SetActive(true); // Put a plane in front of the camera var planeObject = GameObject.CreatePrimitive(PrimitiveType.Plane); planeObject.transform.SetPositionAndRotation(new Vector3(0, 0, 10), Quaternion.Euler(90, 0, 0)); planeObject.transform.localScale = new Vector3(0.1f, -1, 0.1f); var labeling = planeObject.AddComponent <Labeling>(); labeling.labels.Add("label"); AddTestObjectForCleanup(planeObject); perceptionCamera.OverrideLensDistortionIntensity(0.5f); while (fDone != true) { yield return(null); } // Destroy the object to force all pending segmented image readbacks to finish and events to be fired. DestroyTestObject(cameraObject); DestroyTestObject(planeObject); }