updated patch to bring in the first functions with "transparent API"

This commit is contained in:
Vadim Pisarevsky
2013-11-18 11:48:00 -05:00
parent bb4bf7a1f9
commit d914f20a4c
64 changed files with 13355 additions and 318 deletions

View File

@@ -11,7 +11,7 @@
using namespace std;
using namespace cv;
#define LOOP_NUM 10
#define LOOP_NUM 1
const static Scalar colors[] = { CV_RGB(0,0,255),
CV_RGB(0,128,255),
@@ -83,7 +83,7 @@ int main( int argc, const char** argv )
}
CvCapture* capture = 0;
Mat frame, frameCopy, image;
Mat frame, frameCopy0, frameCopy, image;
bool useCPU = cmd.get<bool>("s");
string inputName = cmd.get<string>("i");
@@ -129,16 +129,21 @@ int main( int argc, const char** argv )
if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
frame.copyTo( frameCopy0 );
else
flip( frame, frameCopy, 0 );
flip( frame, frameCopy0, 0 );
if( scale == 1)
frameCopy0.copyTo(frameCopy);
else
resize(frameCopy0, frameCopy, Size(), 1./scale, 1./scale, INTER_LINEAR);
work_end = 0;
if(useCPU)
detectCPU(frameCopy, faces, cpu_cascade, scale, false);
detectCPU(frameCopy, faces, cpu_cascade, 1, false);
else
detect(frameCopy, faces, cascade, scale, false);
detect(frameCopy, faces, cascade, 1, false);
Draw(frameCopy, faces, scale);
Draw(frameCopy, faces, 1);
if( waitKey( 10 ) >= 0 )
break;
}
@@ -150,6 +155,7 @@ int main( int argc, const char** argv )
vector<Rect> faces;
vector<Rect> ref_rst;
double accuracy = 0.;
work_end = 0;
for(int i = 0; i <= LOOP_NUM; i ++)
{
cout << "loop" << i << endl;
@@ -188,7 +194,7 @@ void detect( Mat& img, vector<Rect>& faces,
{
ocl::oclMat image(img);
ocl::oclMat gray, smallImg( cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );
if(calTime) workBegin();
workBegin();
ocl::cvtColor( image, gray, COLOR_BGR2GRAY );
ocl::resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR );
ocl::equalizeHist( smallImg, smallImg );
@@ -197,14 +203,14 @@ void detect( Mat& img, vector<Rect>& faces,
3, 0
|CASCADE_SCALE_IMAGE
, Size(30,30), Size(0, 0) );
if(calTime) workEnd();
workEnd();
}
void detectCPU( Mat& img, vector<Rect>& faces,
CascadeClassifier& cascade,
double scale, bool calTime)
{
if(calTime) workBegin();
workBegin();
Mat cpu_gray, cpu_smallImg( cvRound (img.rows/scale), cvRound(img.cols/scale), CV_8UC1 );
cvtColor(img, cpu_gray, COLOR_BGR2GRAY);
resize(cpu_gray, cpu_smallImg, cpu_smallImg.size(), 0, 0, INTER_LINEAR);
@@ -212,13 +218,15 @@ void detectCPU( Mat& img, vector<Rect>& faces,
cascade.detectMultiScale(cpu_smallImg, faces, 1.1,
3, 0 | CASCADE_SCALE_IMAGE,
Size(30, 30), Size(0, 0));
if(calTime) workEnd();
workEnd();
}
void Draw(Mat& img, vector<Rect>& faces, double scale)
{
int i = 0;
putText(img, format("fps: %.1f", 1000./getTime()), Point(450, 50),
FONT_HERSHEY_SIMPLEX, 1, Scalar(0,255,0), 3);
for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++, i++ )
{
Point center;
@@ -229,7 +237,7 @@ void Draw(Mat& img, vector<Rect>& faces, double scale)
radius = cvRound((r->width + r->height)*0.25*scale);
circle( img, center, radius, color, 3, 8, 0 );
}
imwrite( outputName, img );
//imwrite( outputName, img );
if(abs(scale-1.0)>.001)
{
resize(img, img, Size((int)(img.cols/scale), (int)(img.rows/scale)));