Hi, @nanuxe
Welcome to the forum.
Please read the post at the start of any forum , entitled "How to use this Forum".
An interesting project, is the rolling stock plastic/card with metal wheels/axles.
I would assume the loco will be metal.
You could just count rolling stock, with a disguised LED/Laser beam across the track at body height and count the gaps.
Passenger coaches may be a problem if you can see completely through the chassis windows, probably a strategic placement of the detector would avoid this.
Tom....