使用opencv默认的hog行人检测器来检测视频中的行人

opencv中有训练好的hog行人检测器,可以直接用来做行人检测,下面是代码:

#include "stdafx.h"

#include <opencv2/core/core.hpp>  
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"

#include <opencv2/highgui/highgui.hpp>  

#include <vector>
using std::vector;

using namespace cv;


int _tmain(int argc, _TCHAR* argv[])
{
    Mat frame;
    Mat img;

    VideoWriter writer("VideoTest.avi", CV_FOURCC('D', 'I', 'V', 'X'), 25.0, Size(768, 576));  
    VideoCapture cap;

    vector<Rect> people;  

    //定义HOG对象,采用默认参数,或者按照下面的格式自己设置  
    HOGDescriptor defaultHog; 
    //设置SVM分类器,用默认分类器  
    defaultHog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());  

    int j = 0;

    cap.open("./vtest.avi");
    if( !cap.isOpened() )
    {
        return -1;
    }

    while(1)
    {
        j++;
        if(j>100)
        {
            break;
        }

        cap >> frame;
        if( frame.empty() )
            break;
        frame.copyTo(img);

        //对图像进行多尺度行人检测,返回结果为矩形框  
        defaultHog.detectMultiScale(img, people,0,Size(8,8),Size(0,0),1.03,2);  

        //画矩形,框出行人  
        for (int i = 0; i < people.size(); i++)  
        {  
            Rect r = people[i];  
            rectangle(img, r.tl(), r.br(), Scalar(0, 0, 255), 3);  
        }  

        writer << img;  
    }
    waitKey();

    return 0;
}

实际效果强差人意,而且感觉速度有点慢啊,debug运行了好久。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值