0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

unity x tensorflow lite

Last updated at Posted at 2024-05-08

はじめに

Unityを使って、カメラでobject detectを行うための組み込み方を調べていたので覚書

必要なツールとパフォーマンスについての参考

この動画がとても参考になった

スクリーンショット 2024-05-09 14.08.17.png

スクリーンショット 2024-05-09 14.07.10.png

パフォーマンス的にBaracudaよりもTFLiteの推論ランタイムがおすすめ
..ということで、UnityでTensorflowLiteを使うために下記あたりを参考に組み込んでみようと調べてみる

他にもalia-sdkなどいくつかフレームワークは存在していたり。(未実装)

手順

manifest.json

manifest.json
{
  "scopedRegistries": [
    {
      "name": "package.openupm.com",
      "url": "https://package.openupm.com",
      "scopes": [
        "com.cysharp.unitask"
      ]
    },
    {
      "name": "npm",
      "url": "https://registry.npmjs.com",
      "scopes": [
        "com.github.asus4"
      ]
    }
  ],
  "dependencies": {
    "com.github.asus4.tflite": "2.13.0",
    "com.github.asus4.tflite.common": "2.13.0",
    "com.github.asus4.mediapipe": "2.13.0",
    ...
  }
}

modelのインポート

ファイルのインポート

スクリーンショット 2024-05-09 15.47.21.png

MainCamera -> Camera Texture Background (Tensorflow Lite)

スクリーンショット 2024-05-10 10.01.05.png

Demo -> Virtual Texture Source

スクリーンショット 2024-05-10 10.10.17.png

WebCamTexture

using UnityEngine;
 
public class CamScript : MonoBehaviour
{
    void Start()
    {
        WebCamTexture webCamTexture = new WebCamTexture();
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = webCamTexture;
        webCamTexture.Play();
    }
}

Bugなど

Library/PackageCache/com.unity.xr.management@4.4.1/Editor/Metadata/KnownPackages.cs(12,70): error CS0117: 'BuildTargetGroup' does not contain a definition for 'VisionOS'

スクリーンショット 2024-05-08 17.55.10.png

Unityを使ってデバイスのカメラインプットを利用する場合、大体検索にヒットする方法はCanvasにrawImageを置いて、そのtextureにWebCamTextureを流し込む方法です。たしかにラップトップでは問題なくサンプルコードも動きますが、iOSで動作させた瞬間にアスペクト比、オリエンテーション(向き)がむちゃくちゃになります。

WebCamTexture rotated and flipped on iPhone when applied to renderer.material.texture

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?