The invention discloses a method and instrument for counting the people coming in and going out, composed of CCD camera and PC (personal computer), where the CCD camera is fixed on the top of a passageway and connected with the PC by lines, and the PC is installed with picture collection card and picture recognition algorithm software that comprises five modules, i.e. target-background separating module, background reconstructing module, target picture post-processing and recognizing module, target detecting-tracking module and data accounting-outputting module; and the counting method uses the picture collection card to collect the pictures, circularly, real-timely recognizes each collected picture frame, then makes target-background separation, reconstruction, connectivity analysis and false target elimination on the target pictures, after separating the bonded target pictures, compares them with the standard target pictures of human bodies to judge their behavior, and finally counts the people coming in and going out and outputs the count. The invention can be adapted to count the people coming in and going out in various orders.