-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
58 lines (39 loc) · 1.33 KB
/
main.cpp
File metadata and controls
58 lines (39 loc) · 1.33 KB
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
#include <iostream>
#include <sstream>
#include <chrono>
#include <functional>
#include "image.hpp"
void test();
uint8_t* sort(std::function<uint8_t* (uint8_t*, int, int)> fn, uint8_t* in, int len, int k);
int main() {
test();
}
void test() {
auto image_pool = std::vector<Image>();
for (int i = 0; i < 8; i++) {
std::ostringstream ss;
ss << "./samples/s" << i+1 << ".jpg";
image_pool.push_back(Image(ss.str()));
}
int counter = 1;
for (auto& image : image_pool) {
auto vec = image.vectorize();
auto svec = sort(Image::sort, vec, image.get_rows() * image.get_cols(), 256);
auto mat = Image::vector_to_mat(svec, image.get_rows(), image.get_cols());
delete[] vec;
delete[] svec;
auto res = Image(mat);
std::ostringstream ss;
ss << "output_" << counter << ".jpg";
res.save("./samples/", ss.str());
counter += 1;
}
}
uint8_t* sort(std::function<uint8_t* (uint8_t*, int, int)> fn, uint8_t* in, int len, int k) {
auto t1 = std::chrono::high_resolution_clock::now();
auto res = fn(in, len, k);
auto t2 = std::chrono::high_resolution_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
std::cout << len << " " << diff << std::endl;
return res;
}