Skip to content

Commit

Permalink
Remove unneeded dependency in video classification sample
Browse files Browse the repository at this point in the history
  • Loading branch information
asus4 committed Oct 7, 2022
1 parent 4d92ff5 commit 66985ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Assets/Samples/VideoClassification/VideoClassification.unity
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 86521802}
m_TargetAssemblyTypeName: VideoClassificationSample, Assembly-CSharp
m_MethodName: Invoke
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
OnAspectChange:
m_PersistentCalls:
m_Calls: []
Expand Down
13 changes: 8 additions & 5 deletions Assets/Samples/VideoClassification/VideoClassificationSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UI;
using TextureSource;

/// <summary>
/// MoViNets: Video Classification example from TensorFlow
/// https://www.tensorflow.org/lite/examples/video_classification/overview
/// </summary>
[RequireComponent(typeof(VirtualTextureSource))]
public class VideoClassificationSample : MonoBehaviour
{
[SerializeField]
Expand All @@ -29,17 +27,22 @@ public class VideoClassificationSample : MonoBehaviour
private void Start()
{
classification = new VideoClassification(options);
GetComponent<VirtualTextureSource>().OnTexture.AddListener(Invoke);
}

private void OnDestroy()
{
GetComponent<VirtualTextureSource>().OnTexture.RemoveListener(Invoke);
classification?.Dispose();
}

private void Invoke(Texture texture)
// Called from VirtualTextureSource
[Preserve]
public void Invoke(Texture texture)
{
if (classification == null)
{
return;
}

classification.Invoke(texture);

var categories = classification.GetResults().Take(resultCount);
Expand Down

0 comments on commit 66985ac

Please sign in to comment.