Tango と Unity をいじり始めたところです。残念ながら、最新リリースの Unity でカラー データにアクセスする方法に関するドキュメントや例はないようです。
GitHub のモーション トラッキングの例 ( https://github.com/googlesamples/tango-examples-unity ) を出発点として使用し、ポーズと深度データを読み取るのと同じ方法で着信カラー フレームを読み取ろうとしました。「ITangoVideoOverlay」インターフェースと「OnTangoImageAvailableEventHandler」コールバックを経由するのが最善の方法だと思います。
私が今やろうとしているのは、「OnTangoImageAvailableEventHandler」コールバックを機能させることだけですが、よくわかりません。Tango Manager で [Enable Video Overlay] をオンにし、次のスクリプトをデバッグ用の GUI テキスト オブジェクトに接続しました。
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using Tango;
using System;
public class VideoController : MonoBehaviour, ITangoVideoOverlay
{
private TangoApplication m_tangoApplication;
private bool debugB = false;
public Text debugText;
// Use this for initialization
void Start () {
m_tangoApplication = FindObjectOfType<TangoApplication>();
m_tangoApplication.Register(this);
}
// Update is called once per frame
void Update () {
if (debugB)
debugText.text = "TRUE";
else
debugText.text = "FALSE";
}
// No Unity API
public void OnTangoImageAvailableEventHandler(Tango.TangoEnums.TangoCameraId id, Tango.TangoUnityImageData image)
{
debugB = true;
}
}
私が見逃しているカメラの初期化はありますか? または、この古いコードのように VideoOverlayListener を使用する方法がまだ推奨されています: Unity で色データを取得する
Unityを介してカメラに直接アクセスすることも可能であることを知っています(深度を無効にします)。でも、まずは「正しいやり方」を学びたい。
お時間をいただきありがとうございます!
2015 年 4 月 28 日更新 - スクリプトの最新バージョン、コールバックが機能します。まだ RGB カラーへの変換が必要です
このスクリプトは、GitHub にある Google の Tango Motion Tracking の例への追加として作成されました。スクリプトを Unity カメラにアタッチし、パブリック フィールド「m_viewScreen」をメッシュ オブジェクト (平面など) にリンクして、ビデオ テクスチャを表示します。
using System.Collections;
using UnityEngine;
using Tango;
using System;
public class VideoController : MonoBehaviour
{
private TangoApplication m_tangoApplication;
private Texture2D m_texture;
private Material m_screenMaterial;
private MeshFilter m_meshFilter;
private bool m_readyToDraw = false;
// Link to a mesh object for displaying texture
public GameObject m_viewScreen;
// Use this for initialization
void Start ()
{
// Tango initilization
m_tangoApplication = FindObjectOfType<TangoApplication>();
m_tangoApplication.Register(this);
m_tangoApplication.RegisterPermissionsCallback(_OnTangoApplicationPermissionsEvent);
// Initialize view object Material
m_meshFilter = m_viewScreen.GetComponent<MeshFilter> ();
m_screenMaterial = new Material(Shader.Find("Mobile/Unlit (Supports Lightmap)"));
// Begin to texture to webcam
m_texture = m_tangoApplication.GetVideoOverlayTexture();
m_texture.Apply();
if (m_screenMaterial != null)
{
// Apply the texture
m_screenMaterial.mainTexture = m_texture;
m_meshFilter.GetComponent<MeshRenderer>().material = m_screenMaterial;
// Connect the texture to the camera
if (m_tangoApplication.m_useExperimentalVideoOverlay)
{
VideoOverlayProvider.ExperimentalConnectTexture(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, m_texture.GetNativeTextureID(), _OnUnityFrameAvailable);
}
else
{
VideoOverlayProvider.ConnectTexture(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR, m_texture.GetNativeTextureID());
}
}
}
private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted)
{
m_readyToDraw = true;
}
private void _OnUnityFrameAvailable(System.IntPtr callbackContext, Tango.TangoEnums.TangoCameraId cameraId)
{
// Do fun stuff here!
}
void OnPreRender()
{
if (m_readyToDraw)
{
VideoOverlayProvider.RenderLatestFrame(TangoEnums.TangoCameraId.TANGO_CAMERA_COLOR);
GL.InvalidateState();
}
}
void Update ()
{
// Do other fun stuff here!
}
}