A rapid pedestrian detection and counting algorithm based on HOG is proposed for getting the pedestrian flow passing the confined space. The time efficiency is increased remarkable by restricting window shrink range and setting ROI. Counting method based on single line is presented for getting tow directions people number. Experiments in three different passageway show that the proposed method don't depend on moving information, besides it has the ability of fast and stable in confined space pedestrian counting.