opencv hog svm java_opencv+hog+svm行人检测自己训练

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

using namespace cv;

//常量定义

char IMG_PATH_TEXT[]="E:/INRIAPerson/color/img_path.txt";   //图像路径

//char IMG_PATH_TEXT[]="E:/研究生课件/机器视觉/Project/Data/pictures";   //图像路径

//const int START_FRAME=243;    //开始跟踪的帧243   ||   413

//const int END_FRAME=290;      //结束跟踪的帧290   ||   480

const int WINHEIGHT=180;      //图像高度

const int WINWIDTH=320;       //图像宽度

const int ROIWIDTH=160;       //ROI高度

const int ROIHEIGHT=160;      //ROI宽度

const Scalar green(0,255,0);

const Scalar red(0,0,255);

const Scalar blue(255,0,0);

const string DETECT_WINNAME="Detect Window";

const string TRACKER_WINNAME="Track Window";

Mat img(WINHEIGHT,WINWIDTH,CV_8UC3);   //the Mat storage the image

Mat blackboard(WINHEIGHT,WINWIDTH,CV_8UC3);

const cv::Rect WHOLEIMG(0,0,WINWIDTH-2,WINHEIGHT-2);

const int STATE_NUM=4;

const int MEASURE_NUM=2;

//使用HOG在img图像中检测行人位置

//返回的矩阵vector为矩阵位置

//返回检测时间

void DetectPedestrian(vector<:rect>& found_filtered,const HOGDescriptor& hog,

double* time=NULL)

{

found_filtered.clear ();

vector<:rect> found;

//hog detector get the cv::Rect with pedestrian

if(time!=NULL)

*time=(double)getTickCount();

hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);

if(time!=NULL)

{

*time=(double)getTickCount()-*time;

*time /= getTickFrequency();

}

//if the cv::Rect overlap

size_t i, j;

for( i = 0; i < found.size(); i++ )

{

cv::Rect r = found[i];

for( j = 0; j < found.size(); j++ )

if( j != i && (r & found[j]) == r)

break;

if( j == found.size() )

found_filtered.push_back(r);

}

for( i = 0; i < found_filtered.size(); i++ )

{

cv::Rect r = found_filtered[i];

// the HOG detector returns slightly larger rectangles than the real objects.

// so we slightly shrink the rectangles to get a nicer output.

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);

//found_filtered[i]=r;

cv::rectangle (img,r,green,3);

}

std::cout<

}

//重载函数,在img的一个子区域中检测行人位置

//该子区域由一个矩形确定

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值