HOG+SVM实现目标检测

一、环境:VS2013+OpenCV3.0

看论文《Detection and Recognition of Traffic Planar Objects Using Colorized Laser Scan and Perspective Distortion Rectification》,Traffic Planar Objects Detection is implemented by the HoG+SVM。

HoG是在计算机视觉和图像处理中用于实现物体检测的特征描述子,出自论文:

Dalal N, Triggs B. Histograms of oriented gradients for human detection[C]//Computer Vision and Pattern Recognition, 2005. CVPR 2005. IEEE Computer Society Conference on. IEEE, 2005, 1: 886-893.(2016:Google Citation: 14046) 

下载链接:https://hal.inria.fr/file/index/docid/548512/filename/hog_cvpr2005.pdf

HoG特征详细总结:https://www.cnblogs.com/wyuzl/p/6792216.html

二、函数参数分析

(1)detectMultiScal()

virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
                                  double hitThreshold = 0, Size winStride = Size(),
                                  Size padding = Size(), double scale = 1.05,
                                  double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const;

共有8个参数:

img: 输入图像,可以是彩色图像也可以是灰度图像;

foundLocations:存取检测到的目标的位置;

hitThreshold(optional): The threshold for the distance from features to the SVM classifying plane;

winStride(optional): HoG检测窗口移动时的步长(水平和垂直)

padding(optional):在原图外围添加像素,常见的pad 尺寸包括(8,8),(16,16),(24,24),(32,32)

scale:图像的多尺度表示,每层图像都被缩小然后被高斯平滑,通常在[1.01-1.5];

finalThreshold:优化bounding box.

useMeanshiftGrouping:bool类型,表示是否用meanShift来消除重叠,默认为false.

下面的三幅图hitThreshold分别为0, 0.5,1的检测结果:

hitThreshold=0


hitThreshold=0.5


hitThreshold=1


由此可见,参数的设置不同,对检测效果影响很大,每个参数都需要合理设置,才可以达到最佳的检测效果。

(2) rectangle(): 通过传入矩形参数来画矩形

CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
                          const Scalar& color, int thickness = 1,
                          int lineType = LINE_8, int shift = 0);

(3)rectangle():通过传入对角线两点来画矩形

CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
                          const Scalar& color, int thickness = 1,
                          int lineType = LINE_8, int shift = 0);

三、代码实现HoG行人检测:

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;

int main()
{
	Mat src = imread("person_293.bmp");
	if (!src.data)
	{
		cout << "read image failed" << endl;
		return false;
	}
	//Define HOG Object
	HOGDescriptor hog; // 采用默认参数
	//Set SVM Classifier
	hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
	//Detect the Pedestrians region on the test image 
	vector<Rect> regions;
	double hitThreshold=0.5;
	cout << " hitThreshold=" << hitThreshold << endl;
	hog.detectMultiScale(src, regions, hitThreshold, Size(8, 8), Size(32, 32), 1.05, 1);
	// Display
	for (size_t i = 0; i < regions.size(); i++)
	{
		rectangle(src, regions[i], Scalar(0, 0, 255), 2);  //对判定是行人的区域画矩形标记
	}
    imshow("hog", src);
    waitKey(0);
	return 0;
}
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Linda Fan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值