本文介绍了OpenCV:如何使用HOGDescriptor :: detect方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have succeeded in tracking moving objects in a video.

但是我想决定一个物体是否是人物。我在OpenCV中尝试过 HOGDescriptor 。 HOGDescriptor有两种检测人的方法: HOGDescriptor :: detect HOGDescriptor :: detectMultiScale 。 OpenCV sources \samples\cpp \peopledetect.cpp演示了如何使用 HOGDescriptor :: detectMultiScale ,它在图像周围搜索不同的规模,非常慢。

However I want to decide if an object is person or not. I have tried the HOGDescriptor in OpenCV. HOGDescriptor have two methods for detecting people: HOGDescriptor::detect, and HOGDescriptor::detectMultiScale. OpenCV "sources\samples\cpp\peopledetect.cpp" demonstrates how to use HOGDescriptor::detectMultiScale , which search around the image at different scale and is very slow.

在我的例子中,我跟踪了一个矩形中的对象。我认为使用 HOGDescriptor :: detect 检测矩形内部会更快。但OpenCV文档只有 gpu :: HOGDescriptor :: detect (我仍然无法猜测如何使用它)并错过 HOGDescriptor ::检测。我想使用 HOGDescriptor :: detect

In my case, I have tracked the objects in a rectangle. I think using HOGDescriptor::detect to detect the inside of the rectangle will be much more quickly. But the OpenCV document only have the gpu::HOGDescriptor::detect (I still can't guess how to use it) and missed HOGDescriptor::detect. I want to use HOGDescriptor::detect.

任何人都可以向我提供一些c ++代码片段,演示如何使用 HOGDescriptor :: detect

Could anyone provide me with some c++ code snippet demonstrating the usage of HOGDescriptor::detect?

谢谢。

推荐答案

由于您已经有了一个对象列表,您可以为所有对象调用 HOGDescriptor :: detect 方法并检查输出 foundLocations 数组。如果它不是空的,则该对象被归类为人。唯一的问题是HOG默认使用 64x128 窗口,所以你需要重新调整你的对象:

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<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
    }
}

这篇关于OpenCV:如何使用HOGDescriptor :: detect方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:31