1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/**
* @file main.cpp
* @author mango ([email protected])
* @brief
* @version 0.1
* @date 2022-05-14
*
* @copyright Copyright (c) 2022
*
*/
#include "opencv2/opencv.hpp"
#include "matplot/matplot.h"
#include <iostream>
#include <chrono>
#include <tuple>
#include <vector>
int main(int argc, char** argv)
{
std::vector<std::tuple<size_t, size_t>> img_sizes = { {640, 480}, {1280, 720}, {1280, 960}, {1920, 1080}, {1600, 1200}, {2048, 1536}, {2592, 1944}, {3264, 2448}, {3840, 2160}, {4224, 3168}, {5344, 4106} };
std::vector<double> mat_cost_time;
std::vector<double> umat_cost_time;
std::vector<int> plotx;
for (auto&& [len, wid] : img_sizes)
{
cv::Mat img = cv::Mat(len, wid, CV_8UC1);
cv::UMat uimg = cv::UMat(len, wid, CV_8UC1);
cv::Mat dst;
cv::UMat udst;
auto t0 = std::chrono::system_clock::now();
for (int i = 0; i < 10; i++)
{
cv::GaussianBlur(img, dst, cv::Size(7, 7), 1.5);
//cv::blur(img, dst, cv::Size(7, 7));
//cv::threshold(img, dst, 128, 255, cv::THRESH_BINARY);
//cv::medianBlur(img, dst, 5);
}
auto t1 = std::chrono::system_clock::now();
for (int i = 0; i < 10; i++)
{
cv::GaussianBlur(uimg, udst, cv::Size(7, 7), 1.5);
//cv::blur(uimg, udst, cv::Size(7, 7));
//cv::threshold(uimg, udst, 128, 255, cv::THRESH_BINARY);
//cv::medianBlur(uimg, udst, 5);
}
auto t2 = std::chrono::system_clock::now();
double dt1 = std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count() / 10.0;
double dt2 = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count() / 10.0;
mat_cost_time.push_back(dt1);
umat_cost_time.push_back(dt2);
plotx.push_back(len * wid);
}
matplot::title("umat GaussianBlur performance");
matplot::hold(matplot::on);
auto mat_y = matplot::plot(mat_cost_time, "r");
auto umat_y = matplot::plot(umat_cost_time, "g");
matplot::legend({ mat_y,umat_y }, { "mat", "umat"});
matplot::ylabel("time / ms");
matplot::show();
return 0;
}
|