RenderTextureをOpenCvSharp,Matに取り込む
一旦 Texture2D を経由させる必要があるようです。
かつ、その経由のさせ方がトリッキーです。
private RenderTexture _renderTexture = new RenderTexture(256, 256, 0, RenderTextureFormat.ARGB32); void Update() { Texture2D tex = new Texture2D(_renderTexture.width, _renderTexture.height, TextureFormat.RGB24, false, false); // 現在のフレームバッファを取り込みたい RenderTexture に切り替えて RenderTexture.active = _renderTexture; // 取り込んで tex.ReadPixels(new UnityEngine.Rect(0, 0, tex.width, tex.height), 0, 0); tex.Apply(); // 戻す RenderTexture.active = null; // Matに取り込む Mat srcMat = new Mat(tex.height, tex.width, MatType.CV_8UC3, tex.GetRawTextureData()); }