问题描述
string[] fileEntries = Directory.GetFiles(Application.StartupPath + "/TrainedFaces/", "*.bmp", SearchOption.AllDirectories);
Array.Sort(fileEntries);
foreach (string fileName in (fileEntries))
{
LoadFaces = System.IO.Path.GetFileName(fileName);
trainingImages.Add(new Image<Gray, byte>(fileName));
}
我认为是错误的输出:
[0] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/1 \\ 1.bmp"
[1] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/2 \\ 2.bmp"
[2] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/2 \\ 9.bmp"
[3] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/3 \\ 3.bmp"
[4] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/4 \\ 4.bmp"
我期望的是
[0] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFace/1 \\ 1.bmp"
[1] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/2 \\ 2.bmp"
[2] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/3 \\ 3.bmp"
[3] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/4 \\ 4.bmp"
[4] ="N:\\ FaceRecProOV-复制(2)\\ FaceRecProOV \\ bin \\ Debug/TrainedFaces/4 \\ 9.bmp"
Output that I believe is wrong:
[0] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/1\\1.bmp"
[1] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/2\\2.bmp"
[2] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/2\\9.bmp"
[3] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/3\\3.bmp"
[4] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/4\\4.bmp"
What I expected is
[0] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFace/1\\1.bmp"
[1] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/2\\2.bmp"
[2] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/3\\3.bmp"
[3] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/4\\4.bmp"
[4] = "N:\\FaceRecProOV - Copy (2)\\FaceRecProOV\\bin\\Debug/TrainedFaces/4\\9.bmp"
推荐答案
string[] fileEntries = Directory.GetFiles(Application.StartupPath + "/TrainedFaces/", "*.bmp", SearchOption.AllDirectories);
List<FileInfo> FileInfos = fileEntries.ToList().ConvertAll(x => new FileInfo(x)).ToList();
FileInfos = FileInfos.OrderBy(x => x.Name).ToList();
foreach (FileInfo AFileInfo in FileInfos)
{
LoadFaces = AFileInfo.Name;
trainingImages.Add(new Image<Gray, byte>(AFileInfo.FullName));
}
希望这会有所帮助,
Ed
Hope this helps,
Ed
这篇关于排序字符串Arry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!