-
Notifications
You must be signed in to change notification settings - Fork 13
/
utils.cpp
65 lines (61 loc) · 1.52 KB
/
utils.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
64
65
#include "utils.h"
/* init the dataset: patches & ground truth */
void init_dataset(dataset *A,const char *path)
{
/* read the # of images */
int numImgs=0;
DIR *dir;
struct dirent *ent;
dir = opendir(path);
if (dir != NULL) {
while ((ent = readdir (dir)) != NULL) {
char *ext = strrchr(ent->d_name, '.');
if (strcmp (ext,".pgm")==0)
{
numImgs++;
}
}
closedir (dir);
}
float smoothed[1024];
int cnt=0;
float im[32*32];
char s[35];
char fname[35];
cnt=0;
/* loop through all images and read them */
for (int i = 0; i < numImgs; i++) {
int N = 32;
sprintf(s, "%spatches%04d.pgm",path ,i);
cv::Mat largeImg = cv::imread(s, 0);
for (int r = 0; r < largeImg.rows; r += N)
for (int c = 0; c < largeImg.cols; c += N)
{
cv::Mat tile = largeImg(cv::Range(r, cv::min(r + N, largeImg.rows)),
cv::Range(c, cv::min(c + N, largeImg.cols)));
A->patchesCV.push_back(tile);
}
}
char gt_fname[55];
sprintf(gt_fname, "%sm50_500000_500000_0.txt",path);
/* read the gt file */
FILE *in_file;
in_file = fopen(gt_fname, "rb");
/* init the gt */
A->gt =(int**) malloc(GT_SIZE * sizeof(int *));
for (int i = 0; i < GT_SIZE; i++){
A->gt[i] = (int*)malloc(7 * sizeof(int));
}
/* read the gt */
for (int i = 0; i < GT_SIZE; i++) {
for (int j = 0; j < 7 ; ++j){
int fscan_res;
fscan_res = fscanf(in_file, "%d", &A->gt[i][j]);
if (!fscan_res)
{
printf("Something went wrong. \n");
}
}
}
fclose(in_file);
}