Skip to content

Commit d7e3901

Browse files
committed
add yolo4_tiny
1 parent c577377 commit d7e3901

28 files changed

+8909
-0
lines changed

2007_005331_pred.jpg

68.3 KB
Loading

2007_005331_pred_coco.jpg

67.5 KB
Loading

libtorch_detection.vcxproj

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>15.0</VCProjectVersion>
23+
<ProjectGuid>{8A8A9E6F-B5D4-4679-A4CB-88DD72747306}</ProjectGuid>
24+
<RootNamespace>libtorchdetection</RootNamespace>
25+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v141</PlatformToolset>
32+
<CharacterSet>MultiByte</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v141</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>MultiByte</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v141</PlatformToolset>
45+
<CharacterSet>MultiByte</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v141</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>MultiByte</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<OutDir>$(SolutionDir)bin\$(Platform)_$(Configuration)\</OutDir>
74+
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)_$(Configuration)\</IntDir>
75+
<IncludePath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\include;D:\AllentFiles\code\dependency\libtorch17release\include;D:\AllentFiles\code\dependency\libtorch17release\include\torch\csrc\api\include;$(IncludePath)</IncludePath>
76+
<LibraryPath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\x64\vc14\lib;D:\AllentFiles\code\dependency\libtorch17release\lib;$(LibraryPath)</LibraryPath>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
79+
<OutDir>$(SolutionDir)bin\$(Platform)_$(Configuration)\</OutDir>
80+
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)_$(Configuration)\</IntDir>
81+
<IncludePath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\include;D:\AllentFiles\code\dependency\libtorch17release\include;D:\AllentFiles\code\dependency\libtorch17release\include\torch\csrc\api\include;$(IncludePath)</IncludePath>
82+
<LibraryPath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\x64\vc14\lib;D:\AllentFiles\code\dependency\libtorch17release\lib;$(LibraryPath)</LibraryPath>
83+
</PropertyGroup>
84+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
85+
<OutDir>$(SolutionDir)bin\$(Platform)_$(Configuration)\</OutDir>
86+
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)_$(Configuration)\</IntDir>
87+
<IncludePath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\include;D:\AllentFiles\code\dependency\libtorch17release\include;D:\AllentFiles\code\dependency\libtorch17release\include\torch\csrc\api\include;$(IncludePath)</IncludePath>
88+
<LibraryPath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\x64\vc14\lib;D:\AllentFiles\code\dependency\libtorch17release\lib;$(LibraryPath)</LibraryPath>
89+
</PropertyGroup>
90+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
91+
<OutDir>$(SolutionDir)bin\$(Platform)_$(Configuration)\</OutDir>
92+
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)_$(Configuration)\</IntDir>
93+
<IncludePath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\include;D:\AllentFiles\code\dependency\libtorch17release\include;D:\AllentFiles\code\dependency\libtorch17release\include\torch\csrc\api\include;$(IncludePath)</IncludePath>
94+
<LibraryPath>D:\AllentFiles\code\dependency\opencv-4.5.0-vc14_vc15\opencv\build\x64\vc14\lib;D:\AllentFiles\code\dependency\libtorch17release\lib;$(LibraryPath)</LibraryPath>
95+
</PropertyGroup>
96+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
97+
<ClCompile>
98+
<WarningLevel>Level3</WarningLevel>
99+
<Optimization>Disabled</Optimization>
100+
<SDLCheck>true</SDLCheck>
101+
<ConformanceMode>false</ConformanceMode>
102+
<PreprocessorDefinitions />
103+
</ClCompile>
104+
<Link>
105+
<SubSystem>Console</SubSystem>
106+
<AdditionalDependencies>opencv_world450.lib;asmjit.lib;c10.lib;c10d.lib;c10_cuda.lib;caffe2_detectron_ops_gpu.lib;caffe2_module_test_dynamic.lib;caffe2_nvrtc.lib;clog.lib;cpuinfo.lib;dnnl.lib;fbgemm.lib;gloo.lib;gloo_cuda.lib;libprotobuf-lite.lib;libprotobuf.lib;libprotoc.lib;mkldnn.lib;torch.lib;torch_cpu.lib;torch_cuda.lib;/INCLUDE:?warp_size@cuda@at@@YAHXZ;%(AdditionalDependencies)</AdditionalDependencies>
107+
</Link>
108+
</ItemDefinitionGroup>
109+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
110+
<ClCompile>
111+
<WarningLevel>Level3</WarningLevel>
112+
<Optimization>Disabled</Optimization>
113+
<SDLCheck>true</SDLCheck>
114+
<ConformanceMode>false</ConformanceMode>
115+
<PreprocessorDefinitions />
116+
</ClCompile>
117+
<Link>
118+
<SubSystem>Console</SubSystem>
119+
<AdditionalDependencies>opencv_world450.lib;asmjit.lib;c10.lib;c10d.lib;c10_cuda.lib;caffe2_detectron_ops_gpu.lib;caffe2_module_test_dynamic.lib;caffe2_nvrtc.lib;clog.lib;cpuinfo.lib;dnnl.lib;fbgemm.lib;gloo.lib;gloo_cuda.lib;libprotobuf-lite.lib;libprotobuf.lib;libprotoc.lib;mkldnn.lib;torch.lib;torch_cpu.lib;torch_cuda.lib;/INCLUDE:?warp_size@cuda@at@@YAHXZ;%(AdditionalDependencies)</AdditionalDependencies>
120+
</Link>
121+
</ItemDefinitionGroup>
122+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
123+
<ClCompile>
124+
<WarningLevel>Level3</WarningLevel>
125+
<Optimization>MaxSpeed</Optimization>
126+
<FunctionLevelLinking>true</FunctionLevelLinking>
127+
<IntrinsicFunctions>true</IntrinsicFunctions>
128+
<SDLCheck>true</SDLCheck>
129+
<ConformanceMode>false</ConformanceMode>
130+
<PreprocessorDefinitions />
131+
</ClCompile>
132+
<Link>
133+
<SubSystem>Console</SubSystem>
134+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
135+
<OptimizeReferences>true</OptimizeReferences>
136+
<AdditionalDependencies>opencv_world450.lib;asmjit.lib;c10.lib;c10d.lib;c10_cuda.lib;caffe2_detectron_ops_gpu.lib;caffe2_module_test_dynamic.lib;caffe2_nvrtc.lib;clog.lib;cpuinfo.lib;dnnl.lib;fbgemm.lib;gloo.lib;gloo_cuda.lib;libprotobuf-lite.lib;libprotobuf.lib;libprotoc.lib;mkldnn.lib;torch.lib;torch_cpu.lib;torch_cuda.lib;/INCLUDE:?warp_size@cuda@at@@YAHXZ;%(AdditionalDependencies)</AdditionalDependencies>
137+
</Link>
138+
</ItemDefinitionGroup>
139+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
140+
<ClCompile>
141+
<WarningLevel>Level3</WarningLevel>
142+
<Optimization>MaxSpeed</Optimization>
143+
<FunctionLevelLinking>true</FunctionLevelLinking>
144+
<IntrinsicFunctions>true</IntrinsicFunctions>
145+
<SDLCheck>true</SDLCheck>
146+
<ConformanceMode>false</ConformanceMode>
147+
<PreprocessorDefinitions />
148+
</ClCompile>
149+
<Link>
150+
<SubSystem>Console</SubSystem>
151+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
152+
<OptimizeReferences>true</OptimizeReferences>
153+
<AdditionalDependencies>opencv_world450.lib;asmjit.lib;c10.lib;c10d.lib;c10_cuda.lib;caffe2_detectron_ops_gpu.lib;caffe2_module_test_dynamic.lib;caffe2_nvrtc.lib;clog.lib;cpuinfo.lib;dnnl.lib;fbgemm.lib;gloo.lib;gloo_cuda.lib;libprotobuf-lite.lib;libprotobuf.lib;libprotoc.lib;mkldnn.lib;torch.lib;torch_cpu.lib;torch_cuda.lib;/INCLUDE:?warp_size@cuda@at@@YAHXZ;%(AdditionalDependencies)</AdditionalDependencies>
154+
</Link>
155+
</ItemDefinitionGroup>
156+
<ItemGroup>
157+
<ClCompile Include="src\utils\Augmentations.cpp" />
158+
<ClCompile Include="src\DetDataset.cpp" />
159+
<ClCompile Include="src\Detector.cpp" />
160+
<ClCompile Include="src\models\CSPdarknet53_tiny.cpp" />
161+
<ClCompile Include="src\main.cpp" />
162+
<ClCompile Include="src\utils\tinystr.cpp" />
163+
<ClCompile Include="src\utils\tinyxml.cpp" />
164+
<ClCompile Include="src\utils\tinyxmlerror.cpp" />
165+
<ClCompile Include="src\utils\tinyxmlparser.cpp" />
166+
<ClCompile Include="src\utils\util.cpp" />
167+
<ClCompile Include="src\models\yolo4_tiny.cpp" />
168+
<ClCompile Include="src\models\yolo_training.cpp" />
169+
</ItemGroup>
170+
<ItemGroup>
171+
<ClInclude Include="src\utils\Augmentations.h" />
172+
<ClInclude Include="src\DetDataset.h" />
173+
<ClInclude Include="src\Detector.h" />
174+
<ClInclude Include="src\models\CSPdarknet53_tiny.h" />
175+
<ClInclude Include="src\utils\readfile.h" />
176+
<ClInclude Include="src\utils\tinystr.h" />
177+
<ClInclude Include="src\utils\tinyxml.h" />
178+
<ClInclude Include="src\utils\util.h" />
179+
<ClInclude Include="src\utils\_dirent.h" />
180+
<ClInclude Include="src\models\yolo4_tiny.h" />
181+
<ClInclude Include="src\models\yolo_training.h" />
182+
</ItemGroup>
183+
<ItemGroup>
184+
<None Include="weights\detector.pt" />
185+
<None Include="weights\yolo4_tiny.pt" />
186+
</ItemGroup>
187+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
188+
<ImportGroup Label="ExtensionTargets">
189+
</ImportGroup>
190+
</Project>

libtorch_detection.vcxproj.filters

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="src\main.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
<ClCompile Include="src\utils\util.cpp">
22+
<Filter>Source Files</Filter>
23+
</ClCompile>
24+
<ClCompile Include="src\models\CSPdarknet53_tiny.cpp">
25+
<Filter>Source Files</Filter>
26+
</ClCompile>
27+
<ClCompile Include="src\models\yolo4_tiny.cpp">
28+
<Filter>Source Files</Filter>
29+
</ClCompile>
30+
<ClCompile Include="src\models\yolo_training.cpp">
31+
<Filter>Source Files</Filter>
32+
</ClCompile>
33+
<ClCompile Include="src\Detector.cpp">
34+
<Filter>Source Files</Filter>
35+
</ClCompile>
36+
<ClCompile Include="src\DetDataset.cpp">
37+
<Filter>Source Files</Filter>
38+
</ClCompile>
39+
<ClCompile Include="src\utils\tinystr.cpp">
40+
<Filter>Source Files</Filter>
41+
</ClCompile>
42+
<ClCompile Include="src\utils\tinyxml.cpp">
43+
<Filter>Source Files</Filter>
44+
</ClCompile>
45+
<ClCompile Include="src\utils\tinyxmlerror.cpp">
46+
<Filter>Source Files</Filter>
47+
</ClCompile>
48+
<ClCompile Include="src\utils\tinyxmlparser.cpp">
49+
<Filter>Source Files</Filter>
50+
</ClCompile>
51+
<ClCompile Include="src\utils\Augmentations.cpp">
52+
<Filter>Source Files</Filter>
53+
</ClCompile>
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ClInclude Include="src\utils\util.h">
57+
<Filter>Header Files</Filter>
58+
</ClInclude>
59+
<ClInclude Include="src\utils\_dirent.h">
60+
<Filter>Header Files</Filter>
61+
</ClInclude>
62+
<ClInclude Include="src\utils\readfile.h">
63+
<Filter>Header Files</Filter>
64+
</ClInclude>
65+
<ClInclude Include="src\models\CSPdarknet53_tiny.h">
66+
<Filter>Header Files</Filter>
67+
</ClInclude>
68+
<ClInclude Include="src\models\yolo4_tiny.h">
69+
<Filter>Header Files</Filter>
70+
</ClInclude>
71+
<ClInclude Include="src\models\yolo_training.h">
72+
<Filter>Header Files</Filter>
73+
</ClInclude>
74+
<ClInclude Include="src\Detector.h">
75+
<Filter>Header Files</Filter>
76+
</ClInclude>
77+
<ClInclude Include="src\DetDataset.h">
78+
<Filter>Header Files</Filter>
79+
</ClInclude>
80+
<ClInclude Include="src\utils\tinystr.h">
81+
<Filter>Header Files</Filter>
82+
</ClInclude>
83+
<ClInclude Include="src\utils\tinyxml.h">
84+
<Filter>Header Files</Filter>
85+
</ClInclude>
86+
<ClInclude Include="src\utils\Augmentations.h">
87+
<Filter>Header Files</Filter>
88+
</ClInclude>
89+
</ItemGroup>
90+
<ItemGroup>
91+
<None Include="weights\yolo4_tiny.pt" />
92+
<None Include="weights\detector.pt" />
93+
</ItemGroup>
94+
</Project>

libtorch_detection.vcxproj.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ShowAllFiles>true</ShowAllFiles>
5+
</PropertyGroup>
6+
</Project>

src/DetDataset.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include "DetDataset.h"
2+
#include"utils/tinyxml.h"
3+
#include "utils/readfile.h"
4+
5+
std::vector<BBox> loadXML(std::string xml_path)
6+
{
7+
std::vector<BBox> objects;
8+
// XML文档
9+
TiXmlDocument doc;
10+
// 加载XML文档
11+
if (!doc.LoadFile(xml_path.c_str()))
12+
{
13+
std::cerr << doc.ErrorDesc() << std::endl;
14+
return objects;
15+
}
16+
17+
// 定义根节点变量并赋值为文档的第一个根节点
18+
TiXmlElement *root = doc.FirstChildElement();
19+
// 如果没有找到根节点,说明是空XML文档或者非XML文档
20+
if (root == NULL)
21+
{
22+
std::cerr << "Failed to load file: No root element." << std::endl;
23+
// 清理内存
24+
doc.Clear();
25+
return objects;
26+
}
27+
28+
// 遍历子节点
29+
for (TiXmlElement *elem = root->FirstChildElement(); elem != NULL; elem = elem->NextSiblingElement())
30+
{
31+
// 获取元素名
32+
std::string elemName = elem->Value();
33+
std::string name = "";
34+
// 获取元素属性值
35+
if (strcmp(elemName.data(), "object") == 0)
36+
{
37+
for (TiXmlNode *object = elem->FirstChildElement(); object != NULL; object = object->NextSiblingElement())
38+
{
39+
if (strcmp(object->Value(), "name") == 0)
40+
{
41+
name = object->FirstChild()->Value();
42+
}
43+
44+
if (strcmp(object->Value(), "bndbox") == 0)
45+
{
46+
BBox obj;
47+
TiXmlElement * xmin = object->FirstChildElement("xmin");
48+
TiXmlElement * ymin = object->FirstChildElement("ymin");
49+
TiXmlElement * xmax = object->FirstChildElement("xmax");
50+
TiXmlElement * ymax = object->FirstChildElement("ymax");
51+
52+
obj.xmin = atoi(std::string(xmin->FirstChild()->Value()).c_str());
53+
obj.xmax = atoi(std::string(xmax->FirstChild()->Value()).c_str());
54+
obj.ymin = atoi(std::string(ymin->FirstChild()->Value()).c_str());
55+
obj.ymax = atoi(std::string(ymax->FirstChild()->Value()).c_str());
56+
obj.name = name;
57+
objects.push_back(obj);
58+
}
59+
60+
//cout << bndbox->Value() << endl;
61+
}
62+
}
63+
}
64+
//std::cout << xml_path << std::endl;
65+
// 清理内存
66+
doc.Clear();
67+
return objects;
68+
}
69+
70+
//遍历该目录下的.xml文件,并且找到对应的
71+
void load_det_data_from_folder(std::string folder, std::string image_type,
72+
std::vector<std::string> &list_images, std::vector<std::string> &list_labels)
73+
{
74+
for_each_file(folder,
75+
// filter函数,lambda表达式
76+
[&](const char*path, const char* name) {
77+
auto full_path = std::string(path).append({ file_sepator() }).append(name);
78+
std::string lower_name = tolower1(name);
79+
80+
//判断是否为jpeg文件
81+
if (end_with(lower_name, ".xml")) {
82+
list_labels.push_back(full_path);
83+
std::string image_path = replace_all_distinct(full_path, ".xml", image_type);
84+
image_path = replace_all_distinct(image_path, "\\labels\\", "\\images\\");
85+
list_images.push_back(image_path);
86+
}
87+
//因为文件已经已经在lambda表达式中处理了,
88+
//不需要for_each_file返回文件列表,所以这里返回false
89+
return false;
90+
}
91+
, true//递归子目录
92+
);
93+
}

0 commit comments

Comments
 (0)