How to recognize movement in webcam?

I used webcamtexture.GetPixel(x,y). But it always returned different values every time, even though I covered webcam with paper. I just want to return true if there is any movement in webcam, and return false vice versa.
I don’t have any other devices such as Leapmotion controller or Kinect. I can’t buy them.
Then, how can i recognize any movement in Unity webcam? It doesn’t matter whether it would be Unity 2D or 3D.
Thank you in advance!

this is a very difficult problem even when you’re using libraries.
don’t attempt to implement something like this for yourself, use a CV (computer-vision) or AR (augmented-reality) library, such as OpenCV, or Vuforia (comes built-in unity), or metaio, or something like that.

the pixel(s) always change value even if covered with a sheet of paper because of signal noise.

in general, whatever are you trying to do with the webcam image, and recognizing anything meaningful from it, is going to be hard even using the libraries I mentioned above.

They are returning true cause even if it black it will probably be a bit darker some times, try the code but using a float and discard if the difference between old and new texture are lower than those

Since GetPixel returns a Color instance, you’ve probably noticed that RGB values can be a bit tedious to compare with one another. You’re probably also dealing with electronic gain and general camera stuff which will change your pixel values slightly between frames.

Pixel comparisons are a bit simpler with an HSV format, so you might want to try that:

[Range(0, 1)] public float dh = 0.1f;
[Range(0, 1)] public float ds = 0.1f;
[Range(0, 1)] public float dv = 0.1f;

float h, s, v, hp, sp, vp;

void Update()
        out h, 
        out s,
        out v

    var hueChanged = Mathf.Abs(h - hp) > dh;
    var satChanged = Mathf.Abs(s - sp) > ds;
    var valChanged = Mathf.Abs(v - vp) > dv;

    if (hueChanged || satChanged || valChanged)
        Debug.LogFormat("Pixel {0},{1} changed!");

    hp = h;
    sp = s;
    vp = v;