HOG detectMultiScale 参数分析 与hog 结合svm 行人检测

详见    https://www.cnblogs.com/klitech/p/5747895.html

 

测试函数

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    Mat src = imread("timg.jpg");//D:/vcprojects/images/HOGV.png
    if (src.empty()) {
        printf("could not load image...\n");
        return -1;
    }
    namedWindow("input image", CV_WINDOW_AUTOSIZE);
    imshow("input image", src);

    //Mat dst, dst_gray;
    //resize(src, dst, Size(64, 128));//大小缩放
    //cvtColor(dst, dst_gray, COLOR_BGR2GRAY);
    //HOGDescriptor detector(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9);

    //vector<float> descriptors;
    //vector<Point> locations;
    //detector.compute(dst_gray, descriptors, Size(0, 0), Size(0, 0), locations);
    //printf("number of HOG descriptors : %d", descriptors.size());
    
    HOGDescriptor hog = HOGDescriptor();
    hog.setSVMDetector(hog.getDefaultPeopleDetector());

    vector<Rect> foundLocations;
    hog.detectMultiScale(src, foundLocations, 0, Size(8, 8), Size(32, 32), 1.05, 2); //0, Size(8, 8), Size(32, 32), 1.05, 2  为可选参数
    //第二参数存入  检测到的目标位置
    //第三参数  opencv documents的解释是特征到SVM超平面的距离的阈值(Threshold for the distance between features and SVM classifying plane)

    //所以说这个参数可能是控制HOG特征与SVM最优超平面间的最大距离,当距离小于阈值时则判定为目标。
    //后两个参数为默认   
    Mat result = src.clone();
    for (size_t t = 0; t < foundLocations.size(); t++) {
        rectangle(result, foundLocations[t], Scalar(0, 0, 255), 2, 8, 0);
    }
    namedWindow("HOG SVM Detector Demo", CV_WINDOW_AUTOSIZE);
    imshow("HOG SVM Detector Demo", result);

    waitKey(0);
    return 0;
}

不清楚为啥少了个头,行人密集后也无法检测完全;

HOG detectMultiScale 参数分析 与hog 结合svm 行人检测

 

HOG detectMultiScale 参数分析 与hog 结合svm 行人检测