Occupancy control is a fundamental aspect of managing spaces and services effectively. It aims to ensure safety, compliance with regulations, emergency preparedness, and overall satisfaction for individuals and businesses. To align with the described need, this paper presents a computer vision based system for automatic people counting in gates. The system is divided in five stages: video capture, motion analysis, human detection, human tracking and people counting. An RGB camera captures the top-view image of the gate and analyze the change or movement in the objects in scene. When motion is detected, the frame is sent to the object detector, which is a convolutional neural network. Then, a tracking algorithm analyzes the movement patterns of people. According to the route, it is determined whether the person arrives or leaves and the count is updated. Two test scenarios are analyzed: the entry of a public bus and a building gate. The people detection module is tested, showing a mAP of 95.2% and a mean IoU (50%) of 55.9%. Also, the counting is tested showing an average precision of 96.8%, a recall of 92% and an F1-Score of 94.3%. Finally, the system performance is evaluated, showing an average processing time of 34.2 ms and 29.2 FPS.