My guess: a count increments upward when the entrance door swings open and downward when the exit door swings. If one person holds the door for a few people but they exit individually, the count gets messed up.
You can't go by doors opening or light barriers because of the issue you mentioned.
Using e.g. cameras mounted on the ceiling kinda works, as long as you have a small area to cover, but they use a lot of processing power and are still not accurate.
Going by CO2 counts or VOCs is possible, but lags behind and has to be calibrated per room (and is still inaccurate without good ventilation).
I wish there was an easy solution, especially for smart homes.
Because that would allow me to do a bunch of automations like automatically turning off lights when leaving the room, or transferring music between speakers so it follows you. I've actually implemented both of these, but you have to carry around a Bluetooth beacon, and it's not fast enough to be fully seamless.