【发布时间】:2014-03-21 14:23:46
【问题描述】:
我正在使用 EmguCV 的 Capture 类,使用 LoadImage 函数将来自相机的图像放在 Texture2D 上。在尝试这样做之前,我正在使用 SetPixel 函数,但它太慢了。
当我执行下面的代码时,会出现一个白色背景上的红色问号,而不是相机的图像。
我在这里做错了什么?
public class testEmguCV : MonoBehaviour
{
private Capture capture;
void Start()
{
capture = new Capture();
}
void Update()
{
Image<Gray, Byte> currentFrame = capture.QueryGrayFrame();
Texture2D camera = new Texture2D(400, 400);
if (currentFrame != null)
{
camera.LoadImage(currentFrame.Bytes);
renderer.material.mainTexture = camera;
}
}
}
【问题讨论】:
-
通过快速搜索,LoadImage 似乎用于将 Jpgs 和 Pngs 转换为 Texture2d。鉴于您使用的是 emgu 图像类,我怀疑这会起作用...也许将图像作为 jpg 保存到内存流中,然后将其扔到 LoadImage 中?
-
谢谢史蒂文,我做到了,现在可以了。
标签: c# unity3d camera emgucv texture2d