-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_blur_image.cpp
63 lines (50 loc) · 1.6 KB
/
test_blur_image.cpp
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
#include "blur_image/gpu_fft_blur_image.h"
#include <opencv2/opencv.hpp>
#include <vector>
#include <string>
int main(int argc, char* argv[])
{
const int num_images = argc - 1;
int rows = -1;
int cols = -1;
std::vector<std::string> files;
for( int i = 0; i < num_images; ++i)
{
files.emplace_back(argv[1 + i]);
cv::Mat image = cv::imread(files.back(), cv::IMREAD_GRAYSCALE);
if (image.empty())
{
fprintf(stderr, "Could not read the image %s\n", files.back().c_str());
return -1;
}
if (i == 0)
{
rows = image.rows;
cols = image.cols;
}
else if (rows != image.rows || cols != image.cols)
{
fprintf(stderr, "Images must be the same dimension\n");
return -1;
}
}
std::vector<float> images(num_images * rows * cols);
for (int i = 0; i < files.size(); ++i)
{
cv::Mat image = cv::imread(files[i].c_str(), cv::IMREAD_GRAYSCALE);
assert(!image.empty());
cv::imshow(files[i], image);
image.convertTo(image, CV_32F);
std::memcpy(images.data() + i * rows * cols, image.data, rows * cols * sizeof(float));
}
GpuBlurImage blur_image(rows, cols, num_images, 5);
blur_image.blur(images.data(), images.data(), num_images);
for (int i = 0; i < num_images; ++i)
{
cv::Mat image(rows, cols, CV_32F, images.data() + i * rows * cols);
image.convertTo(image, CV_8U);
cv::imshow("Blurred " + files[i] + std::to_string(i), image);
}
cv::waitKey();
return 0;
}