Frage

I am using the Capture class from EmguCV to put the image from the camera on a Texture2D using LoadImage function. Before trying to do this, i was using the SetPixel function but it was too slow.

When I execute the code below, a red question mark on a white background appears instead of the image of the camera.

What am I doing wrong here ?

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;
        }
     }
}
War es hilfreich?

Lösung

Here are the modifications I did to correct the problem:

public class testEmguCV : MonoBehaviour
{
    private Capture capture;

    void Start() 
    {
        capture = new Capture();
    }

    void Update()
    {
        Image<Gray, Byte> currentFrame = capture.QueryGrayFrame();
        Bitmap bitmapCurrentFrame = currentFrame.ToBitmap();
        MemoryStream m = new MemoryStream();
        bitmapCurrentFrame.Save(m, bitmapCurrentFrame.RawFormat);

        Texture2D camera = new Texture2D(400, 400);
        if (currentFrame != null)
        {
            camera.LoadImage(m.ToArray());
            renderer.material.mainTexture = camera;
        }
     }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top