基于 HOG 特征的 SVM 分类器用于“对象检测"在 OpenCV 中 [英] SVM classifier based on HOG features for "object detection" in OpenCV

查看:41
本文介绍了基于 HOG 特征的 SVM 分类器用于“对象检测"在 OpenCV 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我想检测图像中的对象;我的目标是使用 HOG 功能.通过使用 OpenCV SVM 实现,我可以找到检测人的代码,并且我阅读了一些关于调整参数以检测对象而不是人的论文.不幸的是,由于一些原因我不能这样做;首先,我可能是错误地调整了参数,其次,我不是一个好的 C++ 程序员,但我必须用 C++/OpenCV 来做... 这里 你可以找到使用 C++/OpenCV 检测人的 HOG 特征的代码.

I have a project, which I want to detect objects in the images; my aim is to use HOG features. By using OpenCV SVM implementation , I could find the code for detecting people, and I read some papers about tuning the parameters in order to detect object instead of people. Unfortunately, I couldn't do that for a few reasons; first of all, I am probably tuning the parameters incorrectly, second of all, I am not a good programmer in C++ but I have to do it with C++/OpenCV... here you can find the code for detecting HOG features for people by using C++/OpenCV.

假设我想检测这个中的对象图片.现在,我将向您展示我尝试在代码中更改但对我不起作用的内容.

Let's say that I want to detect the object in this image. Now, I will show you what I have tried to change in the code but it didn't work out with me.

我尝试更改的代码:

HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());

我尝试使用以下参数更改 getDefaultPeopleDetector(),但没有奏效:

I tried to change getDefaultPeopleDetector() with the following parameters, but it didn't work:

(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9, 0,-1, 0, 0.2, true, cv::HOGDescriptor::DEFAULT_NLEVELS)

然后我尝试制作一个矢量,但是当我想打印结果时,它似乎是空的.

I then tried to make a vector, but when I wanted to print the results, it seems to be empty.

vector<float> detector;

HOGDescriptor hog(Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9, 0,-1, 0, 0.2, true, cv::HOGDescriptor::DEFAULT_NLEVELS);

hog.setSVMDetector(detector);

拜托,我需要帮助解决这个问题.

Please, I need help solving this problem.

推荐答案

为了使用 opencv HOG 描述符和 SVM 分类器检测任意对象,您需要首先训练分类器.在这里玩参数无济于事,抱歉:(.

In order to detect arbitrary objects with using opencv HOG descriptors and SVM classifier, you need to first train the classifier. Playing with the parameters will not help here, sorry :( .

从广义上讲,您需要完成以下步骤:

In broad terms, you will need to complete the following steps:

步骤 1) 准备一些您要检测的对象(正样本)的训练图像.您还需要准备一些没有感兴趣对象的图像(负样本).

Step 1) Prepare some training images of the objects you want to detect (positive samples). Also you will need to prepare some images with no objects of interest (negative samples).

步骤 2) 检测训练样本的 HOG 特征并使用该特征来训练 SVM 分类器(OpenCV 中也提供).

Step 2) Detect HOG features of the training sample and use this features to train an SVM classifier (also provided in OpenCV).

步骤 3) 在 HOGDescriptor::setSVMDetector() 方法中使用经过训练的 SVM 分类器的系数.

Step 3) Use the coefficients of the trained SVM classifier in HOGDescriptor::setSVMDetector() method.

只有这样,您才能使用 peopledetector.cpp 示例代码,来检测您要检测的对象.

Only then, you can use the peopledetector.cpp sample code, to detect the objects you want to detect.

这篇关于基于 HOG 特征的 SVM 分类器用于“对象检测"在 OpenCV 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆