2012-10-12 01:56:36 +08:00
|
|
|
#include "perf_precomp.hpp"
|
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
#define SC_PERF_TEST_P(fixture, name, params) \
|
2012-10-12 01:56:36 +08:00
|
|
|
class fixture##_##name : public fixture {\
|
|
|
|
public:\
|
|
|
|
fixture##_##name() {}\
|
|
|
|
protected:\
|
2012-10-15 22:13:58 +08:00
|
|
|
virtual void __cpu();\
|
2012-10-12 01:56:36 +08:00
|
|
|
virtual void __gpu();\
|
|
|
|
virtual void PerfTestBody();\
|
|
|
|
};\
|
2012-12-19 20:44:34 +08:00
|
|
|
TEST_P(fixture##_##name, name /*perf*/){ RunPerfTestBody(); }\
|
2012-10-12 01:56:36 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/*none*/, fixture##_##name, params);\
|
2012-12-19 20:44:34 +08:00
|
|
|
void fixture##_##name::PerfTestBody() { if (PERF_RUN_GPU()) __gpu(); else __cpu(); }
|
2012-10-12 01:56:36 +08:00
|
|
|
|
|
|
|
#define RUN_CPU(fixture, name)\
|
|
|
|
void fixture##_##name::__cpu()
|
|
|
|
|
|
|
|
#define RUN_GPU(fixture, name)\
|
|
|
|
void fixture##_##name::__gpu()
|
|
|
|
|
2012-10-16 01:55:57 +08:00
|
|
|
#define NO_CPU(fixture, name)\
|
2012-10-12 01:56:36 +08:00
|
|
|
void fixture##_##name::__cpu() { FAIL() << "No such CPU implementation analogy";}
|
|
|
|
|
2012-10-15 22:13:58 +08:00
|
|
|
namespace {
|
|
|
|
struct DetectionLess
|
|
|
|
{
|
2012-11-10 04:49:51 +08:00
|
|
|
bool operator()(const cv::gpu::SCascade::Detection& a,
|
|
|
|
const cv::gpu::SCascade::Detection& b) const
|
2012-10-15 22:13:58 +08:00
|
|
|
{
|
2013-01-23 18:57:51 +08:00
|
|
|
if (a.x != b.x) return a.x < b.x;
|
2012-10-15 22:13:58 +08:00
|
|
|
else if (a.y != b.y) return a.y < b.y;
|
|
|
|
else if (a.w != b.w) return a.w < b.w;
|
|
|
|
else return a.h < b.h;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
cv::Mat sortDetections(cv::gpu::GpuMat& objects)
|
|
|
|
{
|
|
|
|
cv::Mat detections(objects);
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
typedef cv::gpu::SCascade::Detection Detection;
|
2012-10-15 22:13:58 +08:00
|
|
|
Detection* begin = (Detection*)(detections.ptr<char>(0));
|
|
|
|
Detection* end = (Detection*)(detections.ptr<char>(0) + detections.cols);
|
|
|
|
std::sort(begin, end, DetectionLess());
|
|
|
|
|
|
|
|
return detections;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 01:56:36 +08:00
|
|
|
|
|
|
|
typedef std::tr1::tuple<std::string, std::string> fixture_t;
|
2012-11-10 04:49:51 +08:00
|
|
|
typedef perf::TestBaseWithParam<fixture_t> SCascadeTest;
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
SC_PERF_TEST_P(SCascadeTest, detect,
|
2012-10-12 01:56:36 +08:00
|
|
|
testing::Combine(
|
2013-01-23 18:57:51 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"),
|
|
|
|
std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")),
|
|
|
|
testing::Values(std::string("cv/cascadeandhog/images/image_00000000_0.png"))))
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
RUN_GPU(SCascadeTest, detect)
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::Mat cpu = readImage (GET_PARAM(1));
|
|
|
|
ASSERT_FALSE(cpu.empty());
|
|
|
|
cv::gpu::GpuMat colored(cpu);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::SCascade cascade;
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
|
|
|
|
ASSERT_TRUE(fs.isOpened());
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
|
|
|
|
rois.setTo(1);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
TEST_CYCLE()
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
2012-12-19 15:13:31 +08:00
|
|
|
|
|
|
|
SANITY_CHECK(sortDetections(objectBoxes));
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
NO_CPU(SCascadeTest, detect)
|
2012-10-12 01:56:36 +08:00
|
|
|
|
|
|
|
static cv::Rect getFromTable(int idx)
|
|
|
|
{
|
|
|
|
static const cv::Rect rois[] =
|
|
|
|
{
|
2012-11-10 04:49:51 +08:00
|
|
|
cv::Rect( 65 * 4, 20 * 4, 35 * 4, 80 * 4),
|
|
|
|
cv::Rect( 95 * 4, 35 * 4, 45 * 4, 40 * 4),
|
|
|
|
cv::Rect( 45 * 4, 35 * 4, 45 * 4, 40 * 4),
|
|
|
|
cv::Rect( 25 * 4, 27 * 4, 50 * 4, 45 * 4),
|
|
|
|
cv::Rect(100 * 4, 50 * 4, 45 * 4, 40 * 4),
|
|
|
|
|
|
|
|
cv::Rect( 60 * 4, 30 * 4, 45 * 4, 40 * 4),
|
|
|
|
cv::Rect( 40 * 4, 55 * 4, 50 * 4, 40 * 4),
|
|
|
|
cv::Rect( 48 * 4, 37 * 4, 72 * 4, 80 * 4),
|
|
|
|
cv::Rect( 48 * 4, 32 * 4, 85 * 4, 58 * 4),
|
|
|
|
cv::Rect( 48 * 4, 0 * 4, 32 * 4, 27 * 4)
|
2012-10-12 01:56:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return rois[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::tr1::tuple<std::string, std::string, int> roi_fixture_t;
|
2012-11-10 04:49:51 +08:00
|
|
|
typedef perf::TestBaseWithParam<roi_fixture_t> SCascadeTestRoi;
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
SC_PERF_TEST_P(SCascadeTestRoi, detectInRoi,
|
2012-10-12 01:56:36 +08:00
|
|
|
testing::Combine(
|
2013-01-23 18:57:51 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"),
|
|
|
|
std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")),
|
|
|
|
testing::Values(std::string("cv/cascadeandhog/images/image_00000000_0.png")),
|
2012-10-12 01:56:36 +08:00
|
|
|
testing::Range(0, 5)))
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
RUN_GPU(SCascadeTestRoi, detectInRoi)
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::Mat cpu = readImage (GET_PARAM(1));
|
|
|
|
ASSERT_FALSE(cpu.empty());
|
|
|
|
cv::gpu::GpuMat colored(cpu);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::SCascade cascade;
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
|
|
|
|
ASSERT_TRUE(fs.isOpened());
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
|
|
|
|
rois.setTo(0);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
int nroi = GET_PARAM(2);
|
|
|
|
cv::RNG rng;
|
|
|
|
for (int i = 0; i < nroi; ++i)
|
|
|
|
{
|
|
|
|
cv::Rect r = getFromTable(rng(10));
|
|
|
|
cv::gpu::GpuMat sub(rois, r);
|
|
|
|
sub.setTo(1);
|
|
|
|
}
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-12-18 20:59:00 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
TEST_CYCLE()
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
2012-12-19 15:13:31 +08:00
|
|
|
|
|
|
|
SANITY_CHECK(sortDetections(objectBoxes));
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
NO_CPU(SCascadeTestRoi, detectInRoi)
|
2012-10-12 01:56:36 +08:00
|
|
|
|
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
SC_PERF_TEST_P(SCascadeTestRoi, detectEachRoi,
|
2012-10-12 01:56:36 +08:00
|
|
|
testing::Combine(
|
2013-01-23 18:57:51 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"),
|
|
|
|
std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")),
|
|
|
|
testing::Values(std::string("cv/cascadeandhog/images/image_00000000_0.png")),
|
2012-10-12 01:56:36 +08:00
|
|
|
testing::Range(0, 10)))
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
RUN_GPU(SCascadeTestRoi, detectEachRoi)
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::Mat cpu = readImage (GET_PARAM(1));
|
|
|
|
ASSERT_FALSE(cpu.empty());
|
|
|
|
cv::gpu::GpuMat colored(cpu);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::SCascade cascade;
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
|
|
|
|
ASSERT_TRUE(fs.isOpened());
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::GpuMat objectBoxes(1, 16384 * 20, CV_8UC1), rois(colored.size(), CV_8UC1);
|
|
|
|
rois.setTo(0);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
int idx = GET_PARAM(2);
|
|
|
|
cv::Rect r = getFromTable(idx);
|
|
|
|
cv::gpu::GpuMat sub(rois, r);
|
|
|
|
sub.setTo(1);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-10-12 01:56:36 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
TEST_CYCLE()
|
2012-10-12 01:56:36 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes);
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
2012-12-19 15:13:31 +08:00
|
|
|
|
|
|
|
SANITY_CHECK(sortDetections(objectBoxes));
|
2012-10-12 01:56:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
NO_CPU(SCascadeTestRoi, detectEachRoi)
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
SC_PERF_TEST_P(SCascadeTest, detectOnIntegral,
|
2012-10-16 01:55:57 +08:00
|
|
|
testing::Combine(
|
2013-01-23 18:57:51 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"),
|
|
|
|
std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")),
|
2012-10-16 01:55:57 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/integrals.xml"))))
|
|
|
|
|
2012-12-19 20:44:34 +08:00
|
|
|
static std::string itoa(long i)
|
|
|
|
{
|
|
|
|
static char s[65];
|
|
|
|
sprintf(s, "%ld", i);
|
|
|
|
return std::string(s);
|
|
|
|
}
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2012-11-10 04:49:51 +08:00
|
|
|
RUN_GPU(SCascadeTest, detectOnIntegral)
|
2012-10-16 01:55:57 +08:00
|
|
|
{
|
2013-01-23 18:57:51 +08:00
|
|
|
cv::Mat cpu = readImage ("cv/cascadeandhog/images/image_00000000_0.png");
|
|
|
|
ASSERT_FALSE(cpu.empty());
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
cv::ICFPreprocessor preprocessor;
|
|
|
|
cv::Mat test_res(cpu.rows / 4 * 10 + 1, cpu.cols / 4 + 1, CV_8UC1);
|
|
|
|
preprocessor.apply(cpu,test_res);
|
2012-11-10 04:49:51 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::SCascade cascade;
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
|
|
|
|
ASSERT_TRUE(fs.isOpened());
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
|
|
|
|
rois.setTo(1);
|
2012-10-16 01:55:57 +08:00
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
cv::gpu::GpuMat hogluv(test_res);
|
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(hogluv, rois, objectBoxes);
|
2012-12-18 20:59:00 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
TEST_CYCLE()
|
2012-12-18 20:59:00 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(hogluv, rois, objectBoxes);
|
2012-12-18 20:59:00 +08:00
|
|
|
}
|
2012-12-19 15:13:31 +08:00
|
|
|
|
|
|
|
SANITY_CHECK(sortDetections(objectBoxes));
|
2012-10-16 01:55:57 +08:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:59:09 +08:00
|
|
|
NO_CPU(SCascadeTest, detectOnIntegral)
|
|
|
|
|
2013-01-23 18:57:51 +08:00
|
|
|
SC_PERF_TEST_P(SCascadeTest, detectStream,
|
2012-11-10 07:59:09 +08:00
|
|
|
testing::Combine(
|
2013-01-23 18:57:51 +08:00
|
|
|
testing::Values(std::string("cv/cascadeandhog/cascades/inria_caltech-17.01.2013.xml"),
|
|
|
|
std::string("cv/cascadeandhog/cascades/sc_cvpr_2012_to_opencv_new_format.xml")),
|
|
|
|
testing::Values(std::string("cv/cascadeandhog/images/image_00000000_0.png"))))
|
2012-11-10 07:59:09 +08:00
|
|
|
|
|
|
|
RUN_GPU(SCascadeTest, detectStream)
|
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::Mat cpu = readImage (GET_PARAM(1));
|
|
|
|
ASSERT_FALSE(cpu.empty());
|
|
|
|
cv::gpu::GpuMat colored(cpu);
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::SCascade cascade;
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::FileStorage fs(perf::TestBase::getDataPath(GET_PARAM(0)), cv::FileStorage::READ);
|
|
|
|
ASSERT_TRUE(fs.isOpened());
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
|
|
|
|
rois.setTo(1);
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cv::gpu::Stream s;
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes, s);
|
2012-11-10 07:59:09 +08:00
|
|
|
|
2012-12-19 15:13:31 +08:00
|
|
|
TEST_CYCLE()
|
2012-12-18 20:59:00 +08:00
|
|
|
{
|
2012-12-19 15:13:31 +08:00
|
|
|
cascade.detect(colored, rois, objectBoxes, s);
|
2012-12-18 20:59:00 +08:00
|
|
|
}
|
2012-12-19 15:13:31 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CUDA
|
|
|
|
cudaDeviceSynchronize();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SANITY_CHECK(sortDetections(objectBoxes));
|
2012-11-10 07:59:09 +08:00
|
|
|
}
|
|
|
|
|
2012-11-27 22:43:17 +08:00
|
|
|
NO_CPU(SCascadeTest, detectStream)
|
2013-01-23 18:57:51 +08:00
|
|
|
|
|
|
|
#undef SC_PERF_TEST_P
|