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

Function load_seg_data_from_folder

lesson6-Segmentation/util.cpp:28–63  ·  view source on GitHub ↗

遍历该目录下的.xml文件,并且找到对应的

Source from the content-addressed store, hash-verified

26
27//遍历该目录下的.xml文件,并且找到对应的
28void load_seg_data_from_folder(std::string folder, std::string image_type,
29 std::vector<std::string> &list_images, std::vector<std::string> &list_labels)
30{
31 long long hFile = 0; //句柄
32 struct _finddata_t fileInfo;
33 std::string pathName;
34 if ((hFile = _findfirst(pathName.assign(folder).append("\\*.*").c_str(), &fileInfo)) == -1)
35 {
36 return;
37 }
38 do
39 {
40 const char* s = fileInfo.name;
41
42 if (fileInfo.attrib&_A_SUBDIR) //是子文件夹
43 {
44 //遍历子文件夹中的文件(夹),查看是否有txt文件
45 if (strcmp(s, ".") == 0 || strcmp(s, "..") == 0) //子文件夹目录是.或者..
46 continue;
47 std::string sub_path = folder + "\\" + fileInfo.name;
48 load_seg_data_from_folder(sub_path, image_type, list_images, list_labels);
49 }
50 else //判断是不是txt文件
51 {
52
53 if (strstr(s, ".json"))
54 {
55 std::string label_path = folder + "\\" + fileInfo.name;
56 list_labels.push_back(label_path);
57 std::string image_path = replace_all_distinct(label_path, ".json", image_type);
58 list_images.push_back(image_path);
59 }
60 }
61 } while (_findnext(hFile, &fileInfo) == 0);
62 return;
63}

Callers 1

TrainMethod · 0.70

Calls 3

c_strMethod · 0.80
push_backMethod · 0.80
replace_all_distinctFunction · 0.70

Tested by

no test coverage detected