#include <iomanip>\r
+#include <stdexcept>\r
#include "performance.h"\r
\r
using namespace std;\r
(*it)->run();\r
flushSubtestData();\r
}\r
- catch (const cv::Exception&)\r
+ catch (const Exception&)\r
{\r
+ // Message is printed via callback\r
+ resetSubtestData();\r
+ }\r
+ catch (const runtime_error& e)\r
+ {\r
+ printError(e.what());\r
resetSubtestData();\r
}\r
}\r
}\r
\r
\r
+void TestSystem::setWorkingDir(const string& val)\r
+{\r
+ working_dir_ = val;\r
+}\r
+\r
+\r
void TestSystem::flushSubtestData()\r
{\r
if (!can_flush_)\r
int cpu_time = static_cast<int>(cpu_elapsed_ / getTickFrequency() * 1000.0);\r
int gpu_time = static_cast<int>(gpu_elapsed_ / getTickFrequency() * 1000.0);\r
\r
- double speedup = static_cast<double>(cpu_time) / std::max(1, gpu_time);\r
+ double speedup = static_cast<double>(cpu_elapsed_) / gpu_elapsed_;\r
speedup_total_ += speedup;\r
\r
printItem(cpu_time, gpu_time, speedup);\r
{\r
cout << setiosflags(ios_base::left);\r
cout << TAB << setw(10) << "CPU, ms" << setw(10) << "GPU, ms" \r
- << setw(10) << "SPEEDUP" \r
+ << setw(14) << "SPEEDUP" \r
<< "DESCRIPTION\n";\r
cout << resetiosflags(ios_base::left);\r
}\r
\r
stream.str("");\r
stream << "x" << setprecision(3) << speedup;\r
- cout << setw(10) << stream.str();\r
+ cout << setw(14) << stream.str();\r
\r
cout << description_.str();\r
cout << resetiosflags(ios_base::left) << endl;\r
}\r
\r
\r
+void TestSystem::printError(const std::string& msg)\r
+{\r
+ cout << TAB << "[error: " << msg << "] " << description_.str() << endl;\r
+}\r
+\r
+\r
void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)\r
{\r
mat.create(rows, cols, type);\r
}\r
\r
\r
+string abspath(const string& relpath)\r
+{\r
+ return TestSystem::instance()->workingDir() + relpath;\r
+}\r
+\r
+\r
int CV_CDECL cvErrorCallback(int /*status*/, const char* /*func_name*/, \r
- const char* /*err_msg*/, const char* /*file_name*/,\r
+ const char* err_msg, const char* /*file_name*/,\r
int /*line*/, void* /*userdata*/)\r
{\r
+ TestSystem::instance()->printError(err_msg);\r
return 0;\r
}\r
\r
\r
-int main()\r
+int main(int argc, char** argv)\r
{\r
+ if (argc < 2)\r
+ {\r
+ cout << "Usage: performance_gpu <working_dir_with_slash>\n\n";\r
+ }\r
+ else\r
+ {\r
+ TestSystem::instance()->setWorkingDir(argv[1]);\r
+ }\r
+\r
redirectError(cvErrorCallback);\r
TestSystem::instance()->run();\r
+\r
return 0;\r
}
\ No newline at end of file
can_flush_ = true;\r
}\r
\r
+ void setWorkingDir(const std::string& val);\r
+\r
+ const std::string& workingDir() const { return working_dir_; }\r
+\r
+ void printError(const std::string& msg);\r
+\r
private:\r
TestSystem(): can_flush_(false), cpu_elapsed_(0), gpu_elapsed_(0), \r
speedup_total_(0.0), num_subtests_called_(0) {};\r
void printSummary();\r
void printItem(double cpu_time, double gpu_time, double speedup);\r
\r
+ std::string working_dir_;\r
+\r
std::vector<Runnable*> inits_;\r
std::vector<Runnable*> tests_;\r
\r
void gen(cv::Mat& mat, int rows, int cols, int type, cv::Scalar low, \r
cv::Scalar high);\r
\r
+std::string abspath(const std::string& relpath);\r
+\r
#endif // OPENCV_GPU_SAMPLE_PERFORMANCE_H_
\ No newline at end of file
+#include <stdexcept>\r
#include <opencv2/imgproc/imgproc.hpp>\r
+#include <opencv2/highgui/highgui.hpp>\r
#include <opencv2/gpu/gpu.hpp>\r
#include "performance.h"\r
\r
SUBTEST << "src " << size << " and 8U, 32F maps";\r
\r
gen(src, size, size, CV_8UC1, 0, 256);\r
- gen(xmap, size, size, CV_32F, 0, size);\r
- gen(ymap, size, size, CV_32F, 0, size);\r
+\r
+ xmap.create(size, size, CV_32F);\r
+ ymap.create(size, size, CV_32F);\r
+ for (int i = 0; i < size; ++i)\r
+ {\r
+ float* xmap_row = xmap.ptr<float>(i);\r
+ float* ymap_row = ymap.ptr<float>(i);\r
+ for (int j = 0; j < size; ++j)\r
+ {\r
+ xmap_row[j] = (j - size * 0.5f) * 0.75f + size * 0.5f;\r
+ ymap_row[j] = (i - size * 0.5f) * 0.75f + size * 0.5f;\r
+ }\r
+ }\r
+\r
dst.create(xmap.size(), src.type());\r
\r
CPU_ON;\r
GPU_ON;\r
gpu::remap(d_src, d_dst, d_xmap, d_ymap);\r
GPU_OFF;\r
-\r
- SUBTEST << "src " << size << " and 8U, 32F singular maps";\r
-\r
- gen(xmap, size, size, CV_32F, 0, 0);\r
- gen(ymap, size, size, CV_32F, 0, 0);\r
-\r
- CPU_ON;\r
- remap(src, dst, xmap, ymap, INTER_LINEAR);\r
- CPU_OFF;\r
-\r
- d_xmap = xmap;\r
- d_ymap = ymap;\r
-\r
- GPU_ON;\r
- gpu::remap(d_src, d_dst, d_xmap, d_ymap);\r
- GPU_OFF;\r
}\r
}\r
\r
GPU_OFF;\r
}\r
}\r
+\r
+\r
+TEST(meanShift)\r
+{\r
+ int sp = 10, sr = 10;\r
+\r
+ Mat src, dst;\r
+ gpu::GpuMat d_src, d_dst;\r
+\r
+ for (int size = 400; size <= 800; size *= 2)\r
+ {\r
+ SUBTEST << "size " << size << ", 8UC3 vs 8UC4";\r
+\r
+ gen(src, size, size, CV_8UC3, Scalar::all(0), Scalar::all(256));\r
+ dst.create(src.size(), src.type());\r
+\r
+ CPU_ON;\r
+ pyrMeanShiftFiltering(src, dst, sp, sr);\r
+ CPU_OFF;\r
+\r
+ gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));\r
+\r
+ d_src = src;\r
+ d_dst.create(d_src.size(), d_src.type());\r
+\r
+ GPU_ON;\r
+ gpu::meanShiftFiltering(d_src, d_dst, sp, sr);\r
+ GPU_OFF;\r
+ }\r
+}\r
+\r
+\r
+TEST(SURF)\r
+{\r
+ Mat src1 = imread(abspath("bowlingL.png"), CV_LOAD_IMAGE_GRAYSCALE);\r
+ Mat src2 = imread(abspath("bowlingR.png"), CV_LOAD_IMAGE_GRAYSCALE);\r
+ if (src1.empty()) throw runtime_error("can't open bowlingL.png");\r
+ if (src2.empty()) throw runtime_error("can't open bowlingR.png");\r
+\r
+ gpu::GpuMat d_src1(src1);\r
+ gpu::GpuMat d_src2(src2);\r
+\r
+ SURF surf;\r
+ vector<KeyPoint> keypoints1, keypoints2;\r
+\r
+ CPU_ON;\r
+ surf(src1, Mat(), keypoints1);\r
+ surf(src2, Mat(), keypoints2);\r
+ CPU_OFF;\r
+\r
+ gpu::SURF_GPU d_surf;\r
+ gpu::GpuMat d_keypoints1, d_keypoints2;\r
+ gpu::GpuMat d_descriptors1, d_descriptors2;\r
+\r
+ GPU_ON;\r
+ d_surf(d_src1, gpu::GpuMat(), d_keypoints1);\r
+ d_surf(d_src2, gpu::GpuMat(), d_keypoints2);\r
+ GPU_OFF;\r
+}
\ No newline at end of file