added SURF perf. test, added working dir field (can be changed via CMD args)

This commit is contained in:
Alexey Spizhevoy 2011-01-26 11:37:54 +00:00
parent 344db91676
commit ba32b447ee
3 changed files with 127 additions and 24 deletions

View File

@ -1,4 +1,5 @@
#include <iomanip>
#include <stdexcept>
#include "performance.h"
using namespace std;
@ -25,8 +26,14 @@ void TestSystem::run()
(*it)->run();
flushSubtestData();
}
catch (const cv::Exception&)
catch (const Exception&)
{
// Message is printed via callback
resetSubtestData();
}
catch (const runtime_error& e)
{
printError(e.what());
resetSubtestData();
}
}
@ -35,6 +42,12 @@ void TestSystem::run()
}
void TestSystem::setWorkingDir(const string& val)
{
working_dir_ = val;
}
void TestSystem::flushSubtestData()
{
if (!can_flush_)
@ -43,7 +56,7 @@ void TestSystem::flushSubtestData()
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) / std::max(1, gpu_time);
double speedup = static_cast<double>(cpu_elapsed_) / gpu_elapsed_;
speedup_total_ += speedup;
printItem(cpu_time, gpu_time, speedup);
@ -57,7 +70,7 @@ void TestSystem::printHeading()
{
cout << setiosflags(ios_base::left);
cout << TAB << setw(10) << "CPU, ms" << setw(10) << "GPU, ms"
<< setw(10) << "SPEEDUP"
<< setw(14) << "SPEEDUP"
<< "DESCRIPTION\n";
cout << resetiosflags(ios_base::left);
}
@ -87,13 +100,19 @@ void TestSystem::printItem(double cpu_time, double gpu_time, double speedup)
stream.str("");
stream << "x" << setprecision(3) << speedup;
cout << setw(10) << stream.str();
cout << setw(14) << stream.str();
cout << description_.str();
cout << resetiosflags(ios_base::left) << endl;
}
void TestSystem::printError(const std::string& msg)
{
cout << TAB << "[error: " << msg << "] " << description_.str() << endl;
}
void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
{
mat.create(rows, cols, type);
@ -102,17 +121,34 @@ void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
}
string abspath(const string& relpath)
{
return TestSystem::instance()->workingDir() + relpath;
}
int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/,
const char* /*err_msg*/, const char* /*file_name*/,
const char* err_msg, const char* /*file_name*/,
int /*line*/, void* /*userdata*/)
{
TestSystem::instance()->printError(err_msg);
return 0;
}
int main()
int main(int argc, char** argv)
{
if (argc < 2)
{
cout << "Usage: performance_gpu <working_dir_with_slash>\n\n";
}
else
{
TestSystem::instance()->setWorkingDir(argv[1]);
}
redirectError(cvErrorCallback);
TestSystem::instance()->run();
return 0;
}

View File

@ -63,6 +63,12 @@ public:
can_flush_ = true;
}
void setWorkingDir(const std::string& val);
const std::string& workingDir() const { return working_dir_; }
void printError(const std::string& msg);
private:
TestSystem(): can_flush_(false), cpu_elapsed_(0), gpu_elapsed_(0),
speedup_total_(0.0), num_subtests_called_(0) {};
@ -81,6 +87,8 @@ private:
void printSummary();
void printItem(double cpu_time, double gpu_time, double speedup);
std::string working_dir_;
std::vector<Runnable*> inits_;
std::vector<Runnable*> tests_;
@ -128,4 +136,6 @@ private:
void gen(cv::Mat& mat, int rows, int cols, int type, cv::Scalar low,
cv::Scalar high);
std::string abspath(const std::string& relpath);
#endif // OPENCV_GPU_SAMPLE_PERFORMANCE_H_

View File

@ -1,4 +1,6 @@
#include <stdexcept>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include "performance.h"
@ -81,8 +83,20 @@ TEST(remap)
SUBTEST << "src " << size << " and 8U, 32F maps";
gen(src, size, size, CV_8UC1, 0, 256);
gen(xmap, size, size, CV_32F, 0, size);
gen(ymap, size, size, CV_32F, 0, size);
xmap.create(size, size, CV_32F);
ymap.create(size, size, CV_32F);
for (int i = 0; i < size; ++i)
{
float* xmap_row = xmap.ptr<float>(i);
float* ymap_row = ymap.ptr<float>(i);
for (int j = 0; j < size; ++j)
{
xmap_row[j] = (j - size * 0.5f) * 0.75f + size * 0.5f;
ymap_row[j] = (i - size * 0.5f) * 0.75f + size * 0.5f;
}
}
dst.create(xmap.size(), src.type());
CPU_ON;
@ -97,22 +111,6 @@ TEST(remap)
GPU_ON;
gpu::remap(d_src, d_dst, d_xmap, d_ymap);
GPU_OFF;
SUBTEST << "src " << size << " and 8U, 32F singular maps";
gen(xmap, size, size, CV_32F, 0, 0);
gen(ymap, size, size, CV_32F, 0, 0);
CPU_ON;
remap(src, dst, xmap, ymap, INTER_LINEAR);
CPU_OFF;
d_xmap = xmap;
d_ymap = ymap;
GPU_ON;
gpu::remap(d_src, d_dst, d_xmap, d_ymap);
GPU_OFF;
}
}
@ -217,3 +215,62 @@ TEST(norm)
GPU_OFF;
}
}
TEST(meanShift)
{
int sp = 10, sr = 10;
Mat src, dst;
gpu::GpuMat d_src, d_dst;
for (int size = 400; size <= 800; size *= 2)
{
SUBTEST << "size " << size << ", 8UC3 vs 8UC4";
gen(src, size, size, CV_8UC3, Scalar::all(0), Scalar::all(256));
dst.create(src.size(), src.type());
CPU_ON;
pyrMeanShiftFiltering(src, dst, sp, sr);
CPU_OFF;
gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
d_src = src;
d_dst.create(d_src.size(), d_src.type());
GPU_ON;
gpu::meanShiftFiltering(d_src, d_dst, sp, sr);
GPU_OFF;
}
}
TEST(SURF)
{
Mat src1 = imread(abspath("bowlingL.png"), CV_LOAD_IMAGE_GRAYSCALE);
Mat src2 = imread(abspath("bowlingR.png"), CV_LOAD_IMAGE_GRAYSCALE);
if (src1.empty()) throw runtime_error("can't open bowlingL.png");
if (src2.empty()) throw runtime_error("can't open bowlingR.png");
gpu::GpuMat d_src1(src1);
gpu::GpuMat d_src2(src2);
SURF surf;
vector<KeyPoint> keypoints1, keypoints2;
CPU_ON;
surf(src1, Mat(), keypoints1);
surf(src2, Mat(), keypoints2);
CPU_OFF;
gpu::SURF_GPU d_surf;
gpu::GpuMat d_keypoints1, d_keypoints2;
gpu::GpuMat d_descriptors1, d_descriptors2;
GPU_ON;
d_surf(d_src1, gpu::GpuMat(), d_keypoints1);
d_surf(d_src2, gpu::GpuMat(), d_keypoints2);
GPU_OFF;
}