Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect and track people using OpenCV?

I have a camera that will be stationary, pointed at an indoors area. People will walk past the camera, within about 5 meters of it. Using OpenCV, I want to detect individuals walking past - my ideal return is an array of detected individuals, with bounding rectangles.

I've looked at several of the built-in samples:

  • None of the Python samples really apply
  • The C blob tracking sample looks promising, but doesn't accept live video, which makes testing difficult. It's also the most complicated of the samples, making extracting the relevant knowledge and converting it to the Python API problematic.
  • The C 'motempl' sample also looks promising, in that it calculates a silhouette from subsequent video frames. Presumably I could then use that to find strongly connected components and extract individual blobs and their bounding boxes - but I'm still left trying to figure out a way to identify blobs found in subsequent frames as the same blob.

Is anyone able to provide guidance or samples for doing this - preferably in Python?

like image 347
Nick Johnson Avatar asked Feb 02 '10 23:02

Nick Johnson


People also ask

How do I find someone on OpenCV?

People detection OpenCV features an implementation for a very fast human detection method, called HOG (Histograms of Oriented Gradients). This method is trained to detect pedestrians, which are human mostly standing up, and fully visible. So do not expect it to work well in other cases. Now run the script.

How does OpenCV tracking work?

We start by reading each frame of the video being played. We start the timer and use the tracker to estimate the trajectory of the object in the video. We use the tracker's estimated trajectory to draw the bounding box around the object of interest.

Can OpenCV be used for object detection?

Object Detection in a Video Using OpenCVTo detect objects in an video, the primary step is to load the video file in the program. After loading the video file, we have to segregate the video data frame by frame and perform object detection using just like before.


1 Answers

The latest SVN version of OpenCV contains an (undocumented) implementation of HOG-based pedestrian detection. It even comes with a pre-trained detector and a python wrapper. The basic usage is as follows:

from cv import *  storage = CreateMemStorage(0) img = LoadImage(file)  # or read from camera  found = list(HOGDetectMultiScale(img, storage, win_stride=(8,8),                 padding=(32,32), scale=1.05, group_threshold=2)) 

So instead of tracking, you might just run the detector in each frame and use its output directly.

See src/cvaux/cvhog.cpp for the implementation and samples/python/peopledetect.py for a more complete python example (both in the OpenCV sources).

like image 147
Martin Avatar answered Oct 01 '22 02:10

Martin