OpenCV: How to use HOGDescriptor::detect method?

前端 未结 2 640
逝去的感伤
逝去的感伤 2021-02-02 01:13

I have succeeded in tracking moving objects in a video. \"http://ww1.sinaimg.cn/mw690/63a9e398jw1ecn39e3togj20jv0g1gnv.jpg\"

2条回答
  •  不思量自难忘°
    2021-02-02 02:06

    Since you already have a list of objects, you can call the HOGDescriptor::detect method for all objects and check the output foundLocations array. If it is not empty the object was classified as a person. The only thing is that HOG works with 64x128 windows by default, so you need to rescale your objects:

    std::vector movingObjects = ...;
    
    cv::HOGDescriptor hog;
    hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
    std::vector foundLocations;
    for (size_t i = 0; i < movingObjects.size(); ++i)
    {
        cv::Mat roi = image(movingObjects[i]);
        cv::Mat window;
        cv::resize(roi, window, cv::Size(64, 128));
        hog.detect(window, foundLocations);
        if (!foundLocations.empty())
        {
            // movingObjects[i] is a person
        }
    }
    

提交回复
热议问题