Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Unity Demo as Web Cam Texture is 16x16 and The Demo Does Not Work #497

Open
chris-o3h opened this issue Mar 31, 2023 · 1 comment

Comments

@chris-o3h
Copy link

chris-o3h commented Mar 31, 2023

The problem is that the web cam texture starts up with a resolution of 16x16 and the example code does not wait until the resolution is actually set. So the reader is looking at a tiny 16x16 portion of the data and will never "see" the image appropriately.

A quick fix to modify the demo:

    void Update()
    {
        if (camTexture.width <= 16) return;

        W = camTexture.width;
        H = camTexture.height;
 // ... and then the rest
@micjahn
Copy link
Owner

micjahn commented Apr 8, 2023

The actual version of the method "Update" is the following:

    void Update()
    {
        if (c == null)
        {
            c = camTexture.GetPixels32();
        }

        // encode the last found
        var textForEncoding = LastResult;
        if (shouldEncodeNow &&
            textForEncoding != null)
        {
            var color32 = Encode(textForEncoding, encoded.width, encoded.height);
            encoded.SetPixels32(color32);
            encoded.Apply();
            shouldEncodeNow = false;
        }
    }

Perhaps it should be changed to this one here? What do you think?

    void Update()
    {
        if (c == null)
        {
            c = camTexture.GetPixels32();
            W = camTexture.width;
            H = camTexture.height;
        }
        /// ... and the rest here like above
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants