行人检测(图片)

//本代码只能在Release模式下运行
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
	Mat image=imread("1.jpg");
	if (image.empty())
	{
		cout << "--------- 加载图像失败 ----------";
		return -1;
	}
	vector<Rect> found;
	
	HOGDescriptor defaultHog;
	//设置线性SVM分类器系数
	defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
	//多尺度检测目标
	defaultHog.detectMultiScale(image,found,0,Size(8,8), Size(32,32),1.1,2.0,false);
	// 画出长方形,框出人
	for (int i = 0; i < found.size(); i++) 
	{
		Rect r=found[i];
		rectangle(image, r.tl(), r.br(), Scalar(0,255,0), 1,CV_AA);
	}
	cout << "people size:" << found.size() <<endl;
	namedWindow("Detect pedestrain", WINDOW_AUTOSIZE);
	imshow("Detect pedestrain", image);
	waitKey(0);
		
	return 0;
}

Release模式运行效果图 

《OpenCV:行人检测简单示例》

Debug模式运行效果图 

《OpenCV:行人检测简单示例》

相关文章:

  • 2021-07-17
  • 2022-02-13
  • 2021-09-10
  • 2021-09-20
  • 2021-11-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2021-10-06
  • 2022-01-23
  • 2021-06-21
  • 2021-11-30
  • 2022-12-23
相关资源
相似解决方案