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;
}
HOG+SVM是一种常用的目标检测方法,其中HOG(Histogram of Oriented Gradients)是一种特征描述子,SVM(Support Vector Machine)是一种分类器。通过使用HOG特征描述子提取图像中的行人特征,然后使用SVM分类器对提取的特征进行分类,从而实现目标行人的检测。 在使用HLS(High-Level Synthesis)实现HOG+SVM目标行人检测时,可以将HOG特征描述子和SVM分类器的算法实现采用C语言编写,并进行分析优化,以更好地利用FPGA的底层架构和资源。这个过程涉及修改directive和C代码,根据不同的需求进行优化指令的实现方式。最后,通过C和RTL联合仿真,可以输出设计并导出IP,以便在vivado的其他设计中使用。 使用HLS实现HOG+SVM目标行人检测的优势在于简化了代码编写的过程。相比于直接编写RTL代码,使用HLS可以通过一个简单的for循环调用模块A来实现对模块A的复用。在资源有限的情况下,可以进行分时复用;而在需要高吞吐量的情况下,可以进行逻辑复制。只需添加不同的directive,即可生成不同的solution,综合成不同的电路结构,非常方便和高效。\[1\]\[2\] #### 引用[.reference_title] - *1* *2* [HOG+SVM实现行人检测原理总结](https://blog.csdn.net/weixin_32954161/article/details/115905294)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Linda Fan

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

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

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

打赏作者

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

抵扣说明:

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

余额充值