Giter Site home page Giter Site logo

anyway2019 / mediapipeunityplugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from homuler/mediapipeunityplugin

0.0 0.0 0.0 4.55 MB

Unity plugin to run MediaPipe

License: MIT License

JavaScript 0.05% C++ 8.24% Python 1.19% C 1.62% Java 0.06% C# 78.97% Batchfile 0.01% Dockerfile 0.75% ShaderLab 0.52% Starlark 8.59%

mediapipeunityplugin's Introduction

MediaPipe Unity Plugin

This is a Unity (2022.3.16f1) Native Plugin to use MediaPipe (0.10.9).

The goal of this project is to port the MediaPipe API (C++) one by one to C# so that it can be called from Unity.
This approach may sacrifice performance when you need to call multiple APIs in a loop, but it gives you the flexibility to use MediaPipe instead.

With this plugin, you can

  • Write MediaPipe code in C#.
  • Run MediaPipe's official solution on Unity.
  • Run your custom Calculator and CalculatorGraph on Unity.
    • โš ๏ธ Depending on the type of input/output, you may need to write C++ code.

๐Ÿ˜ธ Hello World!

Here is a Hello World! example.
Compare it with the official code!

using Mediapipe;
using UnityEngine;

public sealed class HelloWorld : MonoBehaviour
{
    private const string _ConfigText = @"
input_stream: ""in""
output_stream: ""out""
node {
  calculator: ""PassThroughCalculator""
  input_stream: ""in""
  output_stream: ""out1""
}
node {
  calculator: ""PassThroughCalculator""
  input_stream: ""out1""
  output_stream: ""out""
}
";

    private void Start()
    {
        using var graph = new CalculatorGraph(_ConfigText);
        using var poller = graph.AddOutputStreamPoller<string>("out");
        graph.StartRun();

        for (var i = 0; i < 10; i++)
        {
            graph.AddPacketToInputStream("in", Packet.CreateStringAt("Hello World!", i));
        }

        graph.CloseInputStream("in");
        var packet = new Packet<string>();

        while (poller.Next(packet))
        {
            Debug.Log(packet.Get());
        }
        graph.WaitUntilDone();
    }
}

For more detailed usage, see the API Overview page or the tutorial on the Getting Started page.

๐Ÿ› ๏ธ Installation

This repository does not contain required libraries (e.g. libmediapipe_c.so, Google.Protobuf.dll, etc).
You can download them from the release page instead.

file contents
MediaPipeUnityPlugin-all.zip All the source code with required libraries. If you need to run sample scenes on your mobile devices, prefer this.
com.github.homuler.mediapipe-*.tgz A tarball package
MediaPipeUnityPlugin.*.unitypackage A .unitypackage file

If you want to customize the package or minify the package size, you need to build them by yourself.
For a step-by-step guide, please refer to the Installation Guide on Wiki.
You can also make use of the Package Workflow on Github Actions after forking this repository.

โš ๏ธ libraries that can be built differ depending on your environment.

Supported Platforms

โš ๏ธ GPU mode is not supported on macOS and Windows.

Editor Linux (x86_64) macOS (x86_64) macOS (ARM64) Windows (x86_64) Android iOS WebGL
Linux (AMD64) 1 โœ”๏ธ โœ”๏ธ โœ”๏ธ
Intel Mac โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
M1 Mac โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Windows 10/11 (AMD64) 2 โœ”๏ธ โœ”๏ธ โœ”๏ธ

๐Ÿฝ๏ธ Try the sample app

Example Solutions

Here is a list of solutions that you can try in the sample app.

๐Ÿ”” The graphs you can run are not limited to the ones in this list.

Android iOS Linux (GPU) Linux (CPU) macOS (CPU) Windows (CPU) WebGL
Face Detection โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Face Mesh โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Iris โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Hands โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Pose โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Holistic โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Selfie Segmentation โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Hair Segmentation โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ
Object Detection โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ โœ”๏ธ

UnityEditor

Select any scenes under Mediapipe/Samples/Scenes and play.

Desktop, Android, iOS

Select proper Inference Mode and Asset Loader Type from the Inspector Window.

Preferable Inference Mode

If you've built native libraries for CPU (i.e. --desktop cpu), select CPU for inference mode.
When building for Android/iOS, make sure that you select GPU for inference mode, because CPU inference mode is not supported currently.

preferable-inference-mode

Asset Loader Type

The default Asset Loader Type is set to Local, which only works on UnityEditor.
To run it on your devices, switch it to StreamingAssets and copy the required resources under StreamingAssets (if you're using MediaPipeUnityPlugin-all.zip, the StreamingAssets directory already contains them).

asset-loader-type

See the tutorial for more details.

๐Ÿ“– Wiki

https://github.com/homuler/MediaPipeUnityPlugin/wiki

๐Ÿ“œ LICENSE

MIT

Note that some files are distributed under other licenses.

  • MediaPipe (Apache Licence 2.0)
  • emscripten (MIT)
    • third_party/mediapipe_emscripten_patch.diff contains code copied from emscripten
  • FontAwesome (LICENSE)
    • Sample scenes use Font Awesome fonts

See also Third Party Notices.md.

Footnotes

  1. Tested on Arch Linux. โ†ฉ

  2. Running MediaPipe on Windows is experimental. โ†ฉ

mediapipeunityplugin's People

Contributors

homuler avatar sergeyame avatar dender46 avatar donghwankim0101 avatar ethan42411 avatar gkiernozek avatar lguilhermerodrigues avatar mids avatar kennethharmon avatar robyer1 avatar codeavr avatar speykious avatar thaina avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.