suboptimal traffic management, with unnecessary delays, higher fuel consumption, and higher emissions. Traffic management can be improved by installing inductive loops; however, installation involves temporary road closures and high maintenance costs, especially if there is normally a lot of heavy traffic on the road. We present a vehicle detection and counting system based on digital image-processing techniques. These images can be taken by digital cameras installed at the top of existing traffic lights. By using the proposed approach, it is possible to detect the number of vehicles waiting on each side of the intersection, hence, providing the necessary information for optimal traffic management. Results achieved after testing this methodology on three real intersections are promising, attaining high accuracy during the day (98.8%) and the night (91.3%) while counting several vehicles at the same time. Hence, the system is equivalent to installing multiple inductive loops in all the streets of the intersection, but with lower installation and maintenance costs. After integrating the proposed algorithms into a traffic-management system, it was possible to reduce fuel and CO2 emissions by half compared to the standard fixed-time scheduler.