There is a lighted strip on the top of the corner goal ramp, with a camera positioned above. FIRST has a computer for every goal (or is it every two?) dedicated to running an algorithm to count the balls. Apparently the system was found to be extremely accurate under testing.
There is some more information out there about this system, if you search these fora and the
FIRST Q&A fora .