There are several solutions to this problem, but lets start by telling you that this forum has a search option, which will lead you to 1000 of topics doing exactly the same. Techniques you could try:
- If your camera is stable than you could start with background/foreground segmentation and could the amount of segmented areas/blobs to count people. Adding trackers will make sure you count each blob only once.
- More advanced techniques try to model humans. Examples are HOG+SVM descriptor/detector approaches.
- You could also try out the pedestrian detector for full bodys trained with the Viola and Jones approach inside OpenCV.
- Or you could go even further and try more less documented techniques like LatentSVM or ICF detector, which are also inside the OpenCV repository.
I guess, start googling on this topics and start reading!