opencv行人跟踪检测

opencv行人跟踪检测_第1张图片

#include  

#include  
#include  
#include  
#include  
#include  
#include  


using namespace std;
using namespace cv;


int main()
{


Mat src = imread("3123.jpg");
HOGDescriptor hog;//HOG特征检测器  
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());//设置SVM分类器为默认参数  
vector found, found_filtered;//矩形框数组  
hog.detectMultiScale(src, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);//对图像进行多尺度检测,检测窗口移动步长为(8,8)  


cout << "矩形个数:" << found.size() << endl;
//找出所有没有嵌套的矩形框r,并放入found_filtered中,如果有嵌套的话,则取外面最大的那个矩形框放入found_filtered中  
for (int i = 0; i < found.size(); i++)
{
Rect r = found[i];
int j;
for (j=0; j < found.size(); j++)
if (j != i && (r & found[j]) == r)
break;
if (j == found.size())
found_filtered.push_back(r);
}
cout << "过滤后矩形的个数:" << found_filtered.size() << endl;


//画矩形框
for (int i = 0; i {
Rect r = found_filtered[i];
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);
rectangle(src, r.tl(), r.br(), Scalar(0, 255, 0), 3);
}


imwrite("ImgProcessed.jpg", src);
namedWindow("src", 0);
imshow("src", src);
waitKey();




system("pause");

}

当有其他物体叫人体挡住时,效果不明显

opencv行人跟踪检测_第2张图片

你可能感兴趣的:(opencv行人跟踪检测)