Hi,
A dual receiver IR system (receivers mounted about 5cm to 10 cm apart) near the entrance/exit.
An up/down counter where one receiver controls the clock input and the other the direction. When the first person enters the room, the count goes from 0 to 1, next person 2 etc. (it count persons entering and exiting).
When the counter output is zero, the light is off, any other number will hold the light on.
In case of loose limbs resulting in miscounts, either use a reset button or count up/down with a hand to equalize.