我有一个来自 opencv c++ 的 bgr 图像 uchar 格式。
该函数就像 int* texture(int* data, int width, int height); 该函数在 C++ 端处理图像并返回指向数据的指针。如何将 Unity 中的这些数据转换为纹理。基本上使这些数据可用作纹理。我不想将其写入文件。请帮忙。
代码片段(我正在使用 dll):::
public static WebCamTexture webCamTexture;
private Color32[] data;
private int[] imageData;
private int[] imdat;
void Start () {
....
data = new Color32[webCamTexture.width * webCamTexture.height];
imageData = new int[data.Length * 3];
}
void Update()
{
webCamTexture.GetPixels32(data);
// Convert the Color32[] in int* and emit it in bgr format
for (int i = 0; i < data.Length; ++i)
{
imageData[i * 3] = (int)data[i].b;
imageData[i * 3 + 1] = (int)data[i].g;
imageData[i * 3 + 2] = (int)data[i].r;
}
//this is the function called from dll
imdat = texture(imageData, int width, int height);
}
DLL 端看起来像 ::
char *tmp;
int* texture(int* imageData ,int width ,int height)
{
int n = w * h * 3;
tmp = new char[n];
//ImageData inverted here and then passed onto tmp 3 channels image
for (int i = 0; i < (w*3); ++i)
for (int j = 0; j < h; ++j)
tmp[i + j * (w*3)] = (char)imageData[i + (h - j - 1) * (w*3)];
return (int)tmp;
}