-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhardCodeFunctions.h
136 lines (98 loc) · 3.64 KB
/
hardCodeFunctions.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* File: hardCodeFunctions.h
* Author: swl
*
* Created on December 1, 2015, 5:15 PM
*/
#ifndef HARDCODEFUNCTIONS_H
#define HARDCODEFUNCTIONS_H
#include <sys/time.h>
#include <sys/stat.h>
#include "Retriever.h"
std::string libPath = "/home/swl/Documents/Data/psb/";
void train()
{
Retriever retriever;
retriever.init();
retriever.setLibPath(libPath);
retriever.train(libPath+"cluster_pa=1e-1.bin", libPath+"dict_pa=1e-1.bin");
retriever.saveTrainingData(libPath+"sbsr_pa=1e-1.bin");
}
inline double diff(const struct timeval& ts, const struct timeval& te)
{
return (te.tv_sec - ts.tv_sec)*1e6+te.tv_usec-ts.tv_usec;
}
void show()
{
Retriever retriever;
retriever.init();
retriever.loadTrainingData(libPath+"sbsr.bin");
retriever.buildTopKDTree();
struct timeval ts, te;
char line[1024];
while(1)
{
printf("Input File Path:");
gets(line);
std::string folder_name = line;
if(strcmp(line, "q") == 0)
break;
mkdir(line, ACCESSPERMS);
std::string input_path = "/home/swl/Documents/Data/test_sketches/";
input_path = input_path + line + ".png";
cv::Mat sketch = cv::imread(input_path, CV_LOAD_IMAGE_GRAYSCALE);
cv::Mat1f input = sketch / 255.0;
gettimeofday(&ts, NULL);
std::vector<Retriever::RetrievalInfo> retrievalList = retriever.retrieveAll(input);
gettimeofday(&te, NULL);
FILE* file = fopen((folder_name+"/info.txt").c_str(), "w");
fprintf(file, "time = %0.3lf ms\n", diff(ts, te)*1e-3);
for(unsigned i=0; i<10; i++)
{
//printf("%s -- %f\n", retrievalList[i].path.c_str(), retrievalList[i].score);
SketchRenderer::load(retrievalList[i].path.c_str());
cv::imwrite(folder_name+"/input.png", input*255.0);
cv::Mat1f sketch = SketchRenderer::genSketch(
retrievalList[i].front,
retrievalList[i].up
);
char fn[1024];
sprintf(fn, "%s/sketch%u.png", folder_name.c_str(), i+1);
cv::imwrite(fn, sketch*255.0);
// dbg(sketch);
cv::Mat1f image = SketchRenderer::genShading(
retrievalList[i].front,
retrievalList[i].up
);
sprintf(fn, "%s/model%u.png", folder_name.c_str(), i+1);
cv::imwrite(fn, image*255.0);
// dbg(image);
}
gettimeofday(&ts, NULL);
retrievalList = retriever.retrieveTop(input);
gettimeofday(&te, NULL);
fprintf(file, "knn_time = %0.3lf ms\n", diff(ts, te)*1e-3);
for(unsigned i=0; i<10; i++)
{
//printf("%s -- %f\n", retrievalList[i].path.c_str(), retrievalList[i].score);
SketchRenderer::load(retrievalList[i].path.c_str());
cv::Mat1f sketch = SketchRenderer::genSketch(
retrievalList[i].front,
retrievalList[i].up
);
char fn[1024];
sprintf(fn, "%s/knn_sketch%u.png", folder_name.c_str(), i+1);
cv::imwrite(fn, sketch*255.0);
// dbg(sketch);
cv::Mat1f image = SketchRenderer::genShading(
retrievalList[i].front,
retrievalList[i].up
);
sprintf(fn, "%s/knn_model%u.png", folder_name.c_str(), i+1);
cv::imwrite(fn, image*255.0);
// dbg(image);
}
fclose(file);
}
}
#endif /* HARDCODEFUNCTIONS_H */