perf_cascades.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "../perf_precomp.hpp"
  2. #include <opencv2/imgproc.hpp>
  3. #include "opencv2/ts/ocl_perf.hpp"
  4. namespace opencv_test
  5. {
  6. using namespace perf;
  7. typedef tuple<std::string, std::string, int> Cascade_Image_MinSize_t;
  8. typedef perf::TestBaseWithParam<Cascade_Image_MinSize_t> Cascade_Image_MinSize;
  9. #ifdef HAVE_OPENCL
  10. OCL_PERF_TEST_P(Cascade_Image_MinSize, CascadeClassifier,
  11. testing::Combine(
  12. testing::Values( string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt.xml"),
  13. string("cv/cascadeandhog/cascades/haarcascade_frontalface_alt2.xml"),
  14. string("cv/cascadeandhog/cascades/lbpcascade_frontalface.xml") ),
  15. testing::Values( string("cv/shared/lena.png"),
  16. string("cv/cascadeandhog/images/bttf301.png"),
  17. string("cv/cascadeandhog/images/class57.png") ),
  18. testing::Values(30, 64, 90) ) )
  19. {
  20. const string cascadePath = get<0>(GetParam());
  21. const string imagePath = get<1>(GetParam());
  22. int min_size = get<2>(GetParam());
  23. Size minSize(min_size, min_size);
  24. CascadeClassifier cc( getDataPath(cascadePath) );
  25. if (cc.empty())
  26. FAIL() << "Can't load cascade file: " << getDataPath(cascadePath);
  27. Mat img = imread(getDataPath(imagePath), IMREAD_GRAYSCALE);
  28. if (img.empty())
  29. FAIL() << "Can't load source image: " << getDataPath(imagePath);
  30. vector<Rect> faces;
  31. equalizeHist(img, img);
  32. declare.in(img).time(60);
  33. UMat uimg = img.getUMat(ACCESS_READ);
  34. while(next())
  35. {
  36. faces.clear();
  37. cvtest::ocl::perf::safeFinish();
  38. startTimer();
  39. cc.detectMultiScale(uimg, faces, 1.1, 3, 0, minSize);
  40. stopTimer();
  41. }
  42. sort(faces.begin(), faces.end(), comparators::RectLess());
  43. SANITY_CHECK(faces, min_size/5);
  44. }
  45. #endif //HAVE_OPENCL
  46. } // namespace