#include<cv.h>
#include<highgui.h>
#include<ml.h>
#include<string>
#include<vector>
#include<string>
#include<iostream>
#include<fstream>
using namespace std;
using namespace cv;
string cascadeName = "./cascade.xml";
int main(int argc,char** argv)
{
CascadeClassifier cascade;
vector<string> ImgList;
vector<Rect> rects;
vector<Rect>::const_iterator pRect;
double scale = 1;
Mat image;
double t;
if(!cascade.load(cascadeName))
{
cerr<<"ERROR: Could not load classifier cascsde"<<endl;
return 0;
}
if(argv[1] != NULL)
{
ifstream test_data("test.txt");
string buf;
while(test_data)
{
if(getline(test_data,buf))
{
ImgList.push_back(buf);
}
}
test_data.close();
}
else
{
return 0;
}
for(int i = 1; i < ImgList.size(); i++)
{
image = imread(ImgList[i].c_str());
if(!image.empty())
{
Mat gray,smallImg(cvRound(image.rows/scale),cvRound(image.cols/scale),CV_8UC1);
cvtColor(image,gray,CV_BGR2GRAY);
resize(gray,smallImg,smallImg.size(),0,0,INTER_LINEAR);
equalizeHist(smallImg,smallImg);
rects.clear();
printf("begin...\n");
t = (double)cvGetTickCount();
cascade.detectMultiScale(smallImg,rects,1.1,2,0,Size(20,20),Size(30,30));
t=(double)cvGetTickCount()-t;
printf("detection time = %g ms\n\n",t/((double)cvGetTickFrequency()*1000.));
for(pRect = rects.begin();pRect != rects.end(); pRect++)
{
rectangle(image,cvPoint(pRect->x,pRect->y),cvPoint(pRect->x+pRect->width,pRect->y+pRect->height),cvScalar(0,255,0));
}
imwrite(ImgList[i].c_str(),image);
}
}
return 0;
}