Steve Borkman
4 年前
当前提交
5ce0670f
共有 13 个文件被更改,包括 319 次插入 和 34 次删除
-
14com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
-
5com.unity.perception/Runtime/GroundTruth/DatasetCapture.cs
-
36com.unity.perception/Runtime/GroundTruth/Exporters/Coco/CocoExporter.cs
-
6com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
-
8com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
-
2com.unity.perception/Runtime/GroundTruth/Labeling/IdLabelConfig.cs
-
18com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
-
99com.unity.perception/Runtime/GroundTruth/SimulationState.cs
-
5com.unity.perception/Runtime/GroundTruth/SimulationState_Json.cs
-
8com.unity.perception/Runtime/GroundTruth/Exporters/PerceptionFormat.meta
-
141com.unity.perception/Runtime/GroundTruth/Exporters/PerceptionFormat/PerceptionExporter.cs
-
11com.unity.perception/Runtime/GroundTruth/Exporters/PerceptionFormat/PerceptionExporter.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: a40dd8c5379f64748a0942b0475badc6 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Newtonsoft.Json; |
|||
using Newtonsoft.Json.Linq; |
|||
using Unity.Simulation; |
|||
|
|||
namespace UnityEngine.Perception.GroundTruth.Exporters.PerceptionFormat |
|||
{ |
|||
public class PerceptionExporter : IDatasetReporter |
|||
{ |
|||
const Formatting k_Formatting = Formatting.Indented; |
|||
string outputDirectory = string.Empty; |
|||
int captureFileIndex = 0; |
|||
|
|||
public void OnSimulationBegin(string directoryName) |
|||
{ |
|||
outputDirectory = directoryName; |
|||
} |
|||
|
|||
public void OnSimulationEnd() |
|||
{ |
|||
// do nothing :-)
|
|||
} |
|||
|
|||
public void OnAnnotationRegistered<TSpec>(Guid annotationId, TSpec[] values) |
|||
{ |
|||
// do nothing :-)
|
|||
} |
|||
|
|||
void WriteJObjectToFile(JObject jObject, string filename) |
|||
{ |
|||
var stringWriter = new StringWriter(new StringBuilder(256), CultureInfo.InvariantCulture); |
|||
using (var jsonTextWriter = new JsonTextWriter(stringWriter)) |
|||
{ |
|||
jsonTextWriter.Formatting = k_Formatting; |
|||
jObject.WriteTo(jsonTextWriter); |
|||
} |
|||
|
|||
var contents = stringWriter.ToString(); |
|||
|
|||
var path = Path.Combine(outputDirectory, filename); |
|||
File.WriteAllText(path, contents); |
|||
|
|||
// TODO what to do about this...
|
|||
Manager.Instance.ConsumerFileProduced(path); |
|||
} |
|||
|
|||
public Task ProcessPendingCaptures(List<SimulationState.PendingCapture> pendingCaptures, SimulationState simState) |
|||
{ |
|||
//lazily allocate for fast zero-write frames
|
|||
var capturesJArray = new JArray(); |
|||
|
|||
foreach (var pendingCapture in pendingCaptures) |
|||
capturesJArray.Add(JObjectFromPendingCapture(pendingCapture)); |
|||
|
|||
var capturesJObject = new JObject(); |
|||
capturesJObject.Add("version", DatasetCapture.SchemaVersion); |
|||
capturesJObject.Add("captures", capturesJArray); |
|||
|
|||
WriteJObjectToFile(capturesJObject, $"captures_{captureFileIndex:000}.json"); |
|||
|
|||
// TODO what to do about this...
|
|||
return null; |
|||
} |
|||
|
|||
public Task OnCaptureReported(int frame, int width, int height, string filename) |
|||
{ |
|||
// do nothing :-)
|
|||
return null; |
|||
} |
|||
|
|||
static JToken JObjectFromPendingCapture(SimulationState.PendingCapture pendingCapture) |
|||
{ |
|||
var sensorJObject = new JObject();//new SensorCaptureJson
|
|||
sensorJObject["sensor_id"] = pendingCapture.SensorHandle.Id.ToString(); |
|||
sensorJObject["ego_id"] = pendingCapture.SensorData.egoHandle.Id.ToString(); |
|||
sensorJObject["modality"] = pendingCapture.SensorData.modality; |
|||
sensorJObject["translation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.SensorPose.position); |
|||
sensorJObject["rotation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.SensorPose.rotation); |
|||
|
|||
if (pendingCapture.AdditionalSensorValues != null) |
|||
{ |
|||
foreach (var(name, value) in pendingCapture.AdditionalSensorValues) |
|||
sensorJObject.Add(name, DatasetJsonUtility.ToJToken(value)); |
|||
} |
|||
|
|||
var egoCaptureJson = new JObject(); |
|||
egoCaptureJson["ego_id"] = pendingCapture.SensorData.egoHandle.Id.ToString(); |
|||
egoCaptureJson["translation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoPose.position); |
|||
egoCaptureJson["rotation"] = DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoPose.rotation); |
|||
egoCaptureJson["velocity"] = pendingCapture.SensorSpatialData.EgoVelocity.HasValue ? DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoVelocity.Value) : null; |
|||
egoCaptureJson["acceleration"] = pendingCapture.SensorSpatialData.EgoAcceleration.HasValue ? DatasetJsonUtility.ToJToken(pendingCapture.SensorSpatialData.EgoAcceleration.Value) : null; |
|||
|
|||
var capture = new JObject(); |
|||
capture["id"] = pendingCapture.Id.ToString(); |
|||
capture["sequence_id"] = pendingCapture.SequenceId.ToString(); |
|||
capture["step"] = pendingCapture.Step; |
|||
capture["timestamp"] = pendingCapture.Timestamp; |
|||
capture["sensor"] = sensorJObject; |
|||
capture["ego"] = egoCaptureJson; |
|||
capture["filename"] = pendingCapture.Path; |
|||
capture["format"] = GetFormatFromFilename(pendingCapture.Path); |
|||
|
|||
if (pendingCapture.Annotations.Any()) |
|||
capture["annotations"] = new JArray(pendingCapture.Annotations.Select(JObjectFromAnnotation).ToArray()); |
|||
|
|||
return capture; |
|||
} |
|||
|
|||
static JObject JObjectFromAnnotation((Annotation, SimulationState.AnnotationData) annotationInfo) |
|||
{ |
|||
var annotationJObject = new JObject(); |
|||
annotationJObject["id"] = annotationInfo.Item1.Id.ToString(); |
|||
annotationJObject["annotation_definition"] = annotationInfo.Item2.AnnotationDefinition.Id.ToString(); |
|||
if (annotationInfo.Item2.Path != null) |
|||
annotationJObject["filename"] = annotationInfo.Item2.Path; |
|||
|
|||
if (annotationInfo.Item2.ValuesJson != null) |
|||
annotationJObject["values"] = annotationInfo.Item2.ValuesJson; |
|||
|
|||
return annotationJObject; |
|||
} |
|||
|
|||
static string GetFormatFromFilename(string filename) |
|||
{ |
|||
var ext = Path.GetExtension(filename); |
|||
if (ext == null) |
|||
return null; |
|||
|
|||
if (ext.StartsWith(".")) |
|||
ext = ext.Substring(1); |
|||
|
|||
return ext.ToUpperInvariant(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c38f43837b9cf984f92853858398e0b4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue