Unity Texture2D(RGBA32)转换为OpenCV Mat

时间:2019-05-06 16:14:46

标签: opencv unity3d mat texture2d aruco

我正在尝试处理在OpenCV中使用C#拍摄的图片。 为此,我必须将Unitys Texture2D格式(在本例中为RGBA32)转换为OpenCV的Mat。

我的C#代码

static void Main(string[] args)
{
    string[,] grid = {
        {   "A", "B", "C", "D"  },
        {    "P", "R", "A", "T" },
        {    "K", "I", "T", "A" },
        {    "A", "N", "D", "Y" }
    };
}

public static IEnumerable<string> FindAllDirectionWords(string[,] grid, int curRow, int curCol, int numRows, int numCols)
{
            // Find primary diagonal now
            string primaryDiagonalWord = string.Empty;
            for (int i = curRow, j = curCol; i < numRows && j < numCols; i++, j++)
                primaryDiagonalWord += grid[i, j];
            yield return primaryDiagonalWord;


            // Find secondary diagonal now
            string secondaryDiagonalWord = string.Empty;
            for (int i = curRow, j = curCol; i < numRows && j < numCols; i++, j++)
                secondaryDiagonalWord += grid[i, j];
            yield return secondaryDiagonalWord;
}

我的互操作

unsafe{
    Color32[] textureDataColor = MLCamera.PreviewTexture2D.GetPixels32();
    fixed (Color32* p = textureDataColor){
        log("Detected Markers: " + Interop.Detect((IntPtr)p, MLCamera.PreviewTexture2D.width, MLCamera.PreviewTexture2D.height));
    }
}

还有我的C ++代码

[DllImport("ml_aruco_api")]
internal static extern int Detect(IntPtr textureData, int width, int height);

生成的pic.jpg为全灰色。我究竟做错了什么? RGBA32表示4通道,8位,我认为OpenCV可在BGR中使用吗?如果不使用cvtColor,程序将崩溃。

0 个答案:

没有答案