added minMaxLoc, cornerHarris, remap and dft performance tests

This commit is contained in:
Alexey Spizhevoy 2011-01-25 09:54:17 +00:00
parent 8644c6f86b
commit 72b0ec90b9
3 changed files with 96 additions and 11 deletions

View File

@ -14,6 +14,15 @@ void Test::gen(Mat& mat, int rows, int cols, int type)
}
void Test::gen(Mat& mat, int rows, int cols, int type, double low, double high)
{
mat.create(rows, cols, type);
RNG rng(0);
rng.fill(mat, RNG::UNIFORM, Scalar::all(low), Scalar::all(high));
}
void TestSystem::run()
{
cout << setiosflags(ios_base::left);
@ -46,13 +55,12 @@ void TestSystem::flush()
int cpu_time = static_cast<int>(cpu_elapsed_ / getTickFrequency() * 1000.0);
int gpu_time = static_cast<int>(gpu_elapsed_ / getTickFrequency() * 1000.0);
double speedup = static_cast<double>(cpu_time) / gpu_time;
speedup_total_ += speedup;
cpu_elapsed_ = 0;
gpu_elapsed_ = 0;
double speedup = static_cast<double>(cpu_time) / std::max(1, gpu_time);
speedup_total_ += speedup;
cout << " " << setiosflags(ios_base::fixed | ios_base::left);
stringstream stream;

View File

@ -15,6 +15,7 @@ public:
const std::string& name() const { return name_; }
void gen(cv::Mat& mat, int rows, int cols, int type);
void gen(cv::Mat& mat, int rows, int cols, int type, double low, double high);
virtual void run() = 0;
@ -83,7 +84,7 @@ private:
#define TEST(name) \
struct name##_test: public Test \
struct name##_test: Test \
{ \
name##_test(): Test(#name) { TestSystem::instance()->add(this); } \
void run(); \

View File

@ -8,30 +8,30 @@ using namespace cv;
TEST(matchTemplate)
{
Mat image, templ, result;
gen(image, 3000, 3000, CV_8U);
gen(image, 3000, 3000, CV_32F);
gpu::GpuMat d_image(image), d_templ, d_result;
for (int templ_size = 5; templ_size <= 1000; templ_size *= 2)
{
SUBTEST << "img 3000, templ " << templ_size << ", 8U, SQDIFF";
SUBTEST << "img " << image.rows << ", templ " << templ_size << ", 32F, CCORR";
gen(templ, templ_size, templ_size, CV_8U);
gen(templ, templ_size, templ_size, CV_32F);
CPU_ON;
matchTemplate(image, templ, result, CV_TM_SQDIFF);
matchTemplate(image, templ, result, CV_TM_CCORR);
CPU_OFF;
d_templ = templ;
GPU_ON;
gpu::matchTemplate(d_image, d_templ, d_result, CV_TM_SQDIFF);
gpu::matchTemplate(d_image, d_templ, d_result, CV_TM_CCORR);
GPU_OFF;
}
}
TEST(minMaxLoc)
TEST(minMaxLoc)
{
Mat src;
gpu::GpuMat d_src;
@ -55,4 +55,80 @@ TEST(minMaxLoc)
gpu::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
GPU_OFF;
}
}
TEST(remap)
{
Mat src, dst, xmap, ymap;
gpu::GpuMat d_src, d_dst, d_xmap, d_ymap;
for (int size = 1000; size <= 8000; size *= 2)
{
SUBTEST << "img " << size << " and 8UC1, 32FC1 maps";
gen(src, size, size, CV_8UC1);
gen(xmap, size, size, CV_32FC1, 0, size);
gen(ymap, size, size, CV_32FC1, 0, size);
CPU_ON;
remap(src, dst, xmap, ymap, INTER_LINEAR);
CPU_OFF;
d_src = src;
d_xmap = xmap;
d_ymap = ymap;
GPU_ON;
gpu::remap(d_src, d_dst, d_xmap, d_ymap);
GPU_OFF;
}
}
TEST(dft)
{
Mat src, dst;
gpu::GpuMat d_src, d_dst;
for (int size = 1000; size <= 4000; size += 1000)
{
SUBTEST << "size " << size << ", 32FC2, complex-to-complex";
gen(src, size, size, CV_32FC2);
CPU_ON;
dft(src, dst);
CPU_OFF;
d_src = src;
GPU_ON;
gpu::dft(d_src, d_dst, Size(size, size));
GPU_OFF;
}
}
TEST(cornerHarris)
{
Mat src, dst;
gpu::GpuMat d_src, d_dst;
for (int size = 2000; size <= 4000; size *= 2)
{
SUBTEST << "size " << size << ", 32FC1";
gen(src, size, size, CV_32FC1);
CPU_ON;
cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT101);
CPU_OFF;
d_src = src;
GPU_ON;
gpu::cornerHarris(d_src, d_dst, 5, 7, 0.1);
GPU_OFF;
}
}