-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.cpp
54 lines (48 loc) · 1012 Bytes
/
util.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 "util.h"
std::string type2str(int type) {
std::string r;
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch (depth) {
case CV_8U:
r = "8U";
break;
case CV_8S:
r = "8S";
break;
case CV_16U:
r = "16U";
break;
case CV_16S:
r = "16S";
break;
case CV_32S:
r = "32S";
break;
case CV_32F:
r = "32F";
break;
case CV_64F:
r = "64F";
break;
default:
r = "User";
break;
}
r += "C";
r += (chans + '0');
return r;
}
cv::Mat loadImage(std::string img_path, const nlohmann::json &options,
const int &flags) {
cv::Mat image = cv::imread(img_path, flags);
if (!image.data) {
std::cerr << "could not open the image file" << img_path << std::endl;
return image;
}
if (options["crop"]) {
image = image(cv::Rect(options["crop_x"], options["crop_y"],
options["crop_width"], options["crop_height"]));
}
return image;
}