Demo2:视频人体检测 (图片hog参数,效果还可以了)






#include<opencv2\opencv.hpp>
using namespace cv;
int main()
{
	Mat img = imread("11.jpg");

	vector<Rect> found, found_filtered;
    cv::HOGDescriptor people_dectect_hog;
	people_dectect_hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
	people_dectect_hog.detectMultiScale(img, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);
	 
	size_t i, j;
    for (i = 0; i < found.size(); i++ )
        {
            Rect r = found[i];

            //下面的这个for语句是找出所有没有嵌套的矩形框r,并放入found_filtered中,如果有嵌套的
           //话,则取外面最大的那个矩形框放入found_filtered中
            for(j = 0; j <found.size(); j++)
                if(j != i && (r&found[j])==r)
                    break;
            if(j == found.size())
               found_filtered.push_back(r);
        }
	 //在图片img上画出矩形框,因为hog检测出的矩形框比实际人体框要稍微大些,所以这里需要
    //做一些调整
    for(i = 0; i <found_filtered.size(); 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(img, r.tl(), r.br(), Scalar(0, 255, 0), 3);
        }
    imwrite("hog_test_result.jpg", img);


	Mat img2 = imread("hog_test_result.jpg");




	imshow("测试图片",img2);
	waitKey();
	return 0;

}



猜你喜欢

转载自blog.csdn.net/u011473714/article/details/88244637