Steven Borkman
4 年前
当前提交
0cca8c9a
共有 15 个文件被更改,包括 1386 次插入 和 6 次删除
-
958TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
-
2TestProjects/PerceptionURP/Packages/manifest.json
-
4TestProjects/PerceptionURP/ProjectSettings/ProjectVersion.txt
-
2TestProjects/PerceptionURP/ProjectSettings/TagManager.asset
-
35com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
3com.unity.perception/Runtime/GroundTruth/RenderTextureReader.cs
-
154TestProjects/PerceptionURP/Assets/ExampleScripts/BoundingBoxRenderer.cs
-
11TestProjects/PerceptionURP/Assets/ExampleScripts/BoundingBoxRenderer.cs.meta
-
8TestProjects/PerceptionURP/Assets/Textures.meta
-
91TestProjects/PerceptionURP/Assets/Textures/OutlineMaterial.mat
-
8TestProjects/PerceptionURP/Assets/Textures/OutlineMaterial.mat.meta
-
8TestProjects/PerceptionURP/Assets/Textures/Resources.meta
-
4TestProjects/PerceptionURP/Assets/Textures/outline_box.png
-
104TestProjects/PerceptionURP/Assets/Textures/outline_box.png.meta
|
|||
m_EditorVersion: 2019.3.13f1 |
|||
m_EditorVersionWithRevision: 2019.3.13f1 (d4ddf0d95db9) |
|||
m_EditorVersion: 2019.3.15f1 |
|||
m_EditorVersionWithRevision: 2019.3.15f1 (59ff3e03856d) |
|
|||
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
|
|
|||
fileFormatVersion: 2 |
|||
guid: aafc8ed8dbada48fe83980a50c518440 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 111bf8a5038f94fbf84d83b9f54eee51 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &-6196874654385650420 |
|||
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 |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_Name: OutlineMaterial |
|||
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, 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: |
|||
- _BaseMap: |
|||
m_Texture: {fileID: 2800000, guid: 417a472ba22dc45ca97477827295176f, type: 3} |
|||
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: 2800000, guid: 417a472ba22dc45ca97477827295176f, type: 3} |
|||
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} |
|||
- _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 |
|||
- _EnvironmentReflections: 1 |
|||
- _GlossMapScale: 0 |
|||
- _Glossiness: 0 |
|||
- _GlossyReflections: 0 |
|||
- _Metallic: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _QueueOffset: 0 |
|||
- _ReceiveShadows: 1 |
|||
- _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: 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} |
|
|||
fileFormatVersion: 2 |
|||
guid: f36a73e2b367840afa68b31b712a0986 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f5944b993f30d441a97627b37e883a71 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 417a472ba22dc45ca97477827295176f |
|||
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: 0 |
|||
wrapV: 0 |
|||
wrapW: 0 |
|||
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: |
撰写
预览
正在加载...
取消
保存
Reference in new issue