OpenCV_基于HOG特征的行人检测



OpenCV中提供了HOG的行人检测(pedestrain detection)类。


cv::HOGDescriptor类的构造函数的各参数的定义:

[cpp]  view plain  copy
  1. CV_WRAP HOGDescriptor() :   
  2.      winSize(64,128),                             // detect window   
  3.      blockSize(16,16),                            // block 大小   
  4.      blockStride(8,8),                            // overlap block的滑动步长   
  5.      cellSize(8,8),                               // cell 大小    
  6.      nbins(9),                                    // 直方图的bin个数   
  7.      derivAperture(1),                            // 微分算子核   
  8.      winSigma(-1),                                // 在window上进行高斯加权   
  9.      histogramNormType(HOGDescriptor::L2Hys),     // 直方图归一化类型   
  10.      L2HysThreshold(0.2),                         // L2-norm followed by clipping (limiting the maximum values of v to 0.2) and renormalising  
  11.      gammaCorrection(true),                       // Gamma校正,去除光照影响  
  12.      nlevels(HOGDescriptor::DEFAULT_NLEVELS)      // 分层数  



下面的两段代码采用OpenCV中的HOG行人检测类来完成对静态图片中的行人检测。


1)采用64*128 (像素为单位)的detect window


[cpp]  view plain  copy
  1. //  基于HOG特征的行人检测    
  2. //  Author:www.icvpr.com  
  3. //  Blog:  http://blog.csdn.net/icvpr    
  4.   
  5. #include <iostream>  
  6. #include <opencv2/opencv.hpp>  
  7.   
  8.   
  9. int main(int argc, char** argv)  
  10. {  
  11.     cv::Mat image = cv::imread("test.bmp");  
  12.     if (image.empty())  
  13.     {  
  14.         std::cout<<"read image failed"<<std::endl;  
  15.     }  
  16.   
  17.       
  18.     // 1. 定义HOG对象  
  19.     cv::HOGDescriptor hog; // 采用默认参数  
  20.       
  21.   
  22.     // 2. 设置SVM分类器  
  23.     hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());   // 采用已经训练好的行人检测分类器  
  24.   
  25.     // 3. 在测试图像上检测行人区域  
  26.     std::vector<cv::Rect> regions;  
  27.     hog.detectMultiScale(image, regions, 0, cv::Size(8,8), cv::Size(32,32), 1.05, 1);  
  28.   
  29.     // 显示  
  30.     for (size_t i = 0; i < regions.size(); i++)  
  31.     {  
  32.         cv::rectangle(image, regions[i], cv::Scalar(0,0,255), 2);  
  33.     }  
  34.   
  35.     cv::imshow("hog", image);  
  36.     cv::waitKey(0);  
  37.   
  38.     return 0;  
  39. }  


行人检测实验结果:

  





2)采用48*96(像素为单位)的detect window


[cpp]  view plain  copy
  1. //  基于HOG特征的行人检测      
  2. //  Author: http://blog.csdn.net/icvpr      
  3.     
  4. #include <iostream>    
  5. #include <opencv2/opencv.hpp>    
  6.     
  7.     
  8. int main(int argc, char** argv)    
  9. {    
  10.     cv::Mat image = cv::imread("test.bmp");    
  11.     if (image.empty())    
  12.     {    
  13.         std::cout<<"read image failed"<<std::endl;    
  14.     }    
  15.     
  16.         
  17.     // 1. 定义HOG对象    
  18.     cv::HOGDescriptor hog(cv::Size(48, 96), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9, 1,-1, cv::HOGDescriptor::L2Hys, 0.2, true, cv::HOGDescriptor::DEFAULT_NLEVELS);   
  19.         
  20.     
  21.     // 2. 设置SVM分类器    
  22.     hog.setSVMDetector(cv::HOGDescriptor::getDaimlerPeopleDetector());   // 采用已经训练好的行人检测分类器    
  23.     
  24.     // 3. 在测试图像上检测行人区域    
  25.     std::vector<cv::Rect> regions;    
  26.     hog.detectMultiScale(image, regions, 0, cv::Size(8,8), cv::Size(32,32), 1.05, 1);    
  27.     
  28.     // 显示    
  29.     for (size_t i = 0; i < regions.size(); i++)    
  30.     {    
  31.         cv::rectangle(image, regions[i], cv::Scalar(0,0,255), 2);    
  32.     }    
  33.     
  34.     cv::imshow("hog", image);    
  35.     cv::waitKey(0);    
  36.     
  37.     return 0;    
  38. }    



行人检测实验结果:

  



相关内容:www.icvpr.com

--------------------------------------------------------

< 转载请注明:http://blog.csdn.net/icvpr >


OpenCV中提供了HOG的行人检测(pedestrain detection)类。


cv::HOGDescriptor类的构造函数的各参数的定义:

[cpp]  view plain  copy
  1. CV_WRAP HOGDescriptor() :   
  2.      winSize(64,128),                             // detect window   
  3.      blockSize(16,16),                            // block 大小   
  4.      blockStride(8,8),                            // overlap block的滑动步长   
  5.      cellSize(8,8),                               // cell 大小    
  6.      nbins(9),                                    // 直方图的bin个数   
  7.      derivAperture(1),                            // 微分算子核   
  8.      winSigma(-1),                                // 在window上进行高斯加权   
  9.      histogramNormType(HOGDescriptor::L2Hys),     // 直方图归一化类型   
  10.      L2HysThreshold(0.2),                         // L2-norm followed by clipping (limiting the maximum values of v to 0.2) and renormalising  
  11.      gammaCorrection(true),                       // Gamma校正,去除光照影响  
  12.      nlevels(HOGDescriptor::DEFAULT_NLEVELS)      // 分层数  



下面的两段代码采用OpenCV中的HOG行人检测类来完成对静态图片中的行人检测。


1)采用64*128 (像素为单位)的detect window


[cpp]  view plain  copy
  1. //  基于HOG特征的行人检测    
  2. //  Author:www.icvpr.com  
  3. //  Blog:  http://blog.csdn.net/icvpr    
  4.   
  5. #include <iostream>  
  6. #include <opencv2/opencv.hpp>  
  7.   
  8.   
  9. int main(int argc, char** argv)  
  10. {  
  11.     cv::Mat image = cv::imread("test.bmp");  
  12.     if (image.empty())  
  13.     {  
  14.         std::cout<<"read image failed"<<std::endl;  
  15.     }  
  16.   
  17.       
  18.     // 1. 定义HOG对象  
  19.     cv::HOGDescriptor hog; // 采用默认参数  
  20.       
  21.   
  22.     // 2. 设置SVM分类器  
  23.     hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());   // 采用已经训练好的行人检测分类器  
  24.   
  25.     // 3. 在测试图像上检测行人区域  
  26.     std::vector<cv::Rect> regions;  
  27.     hog.detectMultiScale(image, regions, 0, cv::Size(8,8), cv::Size(32,32), 1.05, 1);  
  28.   
  29.     // 显示  
  30.     for (size_t i = 0; i < regions.size(); i++)  
  31.     {  
  32.         cv::rectangle(image, regions[i], cv::Scalar(0,0,255), 2);  
  33.     }  
  34.   
  35.     cv::imshow("hog", image);  
  36.     cv::waitKey(0);  
  37.   
  38.     return 0;  
  39. }  


行人检测实验结果:

  





2)采用48*96(像素为单位)的detect window


[cpp]  view plain  copy
  1. //  基于HOG特征的行人检测      
  2. //  Author: http://blog.csdn.net/icvpr      
  3.     
  4. #include <iostream>    
  5. #include <opencv2/opencv.hpp>    
  6.     
  7.     
  8. int main(int argc, char** argv)    
  9. {    
  10.     cv::Mat image = cv::imread("test.bmp");    
  11.     if (image.empty())    
  12.     {    
  13.         std::cout<<"read image failed"<<std::endl;    
  14.     }    
  15.     
  16.         
  17.     // 1. 定义HOG对象    
  18.     cv::HOGDescriptor hog(cv::Size(48, 96), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 9, 1,-1, cv::HOGDescriptor::L2Hys, 0.2, true, cv::HOGDescriptor::DEFAULT_NLEVELS);   
  19.         
  20.     
  21.     // 2. 设置SVM分类器    
  22.     hog.setSVMDetector(cv::HOGDescriptor::getDaimlerPeopleDetector());   // 采用已经训练好的行人检测分类器    
  23.     
  24.     // 3. 在测试图像上检测行人区域    
  25.     std::vector<cv::Rect> regions;    
  26.     hog.detectMultiScale(image, regions, 0, cv::Size(8,8), cv::Size(32,32), 1.05, 1);    
  27.     
  28.     // 显示    
  29.     for (size_t i = 0; i < regions.size(); i++)    
  30.     {    
  31.         cv::rectangle(image, regions[i], cv::Scalar(0,0,255), 2);    
  32.     }    
  33.     
  34.     cv::imshow("hog", image);    
  35.     cv::waitKey(0);    
  36.     
  37.     return 0;    
  38. }    



行人检测实验结果:

  



相关内容:www.icvpr.com

--------------------------------------------------------

< 转载请注明:http://blog.csdn.net/icvpr >


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值