Skip to content

Commit

Permalink
Fix error when single face is being detected
Browse files Browse the repository at this point in the history
  • Loading branch information
mLauper committed Nov 9, 2016
1 parent 4731adb commit 3465113
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Functions/Invoke-IdentifyFaces.Tests.ps1
Expand Up @@ -35,5 +35,28 @@ Describe "InvokeIdentifyFaces" {
Remove-PersonGroup -personGroupId "pester-persongroup-1"
}

Context "When a single face should be identified in a person group"{
New-PersonGroup -personGroupId "pester-persongroup-1"
New-Person "pester-person-1" -personGroupId "pester-persongroup-1"
New-PersonFace -personName "pester-person-1" -personGroupId "pester-persongroup-1" -LocalImagePath "$here\..\SampleImages\Face_01.JPG"
New-PersonFace -personName "pester-person-1" -personGroupId "pester-persongroup-1" -LocalImagePath "$here\..\SampleImages\Face_01.JPG"
New-PersonFace -personName "pester-person-1" -personGroupId "pester-persongroup-1" -LocalImagePath "$here\..\SampleImages\Face_01.JPG"
Start-PersonGroupTraining -personGroupId "pester-persongroup-1"
$face = Invoke-FaceDetection -localImagePath "$here\..\SampleImages\Face_01.JPG"
While ($true) {
$trainingStatus = Get-PersonGroupTrainingStatus "pester-persongroup-1" | select -Last 1
if ($trainingStatus.status -ne "notstarted" -and $trainingStatus.status -ne "running"){
break
} else {
sleep 1
}
}

$result = Invoke-IdentifyFaces -faceIds $face.faceId -personGroup "pester-persongroup-1"
It "Should return a result" {
$result | Should Not BeNullOrEmpty
}
Remove-PersonGroup -personGroupId "pester-persongroup-1"
}

}
4 changes: 3 additions & 1 deletion Functions/Invoke-IdentifyFaces.ps1
Expand Up @@ -20,7 +20,9 @@ function Invoke-IdentifyFaces {
$Request = "https://api.projectoxford.ai/face/v1.0/identify"

$Body = "{ `"personGroupId`":`"$personGroupId`""
$Body = $Body + ", `"faceIds`":" + ($faceIds | ConvertTo-Json)
$Body = $Body + ", `"faceIds`":"
if (($faceIds | measure).Count -eq 1) {$Body = $Body + "[`"$($faceIds[0])`"]"}
elseif (($faceIds | measure).Count -gt 1) {$Body = $Body + ($faceIds | ConvertTo-Json)}
if ($maxNumOfCandidatesReturned -ne $null) {$Body = $Body + ",`"maxNumOfCandidatesReturned`":`"$maxNumOfCandidatesReturned`"" }
if ($confidenceThreshold -ne 0) {$Body = $Body + ",`"confidenceThreshold`": `"$confidenceThreshold`""}
$Body = $Body + "}"
Expand Down
Binary file modified ps-AzureFaceAPI.psd1
Binary file not shown.

0 comments on commit 3465113

Please sign in to comment.