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

Function show_mask

lesson6-Segmentation/SegDataset.cpp:31–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31void show_mask(std::string json_path, std::string image_type) {
32 using namespace std;
33 using json = nlohmann::json;
34 std::string image_path = replace_all_distinct(json_path, ".json", image_type);
35 cv::Mat image = cv::imread(image_path);
36 cv::Mat mask;
37 mask.create(image.size(), CV_8UC3);
38
39 std::ifstream jfile(json_path);
40 json j;
41 jfile >> j;
42 size_t num_blobs = j["shapes"].size();
43
44 for (int i = 0; i < num_blobs; i++)
45 {
46 std::string name = j["shapes"][i]["label"];
47 size_t points_len = j["shapes"][i]["points"].size();
48 cout << name << endl;
49 std::vector<cv::Point> contour = {};
50 for (int t = 0; t < points_len; t++)
51 {
52 int x = round(double(j["shapes"][i]["points"][t][0]));
53 int y = round(double(j["shapes"][i]["points"][t][1]));
54 cout << x << "\t" << y << endl;
55 contour.push_back(cv::Point(x, y));
56 }
57 const cv::Point* ppt[1] = { contour.data() };
58 int npt[] = { int(contour.size()) };
59 cv::fillPoly(mask, ppt, npt, 1, cv::Scalar(255, 255, 255));
60 }
61 cv::imshow("mask", mask);
62 cv::imshow("image", image);
63 cv::waitKey(0);
64 cv::destroyAllWindows();
65}
66
67void SegDataset::draw_mask(std::string json_path, cv::Mat &mask){
68 std::ifstream jfile(json_path);

Callers

nothing calls this directly

Calls 5

push_backMethod · 0.80
dataMethod · 0.80
replace_all_distinctFunction · 0.70
createMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected