Skip to content

Instantly share code, notes, and snippets.

@Rinatamu
Last active November 9, 2018 08:32
Show Gist options
  • Save Rinatamu/4b4650f9f4efa2b0afde5238b14d91b9 to your computer and use it in GitHub Desktop.
Save Rinatamu/4b4650f9f4efa2b0afde5238b14d91b9 to your computer and use it in GitHub Desktop.
PowerShell で FaceAPI に投げてみる ref: https://qiita.com/rnakamuramartiny/items/48af81533a05e0817914
$Face_API_KEY = '<FaceAPI Key>'
$URL = 'https://japaneast.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age,gender,smile,facialHair,headPose,glasses,emotion,hair,makeup,accessories,blur,exposure,noise'
$image = '<FaceAPIに投げるファイルのフルパス>'
$headers = @{
'Ocp-Apim-Subscription-Key' = $Face_API_KEY
'Accept' = 'application/json'
'Content-Type' = 'application/octet-stream'
}
$result = Invoke-RestMethod `
-Uri $URL `
-Method Post `
-Headers $headers `
-InFile $image
$result_ps = ($result | ConvertFrom-Json)
faceId :
faceRectangle : @{top=337; left=746; width=318; height=318}
faceLandmarks : @{pupilLeft=; pupilRight=; noseTip=; mouthLeft=; mouthRight=; eyebrowLeftOuter=; eyebrowLeftInner=; ey
eLeftOuter=; eyeLeftTop=; eyeLeftBottom=; eyeLeftInner=; eyebrowRightInner=; eyebrowRightOuter=; eyeRi
ghtInner=; eyeRightTop=; eyeRightBottom=; eyeRightOuter=; noseRootLeft=; noseRootRight=; noseLeftAlarT
op=; noseRightAlarTop=; noseLeftAlarOutTip=; noseRightAlarOutTip=; upperLipTop=; upperLipBottom=; unde
rLipTop=; underLipBottom=}
faceAttributes : @{smile=0.743; headPose=; gender=female; age=21.0; facialHair=; glasses=NoGlasses; emotion=; blur=; ex
posure=; noise=; makeup=; accessories=System.Object[]; hair=}
($result_ps.faceAttributes.hair.hairColor | `
Sort-Object -Property confidence -Descending | `
Select-Object -First 1).Color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment