forked from homuler/MediaPipeUnityPlugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoxTrackingSolution.cs
More file actions
53 lines (44 loc) · 1.58 KB
/
Copy pathBoxTrackingSolution.cs
File metadata and controls
53 lines (44 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Mediapipe.Unity.BoxTracking
{
public class BoxTrackingSolution : ImageSourceSolution<BoxTrackingGraph>
{
[SerializeField] private DetectionListAnnotationController _trackedDetectionsAnnotationController;
protected override void OnStartRun()
{
if (!runningMode.IsSynchronous())
{
graphRunner.OnTrackedDetectionsOutput += OnTrackedDetectionsOutput;
}
SetupAnnotationController(_trackedDetectionsAnnotationController, ImageSourceProvider.ImageSource);
}
protected override void AddTextureFrameToInputStream(TextureFrame textureFrame)
{
graphRunner.AddTextureFrameToInputStream(textureFrame);
}
protected override IEnumerator WaitForNextValue()
{
List<Detection> trackedDetections = null;
if (runningMode == RunningMode.Sync)
{
var _ = graphRunner.TryGetNext(out trackedDetections, true);
}
else if (runningMode == RunningMode.NonBlockingSync)
{
yield return new WaitUntil(() => graphRunner.TryGetNext(out trackedDetections, false));
}
_trackedDetectionsAnnotationController.DrawNow(trackedDetections);
}
private void OnTrackedDetectionsOutput(object stream, OutputEventArgs<List<Detection>> eventArgs)
{
_trackedDetectionsAnnotationController.DrawLater(eventArgs.value);
}
}
}