A robot finds dark parts on a light conveyor belt. It works in the afternoon. In the morning, and when a cloud passes, it sees parts everywhere.
You will see why a fixed number cannot work, make the detector follow the overall light, and then make it follow light that changes across the image.