浏览代码

commiting changes that visualize on overlay layer

/result_visualization
Steven Borkman 4 年前
当前提交
0645e2fb
共有 26 个文件被更改,包括 2174 次插入509 次删除
  1. 9
      TestProjects/PerceptionURP/Assets/ExampleLabelingConfiguration.asset
  2. 2
      TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs.meta
  3. 940
      TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
  4. 8
      TestProjects/PerceptionURP/Assets/Textures/outline_box.png
  5. 12
      TestProjects/PerceptionURP/Assets/Textures/outline_box.png.meta
  6. 182
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  7. 3
      com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
  8. 11
      TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat
  9. 26
      TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs
  10. 27
      TestProjects/PerceptionURP/Assets/ExampleScripts/SegmentationToggleHandler.cs
  11. 11
      TestProjects/PerceptionURP/Assets/ExampleScripts/SegmentationToggleHandler.cs.meta
  12. 33
      TestProjects/PerceptionURP/Assets/ExampleScripts/TransparencySlider.cs
  13. 11
      TestProjects/PerceptionURP/Assets/ExampleScripts/TransparencySlider.cs.meta
  14. 8
      TestProjects/PerceptionURP/Assets/Fonts.meta
  15. 3
      TestProjects/PerceptionURP/Assets/Textures/sharp_done_white_18dp.png
  16. 104
      TestProjects/PerceptionURP/Assets/Textures/sharp_done_white_18dp.png.meta
  17. 1001
      TestProjects/PerceptionURP/Assets/Fonts/Inter-Light.otf
  18. 23
      TestProjects/PerceptionURP/Assets/Fonts/Inter-Light.otf.meta
  19. 107
      TestProjects/PerceptionURP/Assets/Textures/Resources/SegmentationMaterial.mat
  20. 8
      TestProjects/PerceptionURP/Assets/Textures/Resources/SegmentationMaterial.mat.meta
  21. 154
      TestProjects/PerceptionURP/Assets/ExampleScripts/BoundingBoxRenderer.cs
  22. 0
      /TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs.meta
  23. 0
      /TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat
  24. 0
      /TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat.meta

9
TestProjects/PerceptionURP/Assets/ExampleLabelingConfiguration.asset


- id: 3
label: Crate
value: 30000
- id: 4
label: BoxMookie
value: 4000
- id: 5
label: BoxKeith
value: 5000
- id: 6
label: BoxGooden
value: 6000

2
TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs.meta


fileFormatVersion: 2
guid: aafc8ed8dbada48fe83980a50c518440
guid: c6e2e5ca2c5264975a091af191e86bdc
MonoImporter:
externalObjects: {}
serializedVersion: 2

940
TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
文件差异内容过多而无法显示
查看文件

8
TestProjects/PerceptionURP/Assets/Textures/outline_box.png

之前 之后
宽度: 100  |  高度: 100  |  大小: 2.2 KiB

12
TestProjects/PerceptionURP/Assets/Textures/outline_box.png.meta


maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
filterMode: 1
aniso: 1
wrapU: 0
wrapV: 0
wrapW: 0
wrapU: 1
wrapV: 1
wrapW: 1
spriteExtrude: 1
spriteExtrude: 0
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}

182
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;
#endif
using UnityEngine.UI;
namespace UnityEngine.Perception.GroundTruth
{

/// Whether object bounding boxes should be computed
/// </summary>
public bool produceBoundingBoxAnnotations = true;
public bool visualizeBoundingBoxAnnotations = true;
public bool visualizeSegementationTextures = true;
// Transparency value for the visualization texture, value needs to be between 0 and 1
public float visualizeSegmentationTextureTransparency = 0.5f;
public float GetVisualizeSegmentationTextureTransparency()
{
return this.visualizeSegmentationTextureTransparency;
}
public void SetVisualizeSegmentationTextureTransparency(float visualizeSegmentationTextureTransparency)
{
this.visualizeSegmentationTextureTransparency = visualizeSegmentationTextureTransparency;
if (segmentationVisualizerGameObject != null)
{
var renderer = segmentationVisualizerGameObject.GetComponent<MeshRenderer>();
if (renderer != null) renderer.material.SetColor("_BaseColor", new Color(1,1,1,visualizeSegmentationTextureTransparency));
}
}
/// <summary>
/// The ID to use for bounding box annotations in the resulting dataset
/// </summary>

public float height;
}
private GameObject boxQuad = null;
private GameObject cubeQuad = null;
private GameObject crateQuad = null;
ClassCountValue[] m_ClassCountValues;
BoundingBoxValue[] m_BoundingBoxValues;
RenderedObjectInfoValue[] m_VisiblePixelsValues;

return m_PersistentSensorData.Remove(key);
}
public void SetBoundsVisualizationEnabled(bool enable)
{
if (boundsVisualizerHolder != null) boundsVisualizerHolder.SetActive(enable);
CaptureOptions.useAsyncReadbackIfSupported = !enable;
}
public void SetEnableSegmentationVisualization(bool enable)
{
visualizeSegementationTextures = enable;
if (segmentationVisualizerGameObject != null) segmentationVisualizerGameObject.SetActive(enable);
}
public bool IsSegmentationVisualizationEnabled()
{
return visualizeSegementationTextures;
}
private int frameCount = 0;
private Dictionary<string, MeshFilter> quadRenderCache = null;
private int visualizerLayerId = 0;
private GameObject boundsVisualizerHolder = null;
private GameObject segmentationVisualizerGameObject = null;
// Start is called before the first frame update
void Awake()
{

semanticSegmentationUrpPass = new SemanticSegmentationUrpPass(myCamera, labelingTexture, LabelingConfiguration);
#endif
if (visualizeBoundingBoxAnnotations)
{
CaptureOptions.useAsyncReadbackIfSupported = false;
}
if (produceSegmentationImages)
{
var specs = LabelingConfiguration.LabelEntries.Select((l) => new SemanticSegmentationSpec()

if (produceRenderedObjectInfoMetric)
ProduceRenderedObjectInfoMetric(renderedObjectInfos, frameCount);
// TODO not sure if this is the right place for this
VisualizeSegmentationTexture(labelingTexture);
visualizerLayerId = LayerMask.NameToLayer("Bounds");
boxQuad = GameObject.Find("BoxQuad");
cubeQuad = GameObject.Find("CubeQuad");
crateQuad = GameObject.Find("CrateQuad");
if (visualizeBoundingBoxAnnotations)
{
quadRenderCache = new Dictionary<string, MeshFilter>();
}
}
// ReSharper disable InconsistentNaming

}
#endif
MeshFilter GetVisualizationQuad(string label)
{
if (boundsVisualizerHolder == null)
{
boundsVisualizerHolder = new GameObject("BoundsVisualizerHolder");
}
if (!quadRenderCache.ContainsKey(label))
{
var go = new GameObject(label + "Quad");
go.layer = visualizerLayerId;
var meshRenderer = go.AddComponent<MeshRenderer>();
var filter = go.AddComponent<MeshFilter>();
meshRenderer.material = Resources.Load<Material>("OutlineMaterial");
quadRenderCache[label] = filter;
go.transform.parent = boundsVisualizerHolder.transform;
}
return quadRenderCache[label];
}
void VisualizeSegmentationTexture(RenderTexture texture)
{
MeshRenderer mr = null;
if (segmentationVisualizerGameObject == null)
{
segmentationVisualizerGameObject = new GameObject("SegmentationTextureRenderer");
segmentationVisualizerGameObject.layer = visualizerLayerId;
var mf = segmentationVisualizerGameObject.AddComponent<MeshFilter>();
mr = segmentationVisualizerGameObject.AddComponent<MeshRenderer>();
mr.material = Resources.Load<Material>("SegmentationMaterial");
var cam = GetComponent<Camera>();
var ll = cam.ScreenToWorldPoint(new Vector3(0, 0, 10));
var ul = cam.ScreenToWorldPoint(new Vector3(0, cam.pixelHeight, 10));
var ur = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, cam.pixelHeight, 10));
var lr = cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth, 0, 10));
// Set up the mesh to project the segmentation render texture on
mf.mesh.vertices = new Vector3[] { ll, ul, ur, lr };
mf.mesh.triangles = new int[] { 0, 1, 2, 0, 2, 3 };
mf.mesh.uv = new Vector2[] { Vector2.zero, new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) };
if (mr != null)
{
mr.material.SetColor("_BaseColor", new Color(1,1,1,visualizeSegmentationTextureTransparency));
mr.material.SetTexture("_BaseMap", texture);
}
}
}
void VisualizeBoundingBoxes(BoundingBoxValue[] inBoxes)
{
if (!visualizeBoundingBoxAnnotations) return;
foreach (var box in inBoxes)
{
var filter = GetVisualizationQuad(box.label_name);
var cam = GetComponent<Camera>();
var height = cam.pixelHeight * 0.5f;
var y = height + (height - box.y);
Vector3 ll = cam.ScreenToWorldPoint(new Vector3(box.x, y, 1));
Vector3 ul = cam.ScreenToWorldPoint(new Vector3(box.x, y - box.height, 1));
Vector3 ur = cam.ScreenToWorldPoint(new Vector3(box.x + box.width, y - box.height, 1));
Vector3 lr = cam.ScreenToWorldPoint(new Vector3(box.x + box.width, y, 1));
Vector3[] verts = new Vector3[4] {ll, ul, ur, lr};
int[] tris = new int[6] {0, 2, 1, 0, 3, 2};
Vector2[] uvs = new Vector2[4] {Vector2.zero, new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) };
Mesh mesh = new Mesh();
mesh.vertices = verts;
mesh.triangles = tris;
mesh.uv = uvs;
filter.mesh = mesh;
}
}
void ProduceBoundingBoxesAnnotation(NativeArray<RenderedObjectInfo> renderedObjectInfos, List<LabelEntry> labelingConfigurations, int frameCount)
{

width = objectInfo.boundingBox.width,
height = objectInfo.boundingBox.height,
};
GameObject active = crateQuad;
if (labelEntry.label == "Box") active = boxQuad;
else if (labelEntry.label == "Cube") active = cubeQuad;
var cam = GetComponent<Camera>();
var height = cam.pixelHeight;
var halfHeight = height * 0.5f;
var y = halfHeight + (halfHeight - objectInfo.boundingBox.y);
Vector3 ll = cam.ScreenToWorldPoint(new Vector3(objectInfo.boundingBox.x, y, 1));
Vector3 ul = cam.ScreenToWorldPoint(new Vector3(objectInfo.boundingBox.x, y - objectInfo.boundingBox.height, 1));
Vector3 ur = cam.ScreenToWorldPoint(new Vector3(objectInfo.boundingBox.x + objectInfo.boundingBox.width, y - objectInfo.boundingBox.height, 1));
Vector3 lr = cam.ScreenToWorldPoint(new Vector3(objectInfo.boundingBox.x + objectInfo.boundingBox.width, y, 1));
Vector3[] verts = new Vector3[4] {ll, ul, ur, lr};
int[] tris = new int[6] {0, 2, 1, 0, 3, 2};
Vector2[] uvs = new Vector2[4] {Vector2.zero, new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0) };
var filter = active.GetComponent<MeshFilter>();
Mesh mesh = new Mesh();
mesh.vertices = verts;
mesh.triangles = tris;
mesh.uv = uvs;
filter.mesh = mesh;
// TODO I'm not sure that I'm calling this from the right place
VisualizeBoundingBoxes(m_BoundingBoxValues);
boundingBoxAsyncAnnotation.ReportValues(m_BoundingBoxValues);
}
}

var dxLocalPath = Path.Combine(k_SemanticSegmentationDirectory, k_SegmentationFilePrefix) + frameCount + ".png";
var path = Path.Combine(Manager.Instance.GetDirectoryFor(k_SemanticSegmentationDirectory), k_SegmentationFilePrefix) + frameCount + ".png";
var annotation = asyncCaptureInfo.SegmentationAsyncAnnotation;
if (!annotation.IsValid)
return;

3
com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs


this.m_CameraRenderingToSource = cameraRenderingToSource;
m_NextFrameToCapture = Time.frameCount;
// TODO find a better place for this but hardcoded right now to make progress
CaptureOptions.useAsyncReadbackIfSupported = false;
if (!GraphicsUtilities.SupportsAsyncReadback())
m_CpuTexture = new Texture2D(m_Source.width, m_Source.height, m_Source.graphicsFormat, TextureCreationFlags.None);

11
TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat


m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: OutlineMaterial
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0

- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 10
- _EnvironmentReflections: 1
- _EnvironmentReflections: 0
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0

- _ReceiveShadows: 1
- _SampleGI: 0
- _SpecularHighlights: 1
- _SpecularHighlights: 0
- _WorkflowMode: 1
- _WorkflowMode: 0
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColor: {r: 0, g: 0.6256573, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}

26
TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
public class BoxToggleHandler : MonoBehaviour
{
public PerceptionCamera perceptionCamera;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnToggle(bool enabled)
{
perceptionCamera.SetBoundsVisualizationEnabled(enabled);
}
}

27
TestProjects/PerceptionURP/Assets/ExampleScripts/SegmentationToggleHandler.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
public class SegmentationToggleHandler : MonoBehaviour
{
public PerceptionCamera perceptionCamera;
// Start is called before the first frame update
void Start()
{
// TODO set up the default toggle state based on
// the perception cameras default values
}
// Update is called once per frame
void Update()
{
}
public void OnToggled(bool enabled)
{
perceptionCamera.SetEnableSegmentationVisualization(enabled);
}
}

11
TestProjects/PerceptionURP/Assets/ExampleScripts/SegmentationToggleHandler.cs.meta


fileFormatVersion: 2
guid: c5d22ec68465e41e381d199c3d1b6f52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

33
TestProjects/PerceptionURP/Assets/ExampleScripts/TransparencySlider.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.UI;
public class TransparencySlider : MonoBehaviour
{
public PerceptionCamera camera;
private Slider slider;
private bool dontEcho = false;
// Start is called before the first frame update
void Start()
{
slider = GetComponent<Slider>();
dontEcho = true;
slider.value = camera.GetVisualizeSegmentationTextureTransparency();
dontEcho = false;
}
// Update is called once per frame
void Update()
{
}
public void OnValueChanged(float updated)
{
if (!dontEcho) camera.SetVisualizeSegmentationTextureTransparency(slider.value);
}
}

11
TestProjects/PerceptionURP/Assets/ExampleScripts/TransparencySlider.cs.meta


fileFormatVersion: 2
guid: 18a20e306f5fe4bb4b0c0d913ded66da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
TestProjects/PerceptionURP/Assets/Fonts.meta


fileFormatVersion: 2
guid: 4875441768dda4ff1850815606f78cde
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3
TestProjects/PerceptionURP/Assets/Textures/sharp_done_white_18dp.png

之前 之后
宽度: 36  |  高度: 36  |  大小: 171 B

104
TestProjects/PerceptionURP/Assets/Textures/sharp_done_white_18dp.png.meta


fileFormatVersion: 2
guid: 2e218e2f433e54da9a576c807fbf99f9
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

1001
TestProjects/PerceptionURP/Assets/Fonts/Inter-Light.otf
文件差异内容过多而无法显示
查看文件

23
TestProjects/PerceptionURP/Assets/Fonts/Inter-Light.otf.meta


fileFormatVersion: 2
guid: 807ae4a0302114abc9474a0222814b27
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontName: Inter
fontNames:
- Inter
fallbackFontReferences:
- {fileID: 12800000, guid: cbeabcf7adb6f49e78f4d2bb72e7f376, type: 3}
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

107
TestProjects/PerceptionURP/Assets/Textures/Resources/SegmentationMaterial.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: SegmentationMaterial
m_Shader: {fileID: 4800000, guid: 650dd9526735d5b46b79224bc6e94025, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3050
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- SHADOWCASTER
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MaskTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _AlphaClip: 0
- _Blend: 0
- _BumpScale: 1
- _Cull: 2
- _Cutoff: 0.5
- _DstBlend: 10
- _EnableExternalAlpha: 0
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _QueueOffset: 0
- _ReceiveShadows: 1
- _SampleGI: 0
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 5
- _Surface: 1
- _WorkflowMode: 1
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 0.50980395}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
--- !u!114 &3089368426582508830
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 1

8
TestProjects/PerceptionURP/Assets/Textures/Resources/SegmentationMaterial.mat.meta


fileFormatVersion: 2
guid: f562a5a621358402796352af288935cc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

154
TestProjects/PerceptionURP/Assets/ExampleScripts/BoundingBoxRenderer.cs


using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Rendering;
using Unity.Entities;
using Unity.Simulation;
[RequireComponent(typeof(Camera))]
public class BoundingBoxRenderer : MonoBehaviour
{
public GameObject light;
public GameObject target;
private PerceptionCamera perception;
private void Awake()
{
perception = GetComponent<PerceptionCamera>();
CaptureOptions.useAsyncReadbackIfSupported = false;
}
}
#if false
private RenderTexture renderTexture = null;
private Texture2D cpuTexture = null;
private AnnotationDefinition bbDef;
private RenderedObjectInfoGenerator renderedObjectInfoGenerator;
private RenderTextureReader<uint> segmentationReader;
private void Awake()
{
var cam = GetComponent<Camera>();
var width = cam.pixelWidth;
var height = cam.pixelHeight;
renderTexture = new RenderTexture(new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8));
renderTexture.name = "segmentation";
cpuTexture = new Texture2D(renderTexture.width, renderTexture.height, renderTexture.graphicsFormat, TextureCreationFlags.None);
bbDef = SimulationManager.RegisterAnnotationDefinition(
"Target bounding box",
"The position of the target in the camera's local space",
id: Guid.Parse("C0B4A22C-0420-4D9F-BAFC-954B8F7B35A7"));
#if false
renderedObjectInfoGenerator = new RenderedObjectInfoGenerator(labelingConfiguration);
World.DefaultGameObjectInjectionWorld.GetExistingSystem<GroundTruthLabelSetupSystem>().Activate(renderedObjectInfoGenerator);
segmentationReader = new RenderTextureReader<uint>(segmentationTexture, cam, (frameCount, data, tex) =>
{
if (segmentationImageReceived != null)
segmentationImageReceived(frameCount, data);
m_RenderedObjectInfoGenerator.Compute(data, tex.width, boundingBoxOrigin, out var renderedObjectInfos, out var classCounts, Allocator.Temp);
using (s_RenderedObjectInfosCalculatedEvent.Auto())
renderedObjectInfosCalculated?.Invoke(frameCount, renderedObjectInfos);
if (produceObjectCountAnnotations)
OnObjectCountsReceived(classCounts, LabelingConfiguration.LabelEntries, frameCount);
if (produceBoundingBoxAnnotations)
ProduceBoundingBoxesAnnotation(renderedObjectInfos, LabelingConfiguration.LabelEntries, frameCount);
if (produceRenderedObjectInfoMetric)
ProduceRenderedObjectInfoMetric(renderedObjectInfos, frameCount);
});
#endif
}
void Update()
{
RenderTexture.active = renderTexture;
cpuTexture.ReadPixels(new Rect(Vector2.zero, new Vector2(renderTexture.width, renderTexture.height)), 0, 0);
RenderTexture.active = null;
var data = cpuTexture.GetRawTextureData<uint>();
ImageReadCallback(Time.frameCount, data, renderTexture);
Vector3 targetPos = transform.worldToLocalMatrix * target.transform.position;
var sensorHandle = GetComponent<PerceptionCamera>().SensorHandle;
var anno = sensorHandle.ReportAnnotationValues(bbDef, new[] { targetPos });
string jsonValues = string.Empty;
MetricDefinition metricDef = SimulationManager.RegisterMetricDefinition()
anno.ReportMetric(bbDef, jsonValues);
// if (sensorHandle.ShouldCaptureThisFrame)
// {
// var anno = sensorHandle.ReportAnnotationValues(bbDef, new[] { targetPos });
// }
}
void ProduceBoundingBoxesAnnotation(NativeArray<RenderedObjectInfo> renderedObjectInfos, List<LabelEntry> labelingConfigurations, int frameCount)
{
RenderTextureReader<short>();
using (s_BoundingBoxCallback.Auto())
{
var findResult = FindAsyncCaptureInfo(frameCount);
if (findResult.index == -1)
return;
var asyncCaptureInfo = findResult.asyncCaptureInfo;
var boundingBoxAsyncAnnotation = asyncCaptureInfo.BoundingBoxAsyncMetric;
if (!boundingBoxAsyncAnnotation.IsValid)
return;
if (m_BoundingBoxValues == null || m_BoundingBoxValues.Length != renderedObjectInfos.Length)
m_BoundingBoxValues = new BoundingBoxValue[renderedObjectInfos.Length];
for (var i = 0; i < renderedObjectInfos.Length; i++)
{
var objectInfo = renderedObjectInfos[i];
if (!TryGetLabelEntryFromInstanceId(objectInfo.instanceId, out var labelEntry))
continue;
m_BoundingBoxValues[i] = new BoundingBoxValue
{
label_id = labelEntry.id,
label_name = labelEntry.label,
instance_id = objectInfo.instanceId,
x = objectInfo.boundingBox.x,
y = objectInfo.boundingBox.y,
width = objectInfo.boundingBox.width,
height = objectInfo.boundingBox.height,
};
}
boundingBoxAsyncAnnotation.ReportValues(m_BoundingBoxValues);
}
}
void ImageReadCallback(int frameCount, NativeArray<uint> data, RenderTexture renderTexture)
{
Debug.Log("Current frame: " + Time.frameCount + ", working frame: " + frameCount);
// First thing lets check that we are the correct frame...
if (frameCount == Time.frameCount)
{
Debug.Log("We are operating on the current frame");
}
else
{
Debug.Log("We are on a different frame");
}
}
}
#endif

/TestProjects/PerceptionURP/Assets/ExampleScripts/BoundingBoxRenderer.cs.meta → /TestProjects/PerceptionURP/Assets/ExampleScripts/BoxToggleHandler.cs.meta

/TestProjects/PerceptionURP/Assets/Textures/OutlineMaterial.mat → /TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat

/TestProjects/PerceptionURP/Assets/Textures/OutlineMaterial.mat.meta → /TestProjects/PerceptionURP/Assets/Textures/Resources/OutlineMaterial.mat.meta

正在加载...
取消
保存