diff --git a/samples/ocl/facedetect.cpp b/samples/ocl/facedetect.cpp index 10c6c4f4d2..fbb08cb1e5 100644 --- a/samples/ocl/facedetect.cpp +++ b/samples/ocl/facedetect.cpp @@ -5,10 +5,16 @@ #include #include +#if defined(_MSC_VER) && (_MSC_VER >= 1700) + # include +#endif + using namespace std; using namespace cv; #define LOOP_NUM 10 +///////////////////////////single-threading faces detecting/////////////////////////////// + const static Scalar colors[] = { CV_RGB(0,0,255), CV_RGB(0,128,255), CV_RGB(0,255,255), @@ -22,7 +28,7 @@ const static Scalar colors[] = { CV_RGB(0,0,255), int64 work_begin = 0; int64 work_end = 0; -string outputName; +string inputName, outputName, cascadeName; static void workBegin() { @@ -58,41 +64,17 @@ static void Draw(Mat& img, vector& faces, double scale); // Else if will return (total diff of each cpu and gpu rects covered pixels)/(total cpu rects covered pixels) double checkRectSimilarity(Size sz, vector& cpu_rst, vector& gpu_rst); -int main( int argc, const char** argv ) +static int facedetect_one_thread(bool useCPU, double scale ) { - const char* keys = - "{ h | help | false | print help message }" - "{ i | input | | specify input image }" - "{ t | template | haarcascade_frontalface_alt.xml |" - " specify template file path }" - "{ c | scale | 1.0 | scale image }" - "{ s | use_cpu | false | use cpu or gpu to process the image }" - "{ o | output | facedetect_output.jpg |" - " specify output image save path(only works when input is images) }"; - - CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) - { - cout << "Usage : facedetect [options]" << endl; - cout << "Available options:" << endl; - cmd.printParams(); - return EXIT_SUCCESS; - } - CvCapture* capture = 0; Mat frame, frameCopy, image; - bool useCPU = cmd.get("s"); - string inputName = cmd.get("i"); - outputName = cmd.get("o"); - string cascadeName = cmd.get("t"); - double scale = cmd.get("c"); ocl::OclCascadeClassifier cascade; CascadeClassifier cpu_cascade; if( !cascade.load( cascadeName ) || !cpu_cascade.load(cascadeName) ) { - cout << "ERROR: Could not load classifier cascade" << endl; + cout << "ERROR: Could not load classifier cascade: " << cascadeName << endl; return EXIT_FAILURE; } @@ -176,9 +158,114 @@ int main( int argc, const char** argv ) } cvDestroyWindow("result"); + std::cout<< "single-threaded sample has finished" <= 1700) + +#define MAX_THREADS 10 + +static void detectFaces(std::string fileName) +{ + ocl::OclCascadeClassifier cascade; + if(!cascade.load(cascadeName)) + { + std::cout << "ERROR: Could not load classifier cascade: " << cascadeName << std::endl; + return; + } + + Mat img = imread(fileName, CV_LOAD_IMAGE_COLOR); + if (img.empty()) + { + std::cout << "cann't open file " + fileName < oclfaces; + cascade.detectMultiScale(d_img, oclfaces, 1.1, 3, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30), Size(0, 0)); + + for(unsigned int i = 0; i threads; + for(int i = 0; i= 1 }"; + + CommandLineParser cmd(argc, argv, keys); + if (cmd.get("help")) + { + cout << "Usage : facedetect [options]" << endl; + cout << "Available options:" << endl; + cmd.printParams(); + return EXIT_SUCCESS; + } + bool useCPU = cmd.get("s"); + inputName = cmd.get("i"); + outputName = cmd.get("o"); + cascadeName = cmd.get("t"); + double scale = cmd.get("c"); + int n = cmd.get("n"); + + if(n > 1) + { +#if defined(_MSC_VER) && (_MSC_VER >= 1700) + std::cout<<"multi-threaded sample is running" <& faces, ocl::OclCascadeClassifier& cascade, double scale, bool calTime)