There will be problems reliably counting railway cars, due to movement, odd reflection angles and such. You will have to take that into account.
The common request here is a means to count the number of people in a room, exposing the difficulty of reliably counting those entering and exiting. Railway cars may be much more constrained, but there will still be difficulties.