#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的一个子区域中检测行人位置
//该子区域由一个矩形确定