-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.cpp
62 lines (40 loc) · 1.38 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
#include <utils.h>
double diff_vec3b(const cv::Vec3b & v0, const cv::Vec3b & v1) {
double diff = 0;
for (int i = 0; i < 3; i++) {
diff += abs(v0[i] - v1[i]);
}
return diff / 3;
}
double m_metric_pixel(const cv::Mat & img0, const cv::Mat & img1) {
int x0 = img0.cols - 1;
int x1 = 0;
double m_score = 0;
for (int y = 0; y < img0.rows; y++) {
m_score += diff_vec3b( img0.at<cv::Vec3b>(y, x0),
img1.at<cv::Vec3b>(y, x1));
}
return -m_score / img0.rows;
}
cv::Mat merge_imgs(const cv::Mat & in_img0, const cv::Mat & in_img1) {
assert(in_img0.rows == in_img1.rows);
cv::Size out_img_size(in_img0.cols + in_img1.cols, in_img0.rows);
cv::Mat out_img(out_img_size, CV_8UC3);
cv::Rect in_img0_roi(0, 0, in_img0.cols, in_img0.rows);
in_img0.copyTo(out_img(in_img0_roi));
cv::Rect in_img1_roi(in_img0.cols, 0, in_img1.cols, in_img1.rows);
in_img1.copyTo(out_img(in_img1_roi));
return out_img;
}
bool cross_seam(const cv::Rect & bbox, int seam_x) {
if (bbox.x < seam_x && bbox.x + bbox.width >= seam_x) {
return true;
} else {
return false;
}
}
void print_timestamp() {
auto now = chrono::system_clock::now();
time_t cur_time = chrono::system_clock::to_time_t(now);
cout << endl << "Current timestamp: " << ctime(&cur_time) << endl;
}