浏览代码

Merge pull request #22 from Unity-Technologies/fix_label_id_report

Fix label id report
/main
GitHub 4 年前
当前提交
cd74fd9b
共有 3 个文件被更改,包括 19 次插入17 次删除
  1. 20
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  2. 12
      com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs
  3. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs

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


for (var i = 0; i < renderedObjectInfos.Length; i++)
{
var objectInfo = renderedObjectInfos[i];
if (!TryGetLabelIdFromInstanceId(objectInfo.instanceId, out var labelId))
if (!TryGetLabelEntryFromInstanceId(objectInfo.instanceId, out var labelEntry))
label_id = labelId,
label_id = labelEntry.id,
instance_id = objectInfo.instanceId,
visible_pixels = objectInfo.pixelCount
};

for (var i = 0; i < renderedObjectInfos.Length; i++)
{
var objectInfo = renderedObjectInfos[i];
if (!TryGetLabelIdFromInstanceId(objectInfo.instanceId, out var labelId))
if (!TryGetLabelEntryFromInstanceId(objectInfo.instanceId, out var labelEntry))
label_id = labelId,
label_name = labelingConfigurations[labelId].label,
label_id = labelEntry.id,
label_name = labelEntry.label,
instance_id = objectInfo.instanceId,
x = objectInfo.boundingBox.x,
y = objectInfo.boundingBox.y,

/// Returns the class ID for the given instance ID resolved by <see cref="LabelingConfiguration"/>. Only valid when bounding boxes are being computed.
/// </summary>
/// <param name="instanceId">The instanceId of the object</param>
/// <param name="labelId">When this method returns, contains the labelId associated with the given instanceId, if one exists. -1 otherwise.</param>
/// <returns>True if a valid labelId was found for the given instanceId.</returns>
/// <param name="labelEntry">When this method returns, contains the LabelEntry associated with the given instanceId if one exists. default otherwise.</param>
/// <returns>True if a valid LabelEntry was found for the given instanceId.</returns>
public bool TryGetLabelIdFromInstanceId(int instanceId, out int labelId)
public bool TryGetLabelEntryFromInstanceId(int instanceId, out LabelEntry labelEntry)
throw new InvalidOperationException($"{nameof(TryGetLabelIdFromInstanceId)} can only be used when bounding box capture is enabled");
return m_RenderedObjectInfoGenerator.TryGetLabelIdFromInstanceId(instanceId, out labelId);
throw new InvalidOperationException($"{nameof(TryGetLabelEntryFromInstanceId)} can only be used when bounding box capture is enabled");
return m_RenderedObjectInfoGenerator.TryGetLabelEntryFromInstanceId(instanceId, out labelEntry);
}
void OnObjectCountsReceived(NativeSlice<uint> counts, IReadOnlyList<LabelEntry> entries, int frameCount)

12
com.unity.perception/Runtime/GroundTruth/RenderedObjectInfoGenerator.cs


using Unity.Jobs;
using Unity.Mathematics;
using Unity.Profiling;
using UnityEngine.UIElements;
namespace UnityEngine.Perception.GroundTruth
{

/// <inheritdoc/>
public void SetupMaterialProperties(MaterialPropertyBlock mpb, MeshRenderer meshRenderer, Labeling labeling, uint instanceId)
{
if (m_LabelingConfiguration.TryGetMatchingConfigurationEntry(labeling, out var entry, out var index))
if (m_LabelingConfiguration.TryGetMatchingConfigurationEntry(labeling, out _, out var index))
{
if (m_InstanceIdToLabelEntryIndexLookup.Length <= instanceId)
{

/// Attempts to find the label id for the given instance id using the LabelingConfiguration passed into the constructor.
/// </summary>
/// <param name="instanceId">The instanceId of the object for which the labelId should be found</param>
/// <param name="labelId">The labelId of the object. -1 if not found</param>
/// <param name="labelEntry">The LabelEntry associated with the object. default if not found</param>
public bool TryGetLabelIdFromInstanceId(int instanceId, out int labelId)
public bool TryGetLabelEntryFromInstanceId(int instanceId, out LabelEntry labelEntry)
labelId = -1;
labelEntry = default;
labelId = m_InstanceIdToLabelEntryIndexLookup[instanceId];
var labelEntryIndex = m_InstanceIdToLabelEntryIndexLookup[instanceId];
labelEntry = m_LabelingConfiguration.LabelEntries[labelEntryIndex];
return true;
}

4
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


yield return null;
var jsonExpected = $@" {{
""label_id"": 0,
""label_id"": 100,
""label_name"": ""label"",
""instance_id"": 1,
""x"": 0.0,

{
new LabelEntry
{
id = 1,
id = 100,
label = label,
value = 500
}

正在加载...
取消
保存