#include<iostream>
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
/*Mat img;
vector<Rect> people;
img = imread("E:\\vs2013work\\20180305\\Pedestrian_Detection-master\\Test.jpg");
*///定义HOG对象,采用默认参数,或者按照下面的格式自己设置
//HOGDescriptor defaultHog;
(cv::Size(64, 128), 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);
设置SVM分类器,用默认分类器
//defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
对图像进行多尺度行人检测,返回结果为矩形框
//defaultHog.detectMultiScale(img, people, 0, Size(8, 8), Size(32, 32), 1.05, 2);
画长方形,框出行人
//for (int i = 0; i < people.size(); i++)
//{
// Rect r = people[i];
// rectangle(img, r.tl(), r.br(), Scalar(0, 0, 255), 3);
//}
/*namedWindow("检测行人", CV_WINDOW_AUTOSIZE);
imshow("检测行人", img);
*/
Mat img;
vector<Rect> people;
img = imread("E:\\vs2013work\\20180305\\Pedestrian_Detection-master\\Test.jpg", CV_LOAD_IMAGE_UNCHANGED);
if
(img.empty())
{
cout << "图像加载失败!"
<< endl;
//system("pause");
return
-1;
}
//定义HOG对象,采用默认参数,或者按照下面的格式自己设置
HOGDescriptor defaultHog;
(cv::Size(64, 128), 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);
//设置SVM分类器,用默认分类器
defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
//对图像进行多尺度行人检测,返回结果为矩形框
defaultHog.detectMultiScale(img, people, 0, Size(8, 8), Size(32, 32), 1.05, 2);
//画长方形,框出行人
for (int i = 0; i < people.size(); i++)
{
Rect r = people[i];
rectangle(img, r.tl(), r.br(), Scalar(0, 0, 255), 3);
}
//创建一个名字为MyWindow的窗口
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
//在MyWindow的窗中中显示存储在img中的图片
imshow("MyWindow", img);
//等待直到有键按下
waitKey(0);
//销毁MyWindow的窗口
destroyWindow("MyWindow");
return
0;
system("pause");
return 0;
}
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
/*Mat img;
vector<Rect> people;
img = imread("E:\\vs2013work\\20180305\\Pedestrian_Detection-master\\Test.jpg");
*///定义HOG对象,采用默认参数,或者按照下面的格式自己设置
//HOGDescriptor defaultHog;
(cv::Size(64, 128), 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);
设置SVM分类器,用默认分类器
//defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
对图像进行多尺度行人检测,返回结果为矩形框
//defaultHog.detectMultiScale(img, people, 0, Size(8, 8), Size(32, 32), 1.05, 2);
画长方形,框出行人
//for (int i = 0; i < people.size(); i++)
//{
// Rect r = people[i];
// rectangle(img, r.tl(), r.br(), Scalar(0, 0, 255), 3);
//}
/*namedWindow("检测行人", CV_WINDOW_AUTOSIZE);
imshow("检测行人", img);
*/
Mat img;
vector<Rect> people;
img = imread("E:\\vs2013work\\20180305\\Pedestrian_Detection-master\\Test.jpg", CV_LOAD_IMAGE_UNCHANGED);
if
(img.empty())
{
cout << "图像加载失败!"
<< endl;
//system("pause");
return
-1;
}
//定义HOG对象,采用默认参数,或者按照下面的格式自己设置
HOGDescriptor defaultHog;
(cv::Size(64, 128), 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);
//设置SVM分类器,用默认分类器
defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
//对图像进行多尺度行人检测,返回结果为矩形框
defaultHog.detectMultiScale(img, people, 0, Size(8, 8), Size(32, 32), 1.05, 2);
//画长方形,框出行人
for (int i = 0; i < people.size(); i++)
{
Rect r = people[i];
rectangle(img, r.tl(), r.br(), Scalar(0, 0, 255), 3);
}
//创建一个名字为MyWindow的窗口
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
//在MyWindow的窗中中显示存储在img中的图片
imshow("MyWindow", img);
//等待直到有键按下
waitKey(0);
//销毁MyWindow的窗口
destroyWindow("MyWindow");
return
0;
system("pause");
return 0;
}