-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.cpp
54 lines (44 loc) · 1.48 KB
/
convert.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
#include <iostream>
#include <string>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include "patchnorm_cuda.h"
#include <experimental/filesystem>
#define NEIGHB 17
using namespace std;
using namespace cv;
namespace fs = std::experimental::filesystem;
int main(int argc, char**argv) {
if (argc < 3) {
cout << "Usage patchnorm_convert output_folder [images...]" << endl;
exit(1);
}
fs::path outputfolder = argv[1];
if(!fs::is_directory(outputfolder)) {
cout << outputfolder << " Is not a directory!" << endl;
exit(1);
}
PatchNormCuda * normalizer = NULL;
Size last_size(0,0);
for(int idx=2; idx < argc; idx++) {
fs::path imgfn = argv[idx];
fs::path outfn = outputfolder / imgfn.filename();
Mat img = imread(imgfn.string(), CV_LOAD_IMAGE_GRAYSCALE);
Mat pn;
if((!normalizer) | (img.size() != last_size)) {
// Lazily initialize the normalizer
// If the image size changed, the normalizer also needs to be reinitialized
delete normalizer;
normalizer = new PatchNormCuda(img.size().width, img.size().height);
}
last_size = img.size();
normalizer->compute(img, pn, 17);
normalize(pn, pn, 255, 0, NORM_MINMAX);
pn.convertTo(pn, CV_8UC1);
imwrite(outfn.string(), pn);
printf("Finished %d/%d\r", idx-1, argc-2);
cout << flush;
}
cout << endl;
}