-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cc
More file actions
133 lines (116 loc) · 1.91 KB
/
utils.cc
File metadata and controls
133 lines (116 loc) · 1.91 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
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
//
// Utility functions
//
#include "modisresam.h"
void
eprintf(const char *fmt, ...)
{
va_list args;
fflush(stdout);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
if(fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
fprintf(stderr, " %s", strerror(errno));
fprintf(stderr, "\n");
exit(2);
}
void
logprintf(const char *fmt, ...)
{
va_list args;
time_t now;
char *t;
time(&now);
t = ctime(&now);
// omit '\n' from time when printing
printf("# %.*s ", (int)strlen(t)-1, t);
fflush(stdout);
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
char*
estrdup(const char *s)
{
char *dup;
dup = strdup(s);
if(dup == NULL)
eprintf("strdup of \"%s\" failed:", s);
return dup;
}
void*
emalloc(size_t n)
{
void *buf;
buf = malloc(n);
if(buf == NULL)
eprintf("malloc failed:");
return buf;
}
const char*
type2str(int type)
{
switch(type) {
default:
return "UnknownType";
break;
case CV_8UC1:
return "CV_8UC1";
break;
case CV_8SC1:
return "CV_8SC1";
break;
case CV_16UC1:
return "CV_16UC1";
break;
case CV_16SC1:
return "CV_16SC1";
break;
case CV_32SC1:
return "CV_32SC1";
break;
case CV_32FC1:
return "CV_32FC1";
break;
case CV_64FC1:
return "CV_64FC1";
break;
}
}
void
dumpmat(const char *filename, Mat &m)
{
int n;
FILE *f;
if(!m.isContinuous()) {
eprintf("m not continuous");
}
f = fopen(filename, "w");
if(!f) {
eprintf("open %s failed:", filename);
}
n = fwrite(m.data, m.elemSize1(), m.rows*m.cols, f);
if(n != m.rows*m.cols) {
fclose(f);
eprintf("wrote %d/%d items; write failed:", n, m.rows*m.cols);
}
fclose(f);
}
void
dumpfloat(const char *filename, float *buf, int nbuf)
{
int n;
FILE *f;
f = fopen(filename, "w");
if(!f) {
eprintf("open %s failed:", filename);
}
n = fwrite(buf, sizeof(*buf), nbuf, f);
if(n != nbuf) {
fclose(f);
eprintf("wrote %d/%d items; write failed:", n, nbuf);
}
fclose(f);
}