Skip to content

Commit 7bb877d

Browse files
authored
feat: New Sample App (#296)
* wip: New sample scene (Face Detection) * wip: make AssetLoader static * wip: implement ImageSource classes for static image and video * fix: WebCamTexture's format is usually ARGB32 * refactor(sample): implement generic method to get NativeArray * refactor(sample): enable to specify TextureFrame's format * refactor: implement WaitForResult * refactor: cache TextureFrame instances * wip: make ImageSource runnable * wip: enable to pause/resume current program * don't show GlogDir's parent directory * wip: add web cam resolutions * wip: initialize outputTexture when Play is called * wip: change font size * refactor: SolutionBase -> Solution * refactor: GetInstanceId -> GetInstanceID * wip: implement StreamingAssetsResourceManager * wip: change Glog I/Fs * wip: UInt64 -> UInt32 * feat: ObserveOutputStream receives observeTimestampBounds flag * wip: convert TextureFormat to ImageFormat.Format * wip: implement GraphRunner * wip: FaceDetection test * fix: Texture format is incompatible * wip: ImageSource does not manage TextureFramePool * wip: implement Annotation * wip: flip image * rename * wip: asynchronous sample * wip: FaceDetection Config * wip: FontAwesome license * remove old face detection sample * wip: make a prefab for Main Canvas * wip: Face Mesh sample * wip: clear annotations when modal is open * wip: implement Logger * refactor: TextureFrame's namespace * wip: use Logger * wip: implement GUIConsole * wip: draw annotations under modal panel * wip: console window * wip: scroll console * fix: fails to initialize calculator graph * wip: switch scenes * wip: Hand Tracking sample * fix: ROI can be NaN * remove old hand tracking example * resume when solution menu is closed * set Glog flags * fix: Config Window's label * wip: new Pose Tracking sample * webcam may fail to start * fix: failed to read pixels from static image and video * wip: fails to restart graph runnner sometimes * wip: annotate PoseWorldLandmarks * remove old Pose Tracking sample * wip: OutputStreamPoller emits empty packets when there are not outputs * wip: annotate RoiFromLandmarks * typo * wip: new Iris Tracking sample * refactor: refactor annotations * wip: draw annotations synchronously * wip: enable to change properties from inspector * wip: add Holistic new sample * remove old iris and holistic samples * refactor: IrisTracking -> Iris Tracking * wip: add new Object Detection sample * remove old Object Detection sample * wip: add new Box Tracking sample * remove old Box Tracking sample * fix: crash when Hair Segmentation sample runs again * wip: add new Hair Segmentation sample * remove old Hair Segmentation sample * fix: log with an empty tag * fix: make menu windows scrollable * wip: Convert Main Canvas's body to prefab * remove unnecessary initialization * refactor: normalize callback names * set callbacks from code * wip: add new Hello World scene * remove all listeners when restarting * remove old Hello World sample * remove unused annotation controllers * remove unused prefabs * feat: port FrameAnnotation * fix: make it runnable on CPU * fix: crashes when calling ObserveOutputStream * FrameAnnotationVector is not used * remove LineListAnnotation * wip: add new Objectron sample * remove old Objectron sample * not to use heap to marshal SerializeProto * wip: add AnchorVectorPacket for InstantMotionTracking * refactor: marshal GlTextureInfo * refactor: not to create unnecessasary struct * wip: Region Tracking * wip: not to crop input images in Objectron * refactor: remove namespace InstantMotionTracking * fix: deserialize SerializedProtoVector * cache Status.ok * refactor CoordinateTransform * wip: scale arrow length * wip: not to crop image in Objectron (OpenGL ES) * wip: add new Instant Motion Tracking sample * remove old samples * wip: not to use AssetBundle by default * wip: install resource files to StreamingAssets * remove unused resource files * wip: isMirrored support * wip: timeout support * fix: incorrect handedness * fix: apply ArrowLengthScale * fallback to CPU * wip: region tracking on CPU * wip: new Official demo sample * ignore UserSettings * wip: enable logtostderr by default * wip: Texture's property may be accessed from another thread * fix: StreamingAssetsResourceManager won't work on Android * wip: synchronize input and output on Android * fix: failed to save config file * fix: typo * default orientation * remove files under UserSettings * refactor: add OutputStream class * fix: marshal boolean value * wip: instant motion tracking * fix: macOS and iOS * doc: change commands * wip: rotation * wip: flip images vertically * wip: hair segmentation on iOS * fix: objectron on iOS * fix: consider device orientation * wip: support rotation * fix: no need to flip vertically in MediaPipeVideoSolution * fix: not to show empty mask layer by default * fix: z scale in instant motion tracking * doc: update example graphs' matrix * fix: ignore Preferable Inference Mode on UnityEditor * doc: update documents * change default rotation
1 parent 92dd555 commit 7bb877d

File tree

860 files changed

+101975
-10752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

860 files changed

+101975
-10752
lines changed

.gitignore

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
.vs/
44
.DS_Store
55

6-
Temp/
7-
Logs/
8-
Library/
9-
CodeCoverage/
10-
obj/
11-
build/
6+
/[Ll]ibrary/
7+
/[Tt]emp/
8+
/[Oo]bj/
9+
/[Bb]uild/
10+
/[Bb]uilds/
11+
/[Ll]ogs/
12+
/[Uu]ser[Ss]ettings/
13+
/[Cc]ode[Cc]overage/
1214
*.csproj
1315
*.sln
1416

Assets/Mediapipe/Samples/Graphs/BoxTracking.meta renamed to Assets/FontAwesome.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Mediapipe/Samples/Graphs/BoxTracking/Objects.meta renamed to Assets/FontAwesome/Fonts.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

Assets/FontAwesome/Fonts/Font Awesome 5 Brands-Regular-400.otf.meta

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

Assets/FontAwesome/Fonts/Font Awesome 5 Free-Regular-400.otf.meta

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

Assets/FontAwesome/Fonts/Font Awesome 5 Free-Solid-900.otf.meta

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
using System.Text.RegularExpressions;
6+
7+
public class UnicodeInlineText : Text {
8+
private bool disableDirty = false;
9+
private Regex regexp = new Regex(@"\\u(?<Value>[a-zA-Z0-9]+)");
10+
11+
protected override void OnPopulateMesh(VertexHelper vh) {
12+
string cache = text;
13+
disableDirty = true;
14+
text = Decode(text);
15+
base.OnPopulateMesh(vh);
16+
text = cache;
17+
disableDirty = false;
18+
}
19+
20+
private string Decode(string value) {
21+
return regexp.Replace(value, m => ((char)int.Parse(m.Groups["Value"].Value, System.Globalization.NumberStyles.HexNumber)).ToString());
22+
}
23+
24+
public override void SetLayoutDirty() {
25+
if (disableDirty) return;
26+
base.SetLayoutDirty();
27+
}
28+
29+
public override void SetVerticesDirty() {
30+
if (disableDirty) return;
31+
base.SetVerticesDirty();
32+
}
33+
34+
public override void SetMaterialDirty() {
35+
if (disableDirty) return;
36+
base.SetMaterialDirty();
37+
}
38+
}
+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Mediapipe/Samples/Graphs/BoxTracking/Resources.meta renamed to Assets/Mediapipe/Samples/Common.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Mediapipe/Samples/Graphs/BoxTracking/Scripts.meta renamed to Assets/Mediapipe/Samples/Common/Scripts.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections;
3+
4+
namespace Mediapipe.Unity {
5+
public static class AssetLoader {
6+
static ResourceManager resourceManager;
7+
8+
public static void Provide(ResourceManager manager) {
9+
resourceManager = manager;
10+
}
11+
12+
public static IEnumerator PrepareAssetAsync(string name, string uniqueKey, bool overwrite = false) {
13+
if (resourceManager == null) {
14+
#if UNITY_EDITOR
15+
Logger.LogWarning("ResourceManager is not provided, so default LocalResourceManager will be used");
16+
resourceManager = new LocalResourceManager();
17+
#else
18+
throw new InvalidOperationException("ResourceManager is not provided");
19+
#endif
20+
}
21+
return resourceManager.PrepareAssetAsync(name, uniqueKey, overwrite);
22+
}
23+
24+
public static IEnumerator PrepareAssetAsync(string name, bool overwrite = false) {
25+
return PrepareAssetAsync(name, name, overwrite);
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System.Collections;
2+
using System.IO;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
using UnityEngine.SceneManagement;
6+
7+
namespace Mediapipe.Unity {
8+
public class Bootstrap : MonoBehaviour {
9+
[System.Serializable]
10+
public enum AssetLoaderType {
11+
StreamingAssets,
12+
AssetBundle,
13+
Local,
14+
}
15+
16+
static readonly string TAG = typeof(Bootstrap).Name;
17+
18+
[SerializeField] Image screen;
19+
[SerializeField] GameObject consolePrefab;
20+
[SerializeField] ImageSource.SourceType defaultImageSource;
21+
[SerializeField] InferenceMode preferableInferenceMode;
22+
[SerializeField] AssetLoaderType assetLoaderType;
23+
[SerializeField] bool enableGlog = true;
24+
25+
public InferenceMode inferenceMode { get; private set; }
26+
public bool isFinished { get; private set; }
27+
bool isGlogInitialized;
28+
29+
IEnumerator Start() {
30+
Logger.SetLogger(new MemoizedLogger(100));
31+
Logger.minLogLevel = Logger.LogLevel.Debug;
32+
33+
Logger.LogInfo(TAG, "Starting console window...");
34+
Instantiate(consolePrefab, screen.transform);
35+
yield return new WaitForEndOfFrame();
36+
37+
Logger.LogInfo(TAG, "Setting global flags...");
38+
GlobalConfigManager.SetFlags();
39+
40+
if (enableGlog) {
41+
if (Glog.logDir != null) {
42+
if (!Directory.Exists(Glog.logDir)) {
43+
Directory.CreateDirectory(Glog.logDir);
44+
}
45+
Logger.LogVerbose(TAG, $"Glog will output files under {Glog.logDir}");
46+
}
47+
Glog.Initialize("MediaPipeUnityPlugin");
48+
isGlogInitialized = true;
49+
}
50+
51+
Logger.LogInfo(TAG, "Initializing AssetLoader...");
52+
switch (assetLoaderType) {
53+
case AssetLoaderType.AssetBundle: {
54+
AssetLoader.Provide(new AssetBundleResourceManager(Path.Combine(Application.streamingAssetsPath, "mediapipe")));
55+
break;
56+
}
57+
case AssetLoaderType.StreamingAssets: {
58+
AssetLoader.Provide(new StreamingAssetsResourceManager());
59+
break;
60+
}
61+
default: {
62+
#if UNITY_EDITOR
63+
AssetLoader.Provide(new LocalResourceManager());
64+
break;
65+
#else
66+
Logger.LogError("LocalResourceManager is only supported on UnityEditor");
67+
yield break;
68+
#endif
69+
}
70+
}
71+
72+
DecideInferenceMode();
73+
if (inferenceMode == InferenceMode.GPU) {
74+
Logger.LogInfo(TAG, "Initializing GPU resources...");
75+
yield return GpuManager.Initialize();
76+
}
77+
78+
Logger.LogInfo(TAG, "Preparing ImageSource...");
79+
ImageSourceProvider.SwitchSource(defaultImageSource);
80+
DontDestroyOnLoad(GameObject.Find("Image Source"));
81+
82+
DontDestroyOnLoad(this.gameObject);
83+
isFinished = true;
84+
85+
Logger.LogInfo(TAG, "Loading the first scene...");
86+
var sceneLoadReq = SceneManager.LoadSceneAsync(1);
87+
yield return new WaitUntil(() => sceneLoadReq.isDone);
88+
}
89+
90+
void DecideInferenceMode() {
91+
#if UNITY_EDITOR_OSX || UNITY_EDITOR_WIN
92+
if (preferableInferenceMode == InferenceMode.GPU) {
93+
Logger.LogWarning(TAG, "Current platform does not support GPU inference mode, so falling back to CPU mode");
94+
}
95+
inferenceMode = InferenceMode.CPU;
96+
#else
97+
inferenceMode = preferableInferenceMode;
98+
#endif
99+
}
100+
101+
void OnApplicationQuit() {
102+
GpuManager.Shutdown();
103+
104+
if (isGlogInitialized) {
105+
Glog.Shutdown();
106+
}
107+
108+
Logger.SetLogger(null);
109+
}
110+
}
111+
}

Assets/Mediapipe/Samples/Common/Scripts/Bootstrap.cs.meta

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)