Sensing the number of people occupying a building in real-time facilitates a number of pervasive applications within the area of building energy optimization and adaptive control. To ascertain occupant counts, the adoption of camera-based sensors i.e. 3D stereo-vision and thermal cameras have grown significantly. However, camera-based sensors can only produce occupant counts with accumulating errors. Existing methods for correcting such errors can only correct erroneous count data at the end of the day and not in real-time. However, many applications depend on real-time corrected counts. In this paper, we present an algorithm named PreCount for accurately correcting raw counts in real-time. The core idea of PreCount is to learn error estimates from the past. We evaluated the accuracy of the PreCount algorithm using datasets from four buildings. Also, the Normalized Root Mean Squared Error was used to evaluate the performance of PreCount. Our evaluation results show that in real-time PreCount achieved a significantly lower Normalized Root Mean Squared Error compared to raw counts and other correction approach with a maximum error reduction of 68% when benchmarked with ground truth data. By presenting a more accurate algorithm for estimating occupant counts in real-time, we hope to enable buildings to better serve the actual number of people to improve both occupant comfort and energy efficiency.