HOG+SVM实现目标检测

以你之姓@ 2022-05-22 04:05 312阅读 0赞

一、环境: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()

  1. virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
  2. double hitThreshold = 0, Size winStride = Size(),
  3. Size padding = Size(), double scale = 1.05,
  4. 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

20180614165111555

hitThreshold=0.5

20180614165140681

hitThreshold=1

20180614165203848

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

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

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

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

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

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

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. using namespace std;
  4. using namespace cv;
  5. int main()
  6. {
  7. Mat src = imread("person_293.bmp");
  8. if (!src.data)
  9. {
  10. cout << "read image failed" << endl;
  11. return false;
  12. }
  13. //Define HOG Object
  14. HOGDescriptor hog; // 采用默认参数
  15. //Set SVM Classifier
  16. hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
  17. //Detect the Pedestrians region on the test image
  18. vector<Rect> regions;
  19. double hitThreshold=0.5;
  20. cout << " hitThreshold=" << hitThreshold << endl;
  21. hog.detectMultiScale(src, regions, hitThreshold, Size(8, 8), Size(32, 32), 1.05, 1);
  22. // Display
  23. for (size_t i = 0; i < regions.size(); i++)
  24. {
  25. rectangle(src, regions[i], Scalar(0, 0, 255), 2); //对判定是行人的区域画矩形标记
  26. }
  27. imshow("hog", src);
  28. waitKey(0);
  29. return 0;
  30. }

发表评论

表情:
评论列表 (有 0 条评论,312人围观)

还没有评论,来说两句吧...

相关阅读

    相关 opencv+tensorFlow探索实现目标检测

    前述: 本文为了记载自己在开发过程中的心得以及问题解决而写,阅读者在参考时尽量加入自己的思考,毕竟依赖库以及主程序随着时间的变化正在不断升级; 另外,牢骚一下,对于初

    相关 目标检测

    目标检测 目的:找出图像中所有感兴趣的目标和物体,并确定目标的位置和大小(定位目标的位置并知道目标物是什么,包括定位和分类)。 1、经典方案:滑动窗口+图像缩放 应