MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / draw_mask

Method draw_mask

lesson6-Segmentation/SegDataset.cpp:67–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67void SegDataset::draw_mask(std::string json_path, cv::Mat &mask){
68 std::ifstream jfile(json_path);
69 nlohmann::json j;
70 jfile >> j;
71 size_t num_blobs = j["shapes"].size();
72
73
74 for (int i = 0; i < num_blobs; i++)
75 {
76 std::string name = j["shapes"][i]["label"];
77 size_t points_len = j["shapes"][i]["points"].size();
78// std::cout << name << std::endl;
79 std::vector<cv::Point> contour = {};
80 for (int t = 0; t < points_len; t++)
81 {
82 int x = round(double(j["shapes"][i]["points"][t][0]));
83 int y = round(double(j["shapes"][i]["points"][t][1]));
84// std::cout << x << "\t" << y << std::endl;
85 contour.push_back(cv::Point(x, y));
86 }
87 const cv::Point* ppt[1] = { contour.data() };
88 int npt[] = { int(contour.size()) };
89 cv::fillPoly(mask, ppt, npt, 1, name2color[name]);
90 }
91}
92
93SegDataset::SegDataset(int _resize_width, int _resize_height, std::vector<std::string> _list_images,
94 std::vector<std::string> _list_labels, std::vector<std::string> _name_list)

Callers

nothing calls this directly

Calls 3

push_backMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected