前提・実現したいこと
FaceAPIで顔識別するプログラムを書いております。
jpgを1つ1つ読み込むことは可能なのですが、ディレクトリのすべてのjpgを読み込ませようとすると以下のようなエラーが出てきます。
読み込ませているところのソースを張っておきます
発生している問題・エラーメッセージ
FaceAPIException: The length of faceIds is not in a valid range.(BadArgument)
該当のソースコード
C#
1 2 private static async Task IdentifyPerson(FaceServiceClient faceServiceClient, string personGroupId) 3 { 4 string testImageDir = @"F:\face_test\"; 5 6 foreach (string imagePath in Directory.GetFiles(testImageDir, "*.jpg")) 7 { 8 9 using (Stream s = File.OpenRead(imagePath)) 10 { 11 var faces = await faceServiceClient.DetectAsync(s); 12 var faceIds = faces.Select(face => face.FaceId).ToArray(); 13 14 var results = await faceServiceClient.IdentifyAsync(personGroupId, faceIds); 15 foreach (var identifyResult in results) 16 { 17 Console.WriteLine("Result of face: {0}", identifyResult.FaceId); 18 if (identifyResult.Candidates.Length == 0) 19 { 20 Console.WriteLine("No one identified"); 21 } 22 else 23 { 24 // Get top 1 among all candidates returned 25 var candidateId = identifyResult.Candidates[0].PersonId; 26 var person = await faceServiceClient.GetPersonAsync(personGroupId, candidateId); 27 Console.WriteLine($"Identified as {person.Name}"); 28 29 using (var sw = new System.IO.StreamWriter(@"test.csv")) 30 { 31 sw.WriteLine("{0}, {1}", imagePath, person.Name); 32 } 33 34 } 35 36 37 38 } 39 40 } 41 } 42 43 Console.WriteLine("Identify is finished!"); 44 } 45
試したこと
MSのサイトなどを見ましたがわかりませんでした
エラーだけでなく、その行番号も載せておいたほうがよいかと。
あなたの回答
tips
プレビュー