When you work with pixel arrays (note plural) you need to be careful to reference the right pixel array. You have three pixel arrays in you’re code:
- cam.Pixels
- prevFrame.Pixels
- pixels – that is pixel array for the screen or window for processing app
You define loc from cam, if it has different height or width than display you will get “NullPointerException” when you pick a pixel on area that’s within cam area, but outside of display area.