我已经成功地跟踪了视频中的移动对象。

但是我想决定一个对象是否是人。我已经在OpenCV中尝试了HOGDescriptor。 HOGDescriptor有两种检测人的方法:HOGDescriptor::detectHOGDescriptor::detectMultiScale。 OpenCV“sources\samples\cpp\peopledetect.cpp”演示了如何使用HOGDescriptor::detectMultiScale,它以不同的比例在图像周围搜索,并且速度非常慢。

就我而言,我已经在矩形中跟踪了对象。我认为使用HOGDescriptor::detect来检测矩形的内部会更快。但是OpenCV文档只有gpu::HOGDescriptor::detect(我仍然不知道如何使用它)和HOGDescriptor::detect遗漏了。我想使用HOGDescriptor::detect

谁能为我提供一些演示HOGDescriptor::detect用法的c++代码段?

谢谢。

最佳答案

由于已经有了对象列表,因此可以为所有对象调用HOGDescriptor::detect方法并检查输出foundLocations数组。如果不为空,则将对象分类为人。唯一的问题是,HOG默认情况下可与64x128窗口一起使用,因此您需要重新调整对象的大小:

std::vector<cv::Rect> movingObjects = ...;

cv::HOGDescriptor hog;
hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
std::vector<cv::Point> 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
    }
}

关于c++ - OpenCV:如何使用HOGDescriptor::detect方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21192984/

10-12 04:49