Skip to content

Commit

Permalink
feat: add the numFaces option to FaceDetectorOptions (#984)
Browse files Browse the repository at this point in the history
* refactor: make runningMode public

* feat: add the numFaces option
  • Loading branch information
homuler committed Aug 5, 2023
1 parent 8dbf3f1 commit a1da808
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
Expand Down Expand Up @@ -42,7 +42,7 @@ public class BaseVisionTaskApi : IDisposable

var (callbackId, nativePacketsCallback) = Tasks.Core.PacketsCallbackTable.Add(packetsCallback);
_taskRunner = Tasks.Core.TaskRunner.Create(graphConfig, callbackId, nativePacketsCallback);
_runningMode = runningMode;
this.runningMode = runningMode;
}

/// <summary>
Expand All @@ -54,9 +54,9 @@ public class BaseVisionTaskApi : IDisposable
/// </exception>
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);
}
Expand All @@ -70,9 +70,9 @@ protected PacketMap ProcessImageData(PacketMap inputs)
/// </exception>
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);
}
Expand All @@ -86,9 +86,9 @@ protected PacketMap ProcessVideoData(PacketMap inputs)
/// </exception>
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ 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(
Tasks.Core.BaseOptions baseOptions,
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;
}

Expand All @@ -53,6 +56,7 @@ internal Proto.FaceDetectorGraphOptions ToProto()
BaseOptions = baseOptionsProto,
MinDetectionConfidence = minDetectionConfidence,
MinSuppressionThreshold = minSuppressionThreshold,
NumFaces = numFaces,
};
}

Expand Down

0 comments on commit a1da808

Please sign in to comment.