Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,763 changes: 1,462 additions & 301 deletions Assets/Huawei/Demos/ML/MLKitDemo.unity

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Assets/Huawei/Demos/ML/MlKitDemoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class MlKitDemoManager : MonoBehaviour
private bool IsTTSEnable => HMSMLKitSettings.Instance.Settings.GetBool(HMSMLKitSettings.EnableTextToSpeechModule);
private bool IsLangDetectionEnable => HMSMLKitSettings.Instance.Settings.GetBool(HMSMLKitSettings.EnableLanguageDetectionModule);
private bool IsTextRecognitionEnable => HMSMLKitSettings.Instance.Settings.GetBool(HMSMLKitSettings.EnableTextRecognitionModule);
private bool IsSkeletonDetectionEnable => HMSMLKitSettings.Instance.Settings.GetBool(HMSMLKitSettings.EnableSkeletonDetectionModule);

#region Singleton
public static MlKitDemoManager Instance { get; private set; }
Expand Down Expand Up @@ -85,5 +86,18 @@ public void OpenTextRecognitionDemo(GameObject trMenu)
Debug.Log($"[{TextRecognitionDemoManager.Instance.enabled}] OpenTextRecognitionDemo");
}

public void OpenSkeletonDetectionDemo(GameObject trMenu)
{
if (!IsSkeletonDetectionEnable)
{
AndroidToast.MakeText("Skeleton Detection Module is not enabled").Show();
Debug.LogWarning("Skeleton Detection Module is not enabled");
return;
}
m_mlKitDemoMenu.SetActive(false);
trMenu.SetActive(true);
Debug.Log($"[{SkeletonDetectionDemoManager.Instance.enabled}] OpenSkeletonDetectionDemo");
}

#endregion
}
8 changes: 8 additions & 0 deletions Assets/Huawei/Demos/ML/SkeletonDetection.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@

using UnityEngine;
using UnityEngine.UI;
using HuaweiMobileServices.ML.SkeletonDetection;
using HuaweiMobileServices.ML.Common;
using HuaweiMobileServices.Utils;
using System.Collections.Generic;


public class SkeletonDetectionDemoManager : MonoBehaviour
{
private const string TAG = "[HMS] SkeletonDetectionDemoManager ";

[SerializeField] private Button m_backButton;
[SerializeField] private Button m_selectImageButton;
[SerializeField] private Button m_detectButton;
[SerializeField] private InputField m_inputField;
[SerializeField] public GameObject m_mlKitMenu;
[SerializeField] public GameObject m_skeletonMenu;


private MLFrame m_frame;


#region Singleton

public static SkeletonDetectionDemoManager Instance { get; private set; }
private void Singleton()
{
if (Instance != null && Instance != this)
{
Destroy(this);
}
else
{
Instance = this;
}
}

#endregion

private void Start()
{
SetupButtonListeners();
HMSMLSkeletonDetectionManager.Instance.InitConfiguration(MLSkeletonAnalyzerSetting.TYPE_NORMAL);
HMSMLTextRecognitionKitManager.Instance.OnImageSelectSuccess += OnImageSelectSuccess;
Debug.Log(TAG + "Start");
}

private void Awake()
{
Singleton();
}

private void SetupButtonListeners()
{

m_backButton.onClick.AddListener(BackToMenu);
m_selectImageButton.onClick.AddListener(OnSelectImageButton);
m_detectButton.onClick.AddListener(OnDetectionButton);

}



private void OnDetectionButton()
{
SkeletonDetectionSync();
}
private void OnSelectImageButton()
{
Debug.Log(TAG + "OnSelectImageButton");
HMSMLTextRecognitionKitManager.Instance.SelectImage();
}

public void OnDetectFrameSuccess(IList<MLSkeleton> result)
{
Debug.Log(TAG + "OnDetectFrameSuccess");

m_inputField.text = string.Empty;
Debug.Log($"{TAG} -> GetJoints: {(result.Count != 0 || result != null)}\n");
if (result.Count != 0 || result != null)
{
foreach (MLSkeleton item in result)
{
var task = item.GetJoints();
Debug.Log($"{TAG} -> TASK: {task:F2}\n");
foreach (var joint in task)
{
Debug.Log($"{TAG} -> GetPointX: {joint.GetPointX():F2} - GetPointY: {joint.GetPointY():F2}\n");
m_inputField.text += $"GetPointX: {joint.GetPointX():F2} - GetPointY: {joint.GetPointY():F2}\n";
}

}
}
else
{

m_inputField.text = "list is empty or null";
}


AndroidToast.MakeText("Skeleton Detection Success").Show();
}


private void SkeletonDetectionAsync() {

HMSMLSkeletonDetectionManager.Instance.AnalyzeFrameAsync(m_frame, OnDetectFrameSuccess, OnDetectFrameFailure);

}

private void SkeletonDetectionSync() {

var result = HMSMLSkeletonDetectionManager.Instance.AnalyzeFrameSync(m_frame);

foreach (MLSkeleton item in result)
{
var task = item.GetJoints();
Debug.Log($"{TAG} -> TASK: {task:F2}\n");
foreach (var joint in task)
{
Debug.Log($"{TAG} -> GetPointX: {joint.GetPointX():F2} - GetPointY: {joint.GetPointY():F2}\n");
m_inputField.text += $"GetPointX: {joint.GetPointX():F2} - GetPointY: {joint.GetPointY():F2}\n";
}

}

}


public void OnDetectFrameFailure(HMSException exception)
{
m_inputField.text = exception.WrappedExceptionMessage;
Debug.Log($"{TAG} -> OnDetectFrameFailure: {exception.WrappedExceptionMessage}\n");
}

public void OnImageSelectSuccess(AndroidIntent intent, AndroidBitmap bitmap)
{
Debug.Log(TAG + "OnImageSelectSuccess");
m_frame = MLFrame.FromBitmap(bitmap);
AndroidToast.MakeText("Image Selected").Show();
}

private void BackToMenu()
{
m_mlKitMenu.gameObject.SetActive(true);
m_skeletonMenu.gameObject.SetActive(false);
m_inputField.text = string.Empty;

m_detectButton.onClick.RemoveAllListeners();
m_selectImageButton.onClick.RemoveAllListeners();
StopDetection();
}

private void StopDetection() {
HMSMLSkeletonDetectionManager.Instance.StopSkeletonDetection();
}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Huawei/Editor/Utils/HMSGradleWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ private void AddConditionalPackages(List<string> packages)
"com.huawei.hms:ml-computer-vision-ocr-latin-model:3.11.0.301"
});
}

if (settings.GetBool(HMSMLKitSettings.EnableSkeletonDetectionModule))
{
packages.AddRange(new[]
{
"com.huawei.hms:ml-computer-vision-skeleton:3.11.0.301"
});
}
}
#endregion
public void OnPreprocessBuild(BuildReport report)
Expand Down
25 changes: 25 additions & 0 deletions Assets/Huawei/Editor/View/MLKitTab/HMSMLKitSettingsDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ internal class HMSMLKitSettingsDrawer : VerticalSequenceDrawer
private bool textToSpeechIsActive = false;
private bool langDetectionIsActive = false;
private bool textRecognitionIsActive = false;
private bool skeletonDetectionIsActive = false;
private TextField.TextFieldWithAccept _keyAPITextField;

private Toggle.Toggle _enableTranslateToggle;
private Toggle.Toggle _enableTextToSpeechToggle;
private Toggle.Toggle _enableLangDetectionToggle;
private Toggle.Toggle _enableTextRecognitionToggle;
private Toggle.Toggle _enableSkeletonDetectionToggle;
private HMSSettings _settings;

public HMSMLKitSettingsDrawer()
Expand All @@ -28,6 +30,7 @@ public HMSMLKitSettingsDrawer()
textToSpeechIsActive = _settings.GetBool(HMSMLKitSettings.EnableTextToSpeechModule);
langDetectionIsActive = _settings.GetBool(HMSMLKitSettings.EnableLanguageDetectionModule);
textRecognitionIsActive = _settings.GetBool(HMSMLKitSettings.EnableTextRecognitionModule);
skeletonDetectionIsActive = _settings.GetBool(HMSMLKitSettings.EnableSkeletonDetectionModule);

AddDrawer(new VerticalSequenceDrawer(
new HorizontalSequenceDrawer(new Spacer(), new Label.Label("- ML Kit Modules -").SetBold(true), new Spacer()),
Expand Down Expand Up @@ -102,13 +105,30 @@ private void TextRecognitionDrawer()
AddDrawer(_enableTextRecognitionToggle);
AddDrawer(new HorizontalLine());
}


private void SkeletonDetectionModuleDrawer()
{
AddDrawer(new VerticalSequenceDrawer(
new HorizontalSequenceDrawer(new Label.Label("Skeleton Detection Module").SetBold(true)),
new HorizontalSequenceDrawer(new Spacer()),
new HorizontalSequenceDrawer(new Label.Label("Skeleton Detection Module enables you to detect to languages."))

));
AddDrawer(new Space(3));
_enableSkeletonDetectionToggle = new Toggle.Toggle("Enable Skeleton Detection Module", skeletonDetectionIsActive, OnSkeletonDetectionToggleChanged, false).SetLabelWidth(210);
AddDrawer(_enableSkeletonDetectionToggle);
AddDrawer(new HorizontalLine());
}

private void SetupSequence()
{
KeyAPIDrawer();
TranslateModuleDrawer();
TextToSpeechModuleDrawer();
LanguageDetectionModuleDrawer();
TextRecognitionDrawer();
SkeletonDetectionModuleDrawer();
}
private void OnTranslateToggleChanged(bool value)
{
Expand All @@ -133,6 +153,11 @@ private void OnTextRecognitionToggleChanged(bool value)
_settings.SetBool(HMSMLKitSettings.EnableTextRecognitionModule, value);
}

private void OnSkeletonDetectionToggleChanged(bool value)
{
_settings.SetBool(HMSMLKitSettings.EnableSkeletonDetectionModule, value);
}

private void OnKeyAPISaveButtonClick()
{
_settings.Set(HMSMLKitSettings.MLKeyAPI, _keyAPITextField.GetCurrentText());
Expand Down
5 changes: 0 additions & 5 deletions Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public static void KeyTool()
{
GetWindow(typeof(HMSKeyToolWindow), false, "HMS Key Tool", true);
}
[MenuItem("Huawei/Utils/Script Compilation")]
public static void ScriptCompilation()
{
GetWindow(typeof(CompilationWindow), false, "Script Compilation", true);
}

public override IDrawer CreateDrawer()
{
Expand Down
8 changes: 8 additions & 0 deletions Assets/Huawei/Scripts/ML/SkeletonDetection.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading