From 13c2a38e129b1d0de59867ee57f65920fdee8f30 Mon Sep 17 00:00:00 2001 From: Junrou Nishida Date: Wed, 9 Mar 2022 17:10:17 +0900 Subject: [PATCH] feat(sample): implement MIN_(DETECTION|TRACKING)_CONFIDENCE (#483) * feat: port TensorsToDetectionsCalculatorOptions * feat: Parse CalculatorGraphConfig with Extensions * feat(sample): FaceDetectionConfig#MIN_DETECTION_CONFIDENCE * fix: uninstall proto.cs * feat: port ThresholdingCalculatorOptions * remove import_prefix * fix compilation errors * feat(sample): MIN_DETECTION_CONFIDENCE /MIN_TRACKING_CONFIDENCE --- .../Scripts/ImageSource/TextureFrame.cs | 4 ++ .../Face Detection/FaceDetectionGraph.cs | 34 +++++++++++- .../Samples/Scenes/Face Mesh/FaceMeshGraph.cs | 51 ++++++++++++++++- .../Scenes/Hand Tracking/HandTrackingGraph.cs | 50 ++++++++++++++++- .../Scenes/Holistic/HolisticTrackingGraph.cs | 55 ++++++++++++++++++- .../Scenes/Objectron/ObjectronGraph.cs | 51 ++++++++++++++++- .../Scenes/Pose Tracking/PoseTrackingGraph.cs | 52 +++++++++++++++++- .../Mediapipe/Samples/UI/Scripts/LogLine.cs | 4 ++ .../Samples/UI/Scripts/SolutionMenu.cs | 4 ++ .../Scripts/Framework/ValidatedGraphConfig.cs | 5 +- .../Runtime/Scripts/Protobuf/Calculators.meta | 8 +++ .../Scripts/Protobuf/Calculators/Tensor.meta | 8 +++ .../TensorsToDetectionsCalculator.cs.meta | 11 ++++ .../Scripts/Protobuf/Calculators/Util.meta | 8 +++ .../Util/ThresholdingCalculator.cs.meta | 11 ++++ .../Runtime/Scripts/Protobuf/Util.meta | 8 +++ .../Scripts/Protobuf/Util/Color.cs.meta | 11 ++++ .../Scripts/Protobuf/Util/RenderData.cs.meta | 11 ++++ .../Runtime/Scripts/Unity/Annotation/Arrow.cs | 4 ++ .../Unity/Annotation/CircleAnnotation.cs | 4 ++ .../Annotation/ConnectionListAnnotation.cs | 4 ++ .../Unity/Annotation/CuboidAnnotation.cs | 4 ++ .../Unity/Annotation/CuboidListAnnotation.cs | 4 ++ .../Unity/Annotation/DetectionAnnotation.cs | 4 ++ .../Annotation/DetectionListAnnotation.cs | 4 ++ .../Annotation/FaceLandmarkListAnnotation.cs | 4 ++ .../FaceLandmarkListWithIrisAnnotation.cs | 4 ++ .../Annotation/HandLandmarkListAnnotation.cs | 4 ++ .../Annotation/IrisLandmarkListAnnotation.cs | 4 ++ .../Unity/Annotation/LabelAnnotation.cs | 4 ++ .../Unity/Annotation/LineAnnotation.cs | 4 ++ .../Unity/Annotation/MaskAnnotation.cs | 4 ++ .../MultiFaceLandmarkListAnnotation.cs | 4 ++ .../MultiHandLandmarkListAnnotation.cs | 4 ++ .../Unity/Annotation/PointAnnotation.cs | 4 ++ .../Unity/Annotation/PointListAnnotation.cs | 4 ++ .../Annotation/PoseLandmarkListAnnotation.cs | 4 ++ .../Unity/Annotation/RectangleAnnotation.cs | 4 ++ .../Annotation/RectangleListAnnotation.cs | 4 ++ build.py | 2 +- mediapipe_api/BUILD | 3 + mediapipe_api/calculators/tensor/BUILD | 29 ++++++++++ mediapipe_api/calculators/util/BUILD | 30 ++++++++++ mediapipe_api/csharp_proto_src.bzl | 9 +-- mediapipe_api/framework/BUILD | 10 ++-- mediapipe_api/framework/formats/BUILD | 1 - .../instant_motion_tracking/calculators/BUILD | 1 - .../object_detection_3d/calculators/BUILD | 1 - mediapipe_api/util/BUILD | 33 ++++++++++- third_party/mediapipe_visibility.diff | 54 ++++++++++++++++-- 50 files changed, 612 insertions(+), 31 deletions(-) create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor/TensorsToDetectionsCalculator.cs.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util/ThresholdingCalculator.cs.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/Color.cs.meta create mode 100644 Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/RenderData.cs.meta create mode 100644 mediapipe_api/calculators/tensor/BUILD create mode 100644 mediapipe_api/calculators/util/BUILD diff --git a/Assets/Mediapipe/Samples/Common/Scripts/ImageSource/TextureFrame.cs b/Assets/Mediapipe/Samples/Common/Scripts/ImageSource/TextureFrame.cs index aeaa0d9dd..b6eb03945 100644 --- a/Assets/Mediapipe/Samples/Common/Scripts/ImageSource/TextureFrame.cs +++ b/Assets/Mediapipe/Samples/Common/Scripts/ImageSource/TextureFrame.cs @@ -14,6 +14,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class TextureFrame { public class ReleaseEvent : UnityEvent { } diff --git a/Assets/Mediapipe/Samples/Scenes/Face Detection/FaceDetectionGraph.cs b/Assets/Mediapipe/Samples/Scenes/Face Detection/FaceDetectionGraph.cs index c67cfc115..4c127e348 100644 --- a/Assets/Mediapipe/Samples/Scenes/Face Detection/FaceDetectionGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Face Detection/FaceDetectionGraph.cs @@ -6,8 +6,12 @@ using System; using System.Collections.Generic; +using System.Linq; +using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.FaceDetection { public class FaceDetectionGraph : GraphRunner @@ -18,6 +22,14 @@ public enum ModelType FullRangeSparse = 1, } public ModelType modelType = ModelType.ShortRange; + + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + #pragma warning disable IDE1006 public UnityEvent> OnFaceDetectionsOutput = new UnityEvent>(); #pragma warning restore IDE1006 @@ -94,7 +106,27 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) { _faceDetectionsStream = new OutputStream>(calculatorGraph, _FaceDetectionsStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "TensorsToDetectionsCalculator").ToList(); + + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } private SidePacket BuildSidePacket(ImageSource imageSource) diff --git a/Assets/Mediapipe/Samples/Scenes/Face Mesh/FaceMeshGraph.cs b/Assets/Mediapipe/Samples/Scenes/Face Mesh/FaceMeshGraph.cs index 6df967509..a29e6359d 100644 --- a/Assets/Mediapipe/Samples/Scenes/Face Mesh/FaceMeshGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Face Mesh/FaceMeshGraph.cs @@ -6,14 +6,33 @@ using System; using System.Collections.Generic; +using System.Linq; +using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.FaceMesh { public class FaceMeshGraph : GraphRunner { public int maxNumFaces = 1; public bool refineLandmarks = true; + + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + + private float _minTrackingConfidence = 0.5f; + public float minTrackingConfidence + { + get => _minTrackingConfidence; + set => _minTrackingConfidence = Mathf.Clamp01(value); + } + #pragma warning disable IDE1006 // UnityEvent is PascalCase public UnityEvent> OnFaceDetectionsOutput = new UnityEvent>(); public UnityEvent> OnMultiFaceLandmarksOutput = new UnityEvent>(); @@ -163,7 +182,37 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) _faceRectsFromLandmarksStream = new OutputStream>(calculatorGraph, _FaceRectsFromLandmarksStreamName, true); _faceRectsFromDetectionsStream = new OutputStream>(calculatorGraph, _FaceRectsFromDetectionsStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext, ThresholdingCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "TensorsToDetectionsCalculator").ToList(); + var thresholdingCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "ThresholdingCalculator").ToList(); + + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + + foreach (var calculator in thresholdingCalculators) + { + if (calculator.Options.HasExtension(ThresholdingCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(ThresholdingCalculatorOptions.Extensions.Ext); + options.Threshold = minTrackingConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } protected override IList RequestDependentAssets() diff --git a/Assets/Mediapipe/Samples/Scenes/Hand Tracking/HandTrackingGraph.cs b/Assets/Mediapipe/Samples/Scenes/Hand Tracking/HandTrackingGraph.cs index 46c3aa8a4..2a8c51cde 100644 --- a/Assets/Mediapipe/Samples/Scenes/Hand Tracking/HandTrackingGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Hand Tracking/HandTrackingGraph.cs @@ -6,8 +6,12 @@ using System; using System.Collections.Generic; +using System.Linq; +using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.HandTracking { public class HandTrackingGraph : GraphRunner @@ -21,6 +25,20 @@ public enum ModelComplexity public ModelComplexity modelComplexity = ModelComplexity.Full; public int maxNumHands = 2; + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + + private float _minTrackingConfidence = 0.5f; + public float minTrackingConfidence + { + get => _minTrackingConfidence; + set => _minTrackingConfidence = Mathf.Clamp01(value); + } + #pragma warning disable IDE1006 // UnityEvent is PascalCase public UnityEvent> OnPalmDetectectionsOutput = new UnityEvent>(); public UnityEvent> OnHandRectsFromPalmDetectionsOutput = new UnityEvent>(); @@ -231,7 +249,37 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) _handRectsFromLandmarksStream = new OutputStream>(calculatorGraph, _HandRectsFromLandmarksStreamName, true); _handednessStream = new OutputStream>(calculatorGraph, _HandednessStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext, ThresholdingCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "TensorsToDetectionsCalculator").ToList(); + var thresholdingCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "ThresholdingCalculator").ToList(); + + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + + foreach (var calculator in thresholdingCalculators) + { + if (calculator.Options.HasExtension(ThresholdingCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(ThresholdingCalculatorOptions.Extensions.Ext); + options.Threshold = minTrackingConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } private WaitForResult WaitForHandLandmarkModel() diff --git a/Assets/Mediapipe/Samples/Scenes/Holistic/HolisticTrackingGraph.cs b/Assets/Mediapipe/Samples/Scenes/Holistic/HolisticTrackingGraph.cs index 85d24ae50..e6887cf89 100644 --- a/Assets/Mediapipe/Samples/Scenes/Holistic/HolisticTrackingGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Holistic/HolisticTrackingGraph.cs @@ -6,8 +6,13 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.Holistic { public class HolisticTrackingGraph : GraphRunner @@ -23,6 +28,20 @@ public enum ModelComplexity public ModelComplexity modelComplexity = ModelComplexity.Lite; public bool smoothLandmarks = true; + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + + private float _minTrackingConfidence = 0.5f; + public float minTrackingConfidence + { + get => _minTrackingConfidence; + set => _minTrackingConfidence = Mathf.Clamp01(value); + } + #pragma warning disable IDE1006 // UnityEvent is PascalCase public UnityEvent OnPoseDetectionOutput = new UnityEvent(); public UnityEvent OnPoseLandmarksOutput = new UnityEvent(); @@ -275,7 +294,41 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) _poseWorldLandmarksStream = new OutputStream(calculatorGraph, _PoseWorldLandmarksStreamName, true); _poseRoiStream = new OutputStream(calculatorGraph, _PoseRoiStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext, ThresholdingCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + + var poseDetectionCalculatorPattern = new Regex("__posedetection[a-z]+__TensorsToDetectionsCalculator$"); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => poseDetectionCalculatorPattern.Match(node.Name).Success).ToList(); + + var poseTrackingCalculatorPattern = new Regex("tensorstoposelandmarksandsegmentation__ThresholdingCalculator$"); + var thresholdingCalculators = cannonicalizedConfig.Node.Where((node) => poseTrackingCalculatorPattern.Match(node.Name).Success).ToList(); + + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + + foreach (var calculator in thresholdingCalculators) + { + if (calculator.Options.HasExtension(ThresholdingCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(ThresholdingCalculatorOptions.Extensions.Ext); + options.Threshold = minTrackingConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } private SidePacket BuildSidePacket(ImageSource imageSource) diff --git a/Assets/Mediapipe/Samples/Scenes/Objectron/ObjectronGraph.cs b/Assets/Mediapipe/Samples/Scenes/Objectron/ObjectronGraph.cs index 48663291c..c4c74c9af 100644 --- a/Assets/Mediapipe/Samples/Scenes/Objectron/ObjectronGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Objectron/ObjectronGraph.cs @@ -6,9 +6,12 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.Objectron { public class ObjectronGraph : GraphRunner @@ -25,6 +28,20 @@ public enum Category public Category category; public int maxNumObjects = 5; + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + + private float _minTrackingConfidence = 0.99f; + public float minTrackingConfidence + { + get => _minTrackingConfidence; + set => _minTrackingConfidence = Mathf.Clamp01(value); + } + public Vector2 focalLength { get @@ -174,7 +191,39 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) _multiBoxRectsStream = new OutputStream>(calculatorGraph, _MultiBoxRectsStreamName, true); _multiBoxLandmarksStream = new OutputStream>(calculatorGraph, _MultiBoxLandmarksStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext, ThresholdingCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "TensorsToDetectionsCalculator").ToList(); + var thresholdingCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "ThresholdingCalculator").ToList(); + + Debug.Log(tensorsToDetectionsCalculators.Count); + Debug.Log(thresholdingCalculators.Count); + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + + foreach (var calculator in thresholdingCalculators) + { + if (calculator.Options.HasExtension(ThresholdingCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(ThresholdingCalculatorOptions.Extensions.Ext); + options.Threshold = minTrackingConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } private SidePacket BuildSidePacket(ImageSource imageSource) diff --git a/Assets/Mediapipe/Samples/Scenes/Pose Tracking/PoseTrackingGraph.cs b/Assets/Mediapipe/Samples/Scenes/Pose Tracking/PoseTrackingGraph.cs index 610c82afa..d65d06f34 100644 --- a/Assets/Mediapipe/Samples/Scenes/Pose Tracking/PoseTrackingGraph.cs +++ b/Assets/Mediapipe/Samples/Scenes/Pose Tracking/PoseTrackingGraph.cs @@ -6,8 +6,12 @@ using System; using System.Collections.Generic; +using System.Linq; +using UnityEngine; using UnityEngine.Events; +using Google.Protobuf; + namespace Mediapipe.Unity.PoseTracking { public class PoseTrackingGraph : GraphRunner @@ -22,6 +26,20 @@ public enum ModelComplexity public ModelComplexity modelComplexity = ModelComplexity.Full; public bool smoothLandmarks = true; + private float _minDetectionConfidence = 0.5f; + public float minDetectionConfidence + { + get => _minDetectionConfidence; + set => _minDetectionConfidence = Mathf.Clamp01(value); + } + + private float _minTrackingConfidence = 0.5f; + public float minTrackingConfidence + { + get => _minTrackingConfidence; + set => _minTrackingConfidence = Mathf.Clamp01(value); + } + #pragma warning disable IDE1006 // UnityEvent is PascalCase public UnityEvent OnPoseDetectionOutput = new UnityEvent(); public UnityEvent OnPoseLandmarksOutput = new UnityEvent(); @@ -177,7 +195,39 @@ protected override Status ConfigureCalculatorGraph(CalculatorGraphConfig config) _poseWorldLandmarksStream = new OutputStream(calculatorGraph, _PoseWorldLandmarksStreamName, true); _roiFromLandmarksStream = new OutputStream(calculatorGraph, _RoiFromLandmarksStreamName, true); } - return calculatorGraph.Initialize(config); + + using (var validatedGraphConfig = new ValidatedGraphConfig()) + { + var status = validatedGraphConfig.Initialize(config); + + if (!status.Ok()) { return status; } + + var extensionRegistry = new ExtensionRegistry() { TensorsToDetectionsCalculatorOptions.Extensions.Ext, ThresholdingCalculatorOptions.Extensions.Ext }; + var cannonicalizedConfig = validatedGraphConfig.Config(extensionRegistry); + var tensorsToDetectionsCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "TensorsToDetectionsCalculator").ToList(); + var thresholdingCalculators = cannonicalizedConfig.Node.Where((node) => node.Calculator == "ThresholdingCalculator").ToList(); + + Debug.Log(tensorsToDetectionsCalculators.Count); + Debug.Log(thresholdingCalculators.Count); + foreach (var calculator in tensorsToDetectionsCalculators) + { + if (calculator.Options.HasExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(TensorsToDetectionsCalculatorOptions.Extensions.Ext); + options.MinScoreThresh = minDetectionConfidence; + } + } + + foreach (var calculator in thresholdingCalculators) + { + if (calculator.Options.HasExtension(ThresholdingCalculatorOptions.Extensions.Ext)) + { + var options = calculator.Options.GetExtension(ThresholdingCalculatorOptions.Extensions.Ext); + options.Threshold = minTrackingConfidence; + } + } + return calculatorGraph.Initialize(cannonicalizedConfig); + } } private WaitForResult WaitForPoseLandmarkModel() diff --git a/Assets/Mediapipe/Samples/UI/Scripts/LogLine.cs b/Assets/Mediapipe/Samples/UI/Scripts/LogLine.cs index 9dbe6d44c..07f71e888 100644 --- a/Assets/Mediapipe/Samples/UI/Scripts/LogLine.cs +++ b/Assets/Mediapipe/Samples/UI/Scripts/LogLine.cs @@ -10,6 +10,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class LogLine : MonoBehaviour { [SerializeField] private Text _utcTimeArea; diff --git a/Assets/Mediapipe/Samples/UI/Scripts/SolutionMenu.cs b/Assets/Mediapipe/Samples/UI/Scripts/SolutionMenu.cs index 97911d6c7..46c01029e 100644 --- a/Assets/Mediapipe/Samples/UI/Scripts/SolutionMenu.cs +++ b/Assets/Mediapipe/Samples/UI/Scripts/SolutionMenu.cs @@ -12,6 +12,10 @@ namespace Mediapipe.Unity.UI { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class SolutionMenu : ModalContents { [SerializeField] private GameObject _solutionRowPrefab; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/ValidatedGraphConfig.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/ValidatedGraphConfig.cs index afdad92d8..25ced10ef 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/ValidatedGraphConfig.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/ValidatedGraphConfig.cs @@ -135,12 +135,13 @@ public Status ValidateRequiredSidePackets(SidePacket sidePacket) return new Status(statusPtr); } - public CalculatorGraphConfig Config() + public CalculatorGraphConfig Config(ExtensionRegistry extensionRegistry = null) { UnsafeNativeMethods.mp_ValidatedGraphConfig__Config(mpPtr, out var serializedProto).Assert(); GC.KeepAlive(this); - var config = serializedProto.Deserialize(CalculatorGraphConfig.Parser); + var parser = extensionRegistry == null ? CalculatorGraphConfig.Parser : CalculatorGraphConfig.Parser.WithExtensionRegistry(extensionRegistry); + var config = serializedProto.Deserialize(parser); serializedProto.Dispose(); return config; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators.meta new file mode 100644 index 000000000..db2b2f5f0 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eaf1a96d5b34138ccace8daecccd0520 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor.meta new file mode 100644 index 000000000..36132d668 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: aa3bc66960753a948bf57e2986ff316a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor/TensorsToDetectionsCalculator.cs.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor/TensorsToDetectionsCalculator.cs.meta new file mode 100644 index 000000000..52f9728f5 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Tensor/TensorsToDetectionsCalculator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b0f773471b719b5f803cac686ec7653 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util.meta new file mode 100644 index 000000000..8dc3ab569 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d691b2ca837664112adbffece01bb6f7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util/ThresholdingCalculator.cs.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util/ThresholdingCalculator.cs.meta new file mode 100644 index 000000000..8ddfad1ff --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Calculators/Util/ThresholdingCalculator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 81f3d9cc258eeb1d1b47c50df48d5cf6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util.meta new file mode 100644 index 000000000..3e79cb4f7 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ca02a698e823ece56862f80d08c631ba +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/Color.cs.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/Color.cs.meta new file mode 100644 index 000000000..ad1a7b6bb --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/Color.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12843ade4075fb5949f3170be8f1601f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/RenderData.cs.meta b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/RenderData.cs.meta new file mode 100644 index 000000000..cdeb18719 --- /dev/null +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Protobuf/Util/RenderData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6475269ad8c98711994a2d30d2e61e4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/Arrow.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/Arrow.cs index 778f5a54f..f0e2baa85 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/Arrow.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/Arrow.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class Arrow : MonoBehaviour { [SerializeField] private Color _color = Color.white; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CircleAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CircleAnnotation.cs index cdd63388a..923456e10 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CircleAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CircleAnnotation.cs @@ -8,6 +8,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class CircleAnnotation : HierarchicalAnnotation { [SerializeField] private LineRenderer _lineRenderer; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/ConnectionListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/ConnectionListAnnotation.cs index 94f2a384e..8d1f76a9a 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/ConnectionListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/ConnectionListAnnotation.cs @@ -10,6 +10,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class ConnectionListAnnotation : ListAnnotation { [SerializeField] private Color _color = Color.red; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidAnnotation.cs index 42dd49e69..2bf62523e 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class CuboidAnnotation : HierarchicalAnnotation { [SerializeField] private PointListAnnotation _pointListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidListAnnotation.cs index 492478895..b3cffaf5a 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/CuboidListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class CuboidListAnnotation : ListAnnotation { [SerializeField] private Color _pointColor = Color.green; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionAnnotation.cs index bea18e348..88e94a466 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class DetectionAnnotation : HierarchicalAnnotation { [SerializeField] private RectangleAnnotation _locationDataAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionListAnnotation.cs index e2b11635b..5721112ee 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/DetectionListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class DetectionListAnnotation : ListAnnotation { [SerializeField, Range(0, 1)] private float _lineWidth = 1.0f; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListAnnotation.cs index 15d462475..fa4767e0e 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class FaceLandmarkListAnnotation : HierarchicalAnnotation { [SerializeField] private PointListAnnotation _landmarkListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListWithIrisAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListWithIrisAnnotation.cs index 0a63ca3d7..8edadd4cd 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListWithIrisAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/FaceLandmarkListWithIrisAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class FaceLandmarkListWithIrisAnnotation : HierarchicalAnnotation { [SerializeField] private FaceLandmarkListAnnotation _faceLandmarkListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/HandLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/HandLandmarkListAnnotation.cs index 4800f7088..5145a39c5 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/HandLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/HandLandmarkListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class HandLandmarkListAnnotation : HierarchicalAnnotation { [SerializeField] private PointListAnnotation _landmarkListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/IrisLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/IrisLandmarkListAnnotation.cs index 404e16062..9e516c1a0 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/IrisLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/IrisLandmarkListAnnotation.cs @@ -10,6 +10,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class IrisLandmarkListAnnotation : HierarchicalAnnotation { [SerializeField] private PointListAnnotation _landmarkListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LabelAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LabelAnnotation.cs index 7ff8ccf1d..735362ce1 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LabelAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LabelAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class LabelAnnotation : HierarchicalAnnotation { [SerializeField] private Text _labelText; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LineAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LineAnnotation.cs index 1eb4a1174..a8eca7ddb 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LineAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/LineAnnotation.cs @@ -8,6 +8,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class LineAnnotation : HierarchicalAnnotation { [SerializeField] private LineRenderer _lineRenderer; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MaskAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MaskAnnotation.cs index b32b1c9e0..7baa15b32 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MaskAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MaskAnnotation.cs @@ -11,6 +11,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class MaskAnnotation : HierarchicalAnnotation { [SerializeField] private RawImage _screen; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiFaceLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiFaceLandmarkListAnnotation.cs index bbc532a89..0d7f0a579 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiFaceLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiFaceLandmarkListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class MultiFaceLandmarkListAnnotation : ListAnnotation { [SerializeField] private Color _faceLandmarkColor = Color.green; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiHandLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiHandLandmarkListAnnotation.cs index 55f20f198..749d73eed 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiHandLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/MultiHandLandmarkListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class MultiHandLandmarkListAnnotation : ListAnnotation { [SerializeField] private Color _leftLandmarkColor = Color.green; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointAnnotation.cs index 73a44a2ab..e416d887d 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointAnnotation.cs @@ -11,6 +11,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class PointAnnotation : HierarchicalAnnotation { [SerializeField] private Color _color = Color.green; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointListAnnotation.cs index 80ab433d0..848ba2a8c 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PointListAnnotation.cs @@ -11,6 +11,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class PointListAnnotation : ListAnnotation { [SerializeField] private Color _color = Color.green; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PoseLandmarkListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PoseLandmarkListAnnotation.cs index fb177508c..7e82cac64 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PoseLandmarkListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/PoseLandmarkListAnnotation.cs @@ -10,6 +10,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public sealed class PoseLandmarkListAnnotation : HierarchicalAnnotation { [SerializeField] private PointListAnnotation _landmarkListAnnotation; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleAnnotation.cs index 6a69283d7..c2f7fab0e 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleAnnotation.cs @@ -11,6 +11,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class RectangleAnnotation : HierarchicalAnnotation { [SerializeField] private LineRenderer _lineRenderer; diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleListAnnotation.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleListAnnotation.cs index 72866e0a7..33a23a174 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleListAnnotation.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Annotation/RectangleListAnnotation.cs @@ -9,6 +9,10 @@ namespace Mediapipe.Unity { +#pragma warning disable IDE0065 + using Color = UnityEngine.Color; +#pragma warning restore IDE0065 + public class RectangleListAnnotation : ListAnnotation { [SerializeField] private Color _color = Color.red; diff --git a/build.py b/build.py index 258f128c8..8d4521e5f 100644 --- a/build.py +++ b/build.py @@ -381,7 +381,7 @@ def run(self): for f in glob.glob(os.path.join(_INSTALL_PATH, 'Plugins', 'Protobuf', '*.dll'), recursive=True): self._remove(f) - for f in glob.glob(os.path.join(_INSTALL_PATH, 'Scripts', 'Protobuf', '*.cs'), recursive=True): + for f in glob.glob(os.path.join(_INSTALL_PATH, 'Scripts', 'Protobuf', '**', '*.cs'), recursive=True): self._remove(f) if self.analyzers: diff --git a/mediapipe_api/BUILD b/mediapipe_api/BUILD index 611eb524b..104aec3ef 100644 --- a/mediapipe_api/BUILD +++ b/mediapipe_api/BUILD @@ -194,12 +194,15 @@ pkg_asset( pkg_zip( name = "mediapipe_proto_srcs", srcs = [ + "//mediapipe_api/calculators/tensor:proto_srcs", + "//mediapipe_api/calculators/util:proto_srcs", "//mediapipe_api/framework:proto_srcs", "//mediapipe_api/framework/formats:proto_srcs", "//mediapipe_api/graphs/instant_motion_tracking/calculators:proto_srcs", "//mediapipe_api/graphs/object_detection_3d/calculators:proto_srcs", "//mediapipe_api/modules/face_geometry/protos:proto_srcs", "//mediapipe_api/modules/objectron/calculators:proto_srcs", + "//mediapipe_api/util:proto_srcs", ], ) diff --git a/mediapipe_api/calculators/tensor/BUILD b/mediapipe_api/calculators/tensor/BUILD new file mode 100644 index 000000000..896df56e2 --- /dev/null +++ b/mediapipe_api/calculators/tensor/BUILD @@ -0,0 +1,29 @@ +# Copyright (c) 2021 homuler +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src") + +package( + default_visibility = ["//visibility:public"], +) + +pkg_files( + name = "proto_srcs", + srcs = [ + ":tensors_to_detections_calculator_cs", + ], + prefix = "Calculators/Tensor", +) + +csharp_proto_src( + name = "tensors_to_detections_calculator_cs", + proto_src = "mediapipe/calculators/tensor/tensors_to_detections_calculator.proto", + deps = [ + "@com_google_mediapipe//mediapipe/calculators/tensor:protos_src", + "@com_google_mediapipe//mediapipe/framework:protos_src", + ], +) diff --git a/mediapipe_api/calculators/util/BUILD b/mediapipe_api/calculators/util/BUILD new file mode 100644 index 000000000..51d7625d9 --- /dev/null +++ b/mediapipe_api/calculators/util/BUILD @@ -0,0 +1,30 @@ +# Copyright (c) 2021 homuler +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. + +load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src") + +package( + default_visibility = ["//visibility:public"], +) + +pkg_files( + name = "proto_srcs", + srcs = [ + ":thresholding_calculator_cs", + ], + prefix = "Calculators/Util", +) + +csharp_proto_src( + name = "thresholding_calculator_cs", + proto_src = "mediapipe/calculators/util/thresholding_calculator.proto", + deps = [ + "@com_google_mediapipe//mediapipe/calculators/util:protos_src", + "@com_google_mediapipe//mediapipe/framework:protos_src", + "@com_google_mediapipe//mediapipe/util:protos_src", + ], +) diff --git a/mediapipe_api/csharp_proto_src.bzl b/mediapipe_api/csharp_proto_src.bzl index ca49514cd..17e3cea80 100644 --- a/mediapipe_api/csharp_proto_src.bzl +++ b/mediapipe_api/csharp_proto_src.bzl @@ -9,23 +9,18 @@ Macro for generating C# source files corresponding to .proto files """ -def csharp_proto_src(name, proto_src, deps, import_prefix = ""): +def csharp_proto_src(name, proto_src, deps): """Generate C# source code for *.proto Args: name: target name deps: label list of dependent targets - import_prefix: Directory where the generated source code is placed proto_src: target .proto file path """ - # e.g. - # If import_prefix is "Annotation" and proto_src is "mediapipe/framework/formats/annotation/rasterization", then - # csharp_out -> Rasterization.cs - # outdir -> $GENDIR/Annotation base_name = proto_src.split("/")[-1] csharp_out = _camelize(base_name.split(".")[0]) + ".cs" - outdir = "$(GENDIR)" if len(import_prefix) == 0 else "$(GENDIR)/" + import_prefix + outdir = "$(GENDIR)" native.genrule( name = name, diff --git a/mediapipe_api/framework/BUILD b/mediapipe_api/framework/BUILD index 0a5c3dde8..516286db3 100644 --- a/mediapipe_api/framework/BUILD +++ b/mediapipe_api/framework/BUILD @@ -95,11 +95,11 @@ pkg_files( srcs = [ ":calculator_cs", ":calculator_options_cs", - "mediapipe_options_cs", - "packet_factory_cs", - "packet_generator_cs", - "status_handler_cs", - "stream_handler_cs", + ":mediapipe_options_cs", + ":packet_factory_cs", + ":packet_generator_cs", + ":status_handler_cs", + ":stream_handler_cs", ], prefix = "Framework", ) diff --git a/mediapipe_api/framework/formats/BUILD b/mediapipe_api/framework/formats/BUILD index fcf16e453..017030a86 100644 --- a/mediapipe_api/framework/formats/BUILD +++ b/mediapipe_api/framework/formats/BUILD @@ -143,7 +143,6 @@ csharp_proto_src( csharp_proto_src( name = "rasterization_cs", - import_prefix = "Annotation", proto_src = "mediapipe/framework/formats/annotation/rasterization.proto", deps = [ "@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src", diff --git a/mediapipe_api/graphs/instant_motion_tracking/calculators/BUILD b/mediapipe_api/graphs/instant_motion_tracking/calculators/BUILD index b088662c7..4e16b9279 100644 --- a/mediapipe_api/graphs/instant_motion_tracking/calculators/BUILD +++ b/mediapipe_api/graphs/instant_motion_tracking/calculators/BUILD @@ -34,7 +34,6 @@ pkg_files( csharp_proto_src( name = "sticker_buffer_cs", - import_prefix = "Graphs/InstantMotionTracking", proto_src = "mediapipe/graphs/instant_motion_tracking/calculators/sticker_buffer.proto", deps = [ "@com_google_mediapipe//mediapipe/graphs/instant_motion_tracking/calculators:protos_src", diff --git a/mediapipe_api/graphs/object_detection_3d/calculators/BUILD b/mediapipe_api/graphs/object_detection_3d/calculators/BUILD index 4a0fab795..a71e0392e 100644 --- a/mediapipe_api/graphs/object_detection_3d/calculators/BUILD +++ b/mediapipe_api/graphs/object_detection_3d/calculators/BUILD @@ -34,7 +34,6 @@ pkg_files( csharp_proto_src( name = "model_matrix_cs", - import_prefix = "Graphs/ObjectDetection3d", proto_src = "mediapipe/graphs/object_detection_3d/calculators/model_matrix.proto", deps = [ "@com_google_mediapipe//mediapipe/graphs/object_detection_3d/calculators:protos_src", diff --git a/mediapipe_api/util/BUILD b/mediapipe_api/util/BUILD index 2b0ca301c..4aafdb8de 100644 --- a/mediapipe_api/util/BUILD +++ b/mediapipe_api/util/BUILD @@ -4,11 +4,17 @@ # license that can be found in the LICENSE file or at # https://opensource.org/licenses/MIT. +load("@rules_pkg//pkg:mappings.bzl", "pkg_files") +load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src") + +package( + default_visibility = ["//visibility:public"], +) + cc_library( name = "resource_util", srcs = ["resource_util_custom.cc"], hdrs = ["resource_util_custom.h"], - visibility = ["//visibility:public"], deps = [ "//mediapipe_api:common", "@com_google_absl//absl/strings", @@ -18,3 +24,28 @@ cc_library( ], alwayslink = True, ) + +pkg_files( + name = "proto_srcs", + srcs = [ + ":color_cs", + ":render_data_cs", + ], + prefix = "Util", +) + +csharp_proto_src( + name = "color_cs", + proto_src = "mediapipe/util/color.proto", + deps = [ + "@com_google_mediapipe//mediapipe/util:protos_src", + ], +) + +csharp_proto_src( + name = "render_data_cs", + proto_src = "mediapipe/util/render_data.proto", + deps = [ + "@com_google_mediapipe//mediapipe/util:protos_src", + ], +) diff --git a/third_party/mediapipe_visibility.diff b/third_party/mediapipe_visibility.diff index 9bc61adfb..547ff5ac8 100644 --- a/third_party/mediapipe_visibility.diff +++ b/third_party/mediapipe_visibility.diff @@ -1,8 +1,36 @@ +diff --git a/mediapipe/calculators/tensor/BUILD b/mediapipe/calculators/tensor/BUILD +index 72c2f51..f400da5 100644 +--- a/mediapipe/calculators/tensor/BUILD ++++ b/mediapipe/calculators/tensor/BUILD +@@ -886,3 +886,9 @@ cc_library( + }), + alwayslink = 1, + ) ++ ++filegroup( ++ name = "protos_src", ++ srcs = glob(["*.proto"]), ++ visibility = ["//visibility:public"], ++) +diff --git a/mediapipe/calculators/util/BUILD b/mediapipe/calculators/util/BUILD +index 0c1a3ce..13b887a 100644 +--- a/mediapipe/calculators/util/BUILD ++++ b/mediapipe/calculators/util/BUILD +@@ -1443,3 +1443,9 @@ cc_test( + "@com_google_absl//absl/strings", + ], + ) ++ ++filegroup( ++ name = "protos_src", ++ srcs = glob(["*.proto"]), ++ visibility = ["//visibility:public"], ++) diff --git a/mediapipe/framework/BUILD b/mediapipe/framework/BUILD -index c25e9d8..d1de343 100644 +index ef32c6c..75f56fb 100644 --- a/mediapipe/framework/BUILD +++ b/mediapipe/framework/BUILD -@@ -1676,5 +1676,5 @@ cc_test( +@@ -1666,5 +1666,5 @@ cc_test( filegroup( name = "protos_src", srcs = glob(["*.proto"]), @@ -10,10 +38,10 @@ index c25e9d8..d1de343 100644 + visibility = ["//visibility:public"], ) diff --git a/mediapipe/framework/formats/BUILD b/mediapipe/framework/formats/BUILD -index e0ec40e..7620d71 100644 +index f79e6aa..546750c 100644 --- a/mediapipe/framework/formats/BUILD +++ b/mediapipe/framework/formats/BUILD -@@ -276,7 +276,7 @@ mediapipe_register_type( +@@ -310,7 +310,7 @@ mediapipe_register_type( filegroup( name = "protos_src", srcs = glob(["*.proto"]), @@ -109,10 +137,10 @@ index 48b7b66..2d53a28 100644 + visibility = ["//visibility:public"], +) diff --git a/mediapipe/modules/objectron/calculators/BUILD b/mediapipe/modules/objectron/calculators/BUILD -index 66150c5..7ab59ce 100644 +index fb75eb3..92b306d 100644 --- a/mediapipe/modules/objectron/calculators/BUILD +++ b/mediapipe/modules/objectron/calculators/BUILD -@@ -387,3 +387,9 @@ cc_test( +@@ -405,3 +405,9 @@ cc_test( "@com_google_absl//absl/container:flat_hash_set", ], ) @@ -122,3 +150,17 @@ index 66150c5..7ab59ce 100644 + srcs = glob(["*.proto"]), + visibility = ["//visibility:public"], +) +diff --git a/mediapipe/util/BUILD b/mediapipe/util/BUILD +index a1b179a..741f767 100644 +--- a/mediapipe/util/BUILD ++++ b/mediapipe/util/BUILD +@@ -343,3 +343,9 @@ cc_test( + "//mediapipe/framework/port:gtest_main", + ], + ) ++ ++filegroup( ++ name = "protos_src", ++ srcs = glob(["*.proto"]), ++ visibility = ["//visibility:public"], ++)