-1

我在 Unity 中使用 opencvsharp。

我想将iplImage 转换为Texture2D。我想这样做:

Texture2D alphaTexture = new Texture2D(1024, 768, TextureFormat.Alpha8, false);
alphaTexture.wrapMode = TextureWrapMode.Clamp;
alphaTexture.filterMode = FilterMode.Point;

IplImage originIplImageAAA = Cv.CreateImage(new CvSize(1024, 768), BitDepth.U8, 1);
Cv.Zero(originIplImageAAA);

int imgSize = originIplImageAAA.ImageSize;
IntPtr aa;
int step;
CvSize rawSize;

originIplImageAAA.GetRawData(out aa, out step, out rawSize);

byte[] imageData = new byte[imgSize];

Marshal.Copy(aa, imageData, 0, imgSize);
alphaTexture.LoadImage(imageData);

但它不起作用。如何正确转换它?

4

1 回答 1

0

最简单的解决方案是将图像保存到本地,然后使用 WWW 类将其加载回 Texture2d 对象。它总是可以正常工作,并且假设它是一台 PC,它不会导致性能下降。

有一条艰难的路要走。如果您仍然需要它,我会发布样本。

PS:使用 WWW 从本地加载的纹理将像普通函数调用一样执行,因此甚至不需要 www。这仅适用于独立。

于 2014-02-24T08:58:41.220 回答