R语言:用微软的深度学习得到人脸的特征数据

本文系转载,原地址:http://blog.csdn.net/wzgl__wh/article/details/52904069

微软的深度学习https://www.microsoft.com/cognitive-services/en-US/subscriptions,使用Face功能来检测人脸的特征。下面用R语言来跑下案例:

> img.url = 'https://www.whitehouse.gov/sites/whitehouse.gov/files/images/first-family/44_barack_obama[1].jpg'
> faceURL = "https://api.projectoxford.ai/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age"
> faceKEY = 'a868182e859c4458953f69dab084f5e8'
> mybody = list(url = img.url)
> faceResponse = POST(  
+   url = faceURL,   
+   content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = faceKEY)),  
+   body = mybody,  
+   encode = 'json'  
+ )
> faceResponse
Response [https://api.projectoxford.ai/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=true&returnFaceAttributes=age]
  Date: 2017-01-03 04:33
  Status: 200
  Content-Type: application/json; charset=utf-8
  Size: 1.19 kB

> ObamaR = httr::content(faceResponse)[[1]]
> OR<-as.data.frame(as.matrix(ObamaR$faceLandmarks))
> OR
                              V1
pupilLeft           475.4, 158.6
pupilRight          590.6, 157.3
noseTip             534.4, 227.7
mouthLeft           460.8, 273.7
mouthRight          603.6, 268.2
eyebrowLeftOuter    425.2, 154.8
eyebrowLeftInner    508.4, 142.3
eyeLeftOuter        458.6, 162.6
eyeLeftTop          473.6, 153.8
eyeLeftBottom       475.9, 164.9
eyeLeftInner        492.8, 162.0
eyebrowRightInner   552.3, 141.4
eyebrowRightOuter   636.0, 156.2
eyeRightInner       571.7, 159.9
eyeRightTop         588.1, 152.5
eyeRightBottom      587.4, 163.9
eyeRightOuter       605.5, 161.5
noseRootLeft        511.2, 163.4
noseRootRight       551.2, 163.0
noseLeftAlarTop     503.1, 204.6
noseRightAlarTop    559.2, 201.6
noseLeftAlarOutTip  485.3, 226.9
noseRightAlarOutTip 580.5, 224.1
upperLipTop         530.9, 264.3
upperLipBottom      532.1, 272.5
underLipTop         530.3, 305.1
underLipBottom      532.5, 318.6
> OR$V2 <- lapply(strsplit(as.character(OR$V1), "\\="), "[", 2)
> OR$V2 <- lapply(strsplit(as.character(OR$V2), "\\,"), "[", 1)
> colnames(OR)[2] <- "X"
> OR$X<-as.numeric(OR$X)
> OR$V3 <- lapply(strsplit(as.character(OR$V1), "\\y = "), "[", 2)
> OR$V3 <- lapply(strsplit(as.character(OR$V3), "\\)"), "[", 1)
> colnames(OR)[3] <- "Y"
> OR$Y<-as.numeric(OR$Y)
> OR$V1<-NULL
> OR
                        X     Y
pupilLeft           475.4 158.6
pupilRight          590.6 157.3
noseTip             534.4 227.7
mouthLeft           460.8 273.7
mouthRight          603.6 268.2
eyebrowLeftOuter    425.2 154.8
eyebrowLeftInner    508.4 142.3
eyeLeftOuter        458.6 162.6
eyeLeftTop          473.6 153.8
eyeLeftBottom       475.9 164.9
eyeLeftInner        492.8 162.0
eyebrowRightInner   552.3 141.4
eyebrowRightOuter   636.0 156.2
eyeRightInner       571.7 159.9
eyeRightTop         588.1 152.5
eyeRightBottom      587.4 163.9
eyeRightOuter       605.5 161.5
noseRootLeft        511.2 163.4
noseRootRight       551.2 163.0
noseLeftAlarTop     503.1 204.6
noseRightAlarTop    559.2 201.6
noseLeftAlarOutTip  485.3 226.9
noseRightAlarOutTip 580.5 224.1
upperLipTop         530.9 264.3
upperLipBottom      532.1 272.5
underLipTop         530.3 305.1
underLipBottom      532.5 318.6

就这样得到了人的脸部数据,感觉可以用于比较人与人之间长相的差别。

你可能感兴趣的:(R语言)