OpenCV Object Detection (HOGDescriptor) on iOS


I'm trying to get the people detector provided by the OpenCV library running. So far I get decent performance on my iPhone 6 but the detection is super bad and almost never correct and I'm not really sure why this is since you can find example videos using the same default HOG descriptor with way better detection.

Here is the code:

- (void)processImage:(Mat&)image {
    cv::Mat cvImg, result;
    cvtColor(image, cvImg, COLOR_BGR2HSV);

    cv::vector<cv::Rect> found, found_filtered;

    hog.detectMultiScale(cvImg, found, 0, cv::Size(4,4), cv::Size(8,8), 1.5, 0);

    size_t i;
    for (i=0; i < found.size(); i++) {
        cv::Rect r = found[i];
        rectangle(image,,, Scalar(0,255,0), 2);

The video input comes from the iPhone camera itself and "processImage:" is called for every frame. For the HOGDescriptor I use the default people detector:


I appreciate any help. :)

Show source
| ios   | iphone   | c++   | object   | opencv   2016-09-12 17:09 1 Answers

Answers to OpenCV Object Detection (HOGDescriptor) on iOS ( 1 )

  1. 2016-09-14 07:09

    I'm new to openCV, so take this with a grain of salt: The line cvtColor(image, cvImg, COLOR_BGR2HSV); converts the image from the BGR color space to the HSV color space. Essentially, it changes each pixel from being represented by how much blue, green, and red it has, to being represented by the components hue (color), saturation (how much color) and value (how bright). Clearly, the hogDescriptor acts on a BGR image, not an HSV image. You need to pass it a type CV_8UC3 image: An image with 3 channels per pixel (C3), ex. BGR, and an 8bit unsigned number for each channel (8U), This part is less important. What are you passing into the method processImage()? It should be one of those types. If not, you need to know the type and convert it to CV_8UC3 using the cvtColor() method

Leave a reply to - OpenCV Object Detection (HOGDescriptor) on iOS

◀ Go back