How to import a trained HOG detector

Hi,

So I have followed this guide to train my own pedestrian HOG detector. https://github.com/DaHoC/trainHOG/wiki/trainHOG-Tutorial

And it was successful with 4 files generated.

  • cvHOGClassifier.yaml
  • descriptorvector.dat
  • features.dat
  • svmlightmodel.dat
  • Does anyone know how to proceed from there?

    This is my current code:

    //--------use default Detector
    	vector<float> detector = gpu::HOGDescriptor::getDefaultPeopleDetector();
            gpu::HOGDescriptor hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8),9);
    	hog.setSVMDetector(detector);
    

    How should I import my own detector? and exactly which one of those 4 files is the detector?

    Thanks a bunch!

    Hi,

    We are not familiar with HOG descriptor.
    But based on the github you pasted, you should be able to use custom detector via setSVMDetector.

    hog.setSVMDetector(descriptorVector); // Set our custom detecting vector
    

    This function also contains in opencv gpu module.

    gpu::HOGDescriptor::setSVMDetector
    

    Please read details here:
    http://docs.opencv.org/2.4/modules/gpu/doc/object_detection.html#gpu-hogdescriptor-setsvmdetector

    Thank you for your reply. Do you know how to load the descriptorvector.dat file as a vector?
    I’ve tried this but failed.

    vector<float> detector;
    	std::ifstream file;
    	file.open("/home/ubuntu/work/trainHOG/genfiles/descriptorvector.dat");
    	file >> detector;
    	file.close();
            gpu::HOGDescriptor hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8),9);
    	hog.setSVMDetector(detector);
    

    Thank you!

    Hi,

    You can try this:

    SVMLight::SVMClassifier c(classifierModelName);
    vector<float> descriptorVector = c.getDescriptorVector();
    hog.setSVMDetector(descriptorVector);
    ...
    vector<Rect> found;
    Size padding(Size(0, 0));
    Size winStride(Size(8, 8));
    hog.detectMultiScale(segment, found, 0.0, winStride, padding, 1.01, 0.1);
    

    Extracted from this link:
    https://stackoverflow.com/questions/10769519/svm-classifier-based-on-hog-features-for-object-detection-in-opencv