Detecting a vehicle to obtain traffic information at nighttime is difficult. This study proposes a vehicle detection algorithm, called the headlight extraction, pairing, and tracking (HLEPT) algorithm, which can acquire traffic information in the rain at nighttime by identifying vehicles through the location of their headlights and other indicative lights. A knowledge-based connected-component procedure, in which vehicles are located by grouping their lights and estimating their features, is proposed. The features of a complex nighttime traffic scene were also analyzed. The HLEPT algorithm includes a headlight extraction algorithm, as well as regulations for the pairing and grouping of lights and light tracking using a Kanade-Lucas-Tomasi tracker to measure traffic flow and velocity. Experimental results demonstrate the feasibility and effectiveness of the proposed approach on vehicle detection in the rain at nighttime.