Cascade person detector with Haar-like features

There are two different OpenCV implementations for a cascade (boosting approach) person detector with Haar-like features:

Both versions are parallel.

CPU version

The CPU version is distributed onto the CPU cores by the parallel_for statement. The CascadeClassifier::detectMultiScale() method calls CascadeClassifier::detectSingleScale() which uses the parallel_for statement:

parallel_for(BlockedRange(0, stripCount), CascadeClassifierInvoker( *this,
processingRectSize, stripSize, yStep, factor, concurrentCandidates,
rejectLevels, levelWeights, false, currentMask));

GPU version

The GPU version uses a GpuMat matrix to upload the image to the graphics card, then calls cv::gpu::CascadeClassifier_GPU::detectMultiScale() to do the processing on the GPU.

Both versions can be tested with the new cascadeclassifier_gpu.exe sample program (in <yourOpenCVBuildDirectory>\bin\Release\).

You can switch with space between the GPU and CPU versions of the cascade detector.

cascadeclassifier_gpu.cpp shows you how to use both the GPU and the CPU version:

...
GpuMat frame_gpu, gray_gpu, resized_gpu, facesBuf_gpu;
 
/* parameters */
bool useGPU = false;
double scaleFactor = 1.0;
bool findLargestObject = false;
bool filterRects = true;
bool helpScreen = false;
 
int detections_num;
for (;;)
{
    if (isInputCamera || isInputVideo)
    {
        capture >> frame;
        if (frame.empty())
        {
            break;
        }
    }
 
    (image.empty() ? frame : image).copyTo(frame_cpu);
    frame_gpu.upload(image.empty() ? frame : image);
 
    convertAndResize(frame_gpu, gray_gpu, resized_gpu, scaleFactor);
    convertAndResize(frame_cpu, gray_cpu, resized_cpu, scaleFactor);
 
    TickMeter tm;
    tm.start();
 
    if (useGPU)
    {
        cascade_gpu.visualizeInPlace = true;
        cascade_gpu.findLargestObject = findLargestObject;
 
        detections_num = cascade_gpu.detectMultiScale(resized_gpu, facesBuf_gpu, 1.2,
                                              (filterRects || findLargestObject) ? 4 : 0);
        facesBuf_gpu.colRange(0, detections_num).download(faces_downloaded);
    }
    else
    {
        Size minSize = cascade_gpu.getClassifierSize();
        cascade_cpu.detectMultiScale(resized_cpu, facesBuf_cpu, 1.2,
                                        (filterRects || findLargestObject) ? 4 : 0,
                                        (findLargestObject ? CV_HAAR_FIND_BIGGEST_OBJECT : 0)
                                        | CV_HAAR_SCALE_IMAGE,
                                        minSize);
        detections_num = (int)facesBuf_cpu.size();
    }
...

Demos

Call the 'cascadeclassifier_gpu.exe like the following:

cascadeclassifier_gpu.exe --cascade C:\opencv\orig\data\haarcascades\haarcascade_fullbody.xml
 --video C:\humaneva\orig\I\S1\Image_Data\Box_1_(C1).avi

GPU vs. CPU (with filter)

With filter means that the detection rectangles are filtered before they are returned by the detectMultiScale() method.

GPU vs. CPU (without filter)

Conclusions

  • Note: the GPU and CPU version yield different results!
  • in particular does the GPU version not yield as much detections as the CPU version does when the detection rectangle filter is switched on
  • speed differences will heavily depend on your CPU / GPU features
 
public/cascade_person_detector_with_haar-like_features.txt · Last modified: 2012/04/03 11:47 (external edit) · []
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki