licornea_tools
border.cc
Go to the documentation of this file.
1 #include "border.h"
2 
3 namespace tlz {
4 
5 json encode_border(const border& bord) {
6  json j_bord = json::object();
7  j_bord["top"] = bord.top;
8  j_bord["left"] = bord.left;
9  j_bord["right"] = bord.right;
10  j_bord["bottom"] = bord.bottom;
11  return j_bord;
12 }
13 
14 
15 border decode_border(const json& j_bord) {
16  border bord;
17  bord.top = get_or(j_bord, "top", 0);
18  bord.left = get_or(j_bord, "left", 0);
19  bord.right = get_or(j_bord, "right", 0);
20  bord.bottom = get_or(j_bord, "bottom", 0);
21  return bord;
22 }
23 
24 cv::Size add_border(const border& bord, const cv::Size& sz) {
25  cv::Size out_sz = sz;
26  out_sz.width += (bord.left + bord.right);
27  out_sz.height += (bord.top + bord.bottom);
28  return out_sz;
29 }
30 
31 cv::Point add_border(const border& bord, const cv::Point& pt) {
32  cv::Point out_pt = pt;
33  out_pt.x += bord.left;
34  out_pt.y += bord.top;
35  return out_pt;
36 }
37 
38 
39 }
border decode_border(const json &j_bord)
Definition: border.cc:15
int left
Definition: border.h:10
int bottom
Definition: border.h:12
int top
Definition: border.h:9
cv::Size add_border(const border &bord, const cv::Size &sz)
Definition: border.cc:24
int right
Definition: border.h:11
json encode_border(const border &bord)
Definition: border.cc:5
nlohmann::json json
Definition: json.h:11
T get_or(const json &j, const std::string &key, const T &default_value)
Definition: json.h:28