Skip to content

Commit

Permalink
feat: New Sample App (#296)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
homuler committed Sep 26, 2021
1 parent 92dd555 commit 7bb877d
Show file tree
Hide file tree
Showing 860 changed files with 101,975 additions and 10,752 deletions.
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
.vs/
.DS_Store

Temp/
Logs/
Library/
CodeCoverage/
obj/
build/
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
/[Cc]ode[Cc]overage/
*.csproj
*.sln

Expand Down

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

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

Binary file not shown.

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

Binary file not shown.
22 changes: 22 additions & 0 deletions Assets/FontAwesome/Fonts/Font Awesome 5 Free-Regular-400.otf.meta

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

Binary file not shown.
21 changes: 21 additions & 0 deletions Assets/FontAwesome/Fonts/Font Awesome 5 Free-Solid-900.otf.meta

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

38 changes: 38 additions & 0 deletions Assets/FontAwesome/UnicodeInlineText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Text.RegularExpressions;

public class UnicodeInlineText : Text {
private bool disableDirty = false;
private Regex regexp = new Regex(@"\\u(?<Value>[a-zA-Z0-9]+)");

protected override void OnPopulateMesh(VertexHelper vh) {
string cache = text;
disableDirty = true;
text = Decode(text);
base.OnPopulateMesh(vh);
text = cache;
disableDirty = false;
}

private string Decode(string value) {
return regexp.Replace(value, m => ((char)int.Parse(m.Groups["Value"].Value, System.Globalization.NumberStyles.HexNumber)).ToString());
}

public override void SetLayoutDirty() {
if (disableDirty) return;
base.SetLayoutDirty();
}

public override void SetVerticesDirty() {
if (disableDirty) return;
base.SetVerticesDirty();
}

public override void SetMaterialDirty() {
if (disableDirty) return;
base.SetMaterialDirty();
}
}

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

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

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

28 changes: 28 additions & 0 deletions Assets/Mediapipe/Samples/Common/Scripts/AssetLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections;

namespace Mediapipe.Unity {
public static class AssetLoader {
static ResourceManager resourceManager;

public static void Provide(ResourceManager manager) {
resourceManager = manager;
}

public static IEnumerator PrepareAssetAsync(string name, string uniqueKey, bool overwrite = false) {
if (resourceManager == null) {
#if UNITY_EDITOR
Logger.LogWarning("ResourceManager is not provided, so default LocalResourceManager will be used");
resourceManager = new LocalResourceManager();
#else
throw new InvalidOperationException("ResourceManager is not provided");
#endif
}
return resourceManager.PrepareAssetAsync(name, uniqueKey, overwrite);
}

public static IEnumerator PrepareAssetAsync(string name, bool overwrite = false) {
return PrepareAssetAsync(name, name, overwrite);
}
}
}
111 changes: 111 additions & 0 deletions Assets/Mediapipe/Samples/Common/Scripts/Bootstrap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

namespace Mediapipe.Unity {
public class Bootstrap : MonoBehaviour {
[System.Serializable]
public enum AssetLoaderType {
StreamingAssets,
AssetBundle,
Local,
}

static readonly string TAG = typeof(Bootstrap).Name;

[SerializeField] Image screen;
[SerializeField] GameObject consolePrefab;
[SerializeField] ImageSource.SourceType defaultImageSource;
[SerializeField] InferenceMode preferableInferenceMode;
[SerializeField] AssetLoaderType assetLoaderType;
[SerializeField] bool enableGlog = true;

public InferenceMode inferenceMode { get; private set; }
public bool isFinished { get; private set; }
bool isGlogInitialized;

IEnumerator Start() {
Logger.SetLogger(new MemoizedLogger(100));
Logger.minLogLevel = Logger.LogLevel.Debug;

Logger.LogInfo(TAG, "Starting console window...");
Instantiate(consolePrefab, screen.transform);
yield return new WaitForEndOfFrame();

Logger.LogInfo(TAG, "Setting global flags...");
GlobalConfigManager.SetFlags();

if (enableGlog) {
if (Glog.logDir != null) {
if (!Directory.Exists(Glog.logDir)) {
Directory.CreateDirectory(Glog.logDir);
}
Logger.LogVerbose(TAG, $"Glog will output files under {Glog.logDir}");
}
Glog.Initialize("MediaPipeUnityPlugin");
isGlogInitialized = true;
}

Logger.LogInfo(TAG, "Initializing AssetLoader...");
switch (assetLoaderType) {
case AssetLoaderType.AssetBundle: {
AssetLoader.Provide(new AssetBundleResourceManager(Path.Combine(Application.streamingAssetsPath, "mediapipe")));
break;
}
case AssetLoaderType.StreamingAssets: {
AssetLoader.Provide(new StreamingAssetsResourceManager());
break;
}
default: {
#if UNITY_EDITOR
AssetLoader.Provide(new LocalResourceManager());
break;
#else
Logger.LogError("LocalResourceManager is only supported on UnityEditor");
yield break;
#endif
}
}

DecideInferenceMode();
if (inferenceMode == InferenceMode.GPU) {
Logger.LogInfo(TAG, "Initializing GPU resources...");
yield return GpuManager.Initialize();
}

Logger.LogInfo(TAG, "Preparing ImageSource...");
ImageSourceProvider.SwitchSource(defaultImageSource);
DontDestroyOnLoad(GameObject.Find("Image Source"));

DontDestroyOnLoad(this.gameObject);
isFinished = true;

Logger.LogInfo(TAG, "Loading the first scene...");
var sceneLoadReq = SceneManager.LoadSceneAsync(1);
yield return new WaitUntil(() => sceneLoadReq.isDone);
}

void DecideInferenceMode() {
#if UNITY_EDITOR_OSX || UNITY_EDITOR_WIN
if (preferableInferenceMode == InferenceMode.GPU) {
Logger.LogWarning(TAG, "Current platform does not support GPU inference mode, so falling back to CPU mode");
}
inferenceMode = InferenceMode.CPU;
#else
inferenceMode = preferableInferenceMode;
#endif
}

void OnApplicationQuit() {
GpuManager.Shutdown();

if (isGlogInitialized) {
Glog.Shutdown();
}

Logger.SetLogger(null);
}
}
}
15 changes: 15 additions & 0 deletions Assets/Mediapipe/Samples/Common/Scripts/Bootstrap.cs.meta

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

Loading

0 comments on commit 7bb877d

Please sign in to comment.