正如题主所说。我正在尝试在unity3d中实现openCVSharp surf,并且有点卡在从iplimage到texture2d的转换部分。还考虑到此转换过程应至少以 25 fps 运行。所以任何提示或建议都非常有帮助!
问问题
3128 次
3 回答
1
可能有点晚了,我现在正在做同样的事情,这是我的解决方案:
void IplImageToTexture2D (IplImage displayImg)
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
float b = (float)displayImg[i, j].Val0;
float g = (float)displayImg[i, j].Val1;
float r = (float)displayImg[i, j].Val2;
Color color = new Color(r / 255.0f, g / 255.0f, b / 255.0f);
videoTexture.SetPixel(j, height - i - 1, color);
}
}
videoTexture.Apply();
}
但这有点慢。仍在努力提高性能。
于 2013-05-03T10:09:12.260 回答
1
Texture2D tex = new Texture2D(640, 480);
CvMat img = new CvMat(640, 480, MatrixType.U8C3);
byte[] data = new byte[640 * 480 * 3];
Marshal.Copy(img.Data, data, 0, 640 * 480 * 3);
tex.LoadImage(data);
于 2014-01-29T14:43:25.813 回答
0
要提高性能,请使用 Unity3d 的未记录函数 LoadRawTextureData :
Texture2D IplImageToTexture2D(IplImage img)
{
Texture2D videoTexture = new Texture2D(imWidth, imHeight, TextureFormat.RGB24, false);
byte[] data = new byte[imWidth * imHeight * 3];
Marshal.Copy(img.ImageData, data, 0, imWidth * imHeight * 3);
videoTexture.LoadRawTextureData(data);
videoTexture.Apply();
return videoTexture;
}
于 2015-01-06T10:07:50.153 回答