| 65 | } |
| 66 | |
| 67 | void 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 | |
| 93 | SegDataset::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) |