The invention provides a method for counting passenger flow of buses in real time, which adopts means of machine learning, multi-target detection and tracking, target behavior analysis and the like, and belongs to the technical field of pattern recognition. The method comprises the following concrete steps: detecting passenger targets by analyzing shape information and texture information of passenger heads in video images, wherein a column diagram in a gradient direction is used for representing the shape information, and a column diagram in a local binary mode is used for representing the texture information; then, accurately positioning passengers by adopting the target tracking policy combining gray level cross-correlation matching tracking and mean translation algorithm searching tracking; and finally, judging the behavior characteristics of the passengers by analyzing the moving tracks of the passengers, thereby accurately counting the passenger flow of buses. The practice shows that the method provided by the invention can provide an accurate and reliable basis for realizing intelligent scheduling of buses for bus companies, analyzing the acceptability of mobile media advertisements in buses, and the like, and the invention has very high practical value.