From a1da808f0dddfa68c93e0302dca868d5dc852339 Mon Sep 17 00:00:00 2001 From: Junrou Nishida Date: Sat, 5 Aug 2023 15:35:35 +0900 Subject: [PATCH] feat: add the numFaces option to FaceDetectorOptions (#984) * refactor: make runningMode public * feat: add the numFaces option --- .../Tasks/Vision/Core/BaseVisionTaskApi.cs | 16 ++++++++-------- .../Vision/FaceDetector/FaceDetectorOptions.cs | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/Core/BaseVisionTaskApi.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/Core/BaseVisionTaskApi.cs index d77af2df2..7e10dd850 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/Core/BaseVisionTaskApi.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/Core/BaseVisionTaskApi.cs @@ -14,7 +14,7 @@ namespace Mediapipe.Tasks.Vision.Core public class BaseVisionTaskApi : IDisposable { private readonly Tasks.Core.TaskRunner _taskRunner; - private readonly RunningMode _runningMode; + public RunningMode runningMode { get; } private bool _isClosed = false; /// @@ -42,7 +42,7 @@ protected BaseVisionTaskApi( var (callbackId, nativePacketsCallback) = Tasks.Core.PacketsCallbackTable.Add(packetsCallback); _taskRunner = Tasks.Core.TaskRunner.Create(graphConfig, callbackId, nativePacketsCallback); - _runningMode = runningMode; + this.runningMode = runningMode; } /// @@ -54,9 +54,9 @@ protected BaseVisionTaskApi( /// protected PacketMap ProcessImageData(PacketMap inputs) { - if (_runningMode != RunningMode.IMAGE) + if (runningMode != RunningMode.IMAGE) { - throw new InvalidOperationException($"Task is not initialized with the image mode. Current running mode: {_runningMode}"); + throw new InvalidOperationException($"Task is not initialized with the image mode. Current running mode: {runningMode}"); } return _taskRunner.Process(inputs); } @@ -70,9 +70,9 @@ protected PacketMap ProcessImageData(PacketMap inputs) /// protected PacketMap ProcessVideoData(PacketMap inputs) { - if (_runningMode != RunningMode.VIDEO) + if (runningMode != RunningMode.VIDEO) { - throw new InvalidOperationException($"Task is not initialized with the video mode. Current running mode: {_runningMode}"); + throw new InvalidOperationException($"Task is not initialized with the video mode. Current running mode: {runningMode}"); } return _taskRunner.Process(inputs); } @@ -86,9 +86,9 @@ protected PacketMap ProcessVideoData(PacketMap inputs) /// protected void SendLiveStreamData(PacketMap inputs) { - if (_runningMode != RunningMode.LIVE_STREAM) + if (runningMode != RunningMode.LIVE_STREAM) { - throw new InvalidOperationException($"Task is not initialized with the live stream mode. Current running mode: {_runningMode}"); + throw new InvalidOperationException($"Task is not initialized with the live stream mode. Current running mode: {runningMode}"); } _taskRunner.Send(inputs); } diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/FaceDetector/FaceDetectorOptions.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/FaceDetector/FaceDetectorOptions.cs index bac7339f7..c1d1ddacc 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/FaceDetector/FaceDetectorOptions.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Tasks/Vision/FaceDetector/FaceDetectorOptions.cs @@ -25,8 +25,9 @@ public sealed class FaceDetectorOptions : Tasks.Core.ITaskOptions public Tasks.Core.BaseOptions baseOptions { get; } public Core.RunningMode runningMode { get; } - public float minDetectionConfidence { get; } = 0.5f; - public float minSuppressionThreshold { get; } = 0.3f; + public float minDetectionConfidence { get; } + public float minSuppressionThreshold { get; } + public int numFaces { get; } public ResultCallback resultCallback { get; } public FaceDetectorOptions( @@ -34,12 +35,14 @@ public FaceDetectorOptions( Core.RunningMode runningMode = Core.RunningMode.IMAGE, float minDetectionConfidence = 0.5f, float minSuppressionThreshold = 0.3f, + int numFaces = 3, ResultCallback resultCallback = null) { this.baseOptions = baseOptions; this.runningMode = runningMode; this.minDetectionConfidence = minDetectionConfidence; this.minSuppressionThreshold = minSuppressionThreshold; + this.numFaces = numFaces; this.resultCallback = resultCallback; } @@ -53,6 +56,7 @@ internal Proto.FaceDetectorGraphOptions ToProto() BaseOptions = baseOptionsProto, MinDetectionConfidence = minDetectionConfidence, MinSuppressionThreshold = minSuppressionThreshold, + NumFaces = numFaces, }; }