[Python] Microsoft Cognitive Services의 Face API 사용
7525 단어 Python
Microsoft Cognitive Services - Face API
https://www.microsoft.com/cognitive-services/en-us/face-api
이미지에 포함된 얼굴의 위치와 그 사람의 성별, 나이 등을 측정할 수 있다.
Subscription Key
Face Preview(무료)의 Subscription Key를 Cognitive Services에서 받으십시오.
Key1과 Key2가 있습니다. Key1만 있으면 됩니다.
Python에서 API
Version은 2.7입니다.3도 움직일 거야.
미리 pip로 Requests를 설치합니다.$ pip install requests
이미지 파일 버전
detect.pyimport sys
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age,gender', # age, gender, headPose, smile, facialHair, and glasses.
}
if __name__ == '__main__':
argv = sys.argv
if len(argv) == 1:
print 'Usage: # python %s [filename]' % argv[0]
quit()
r = requests.post(url ,headers = headers,params = params,data = open(argv[1],'rb'))
print(r.text)
image.png의 얼굴 검사를 진행하려면 다음과 같이 실행하십시오.$ python detect.py image.png
사진 링크판
URL을 사용하여 이미지를 지정할 때는 다음과 같습니다.
detect.pyimport sys
import json
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
image_url = 'http://example.com/image.png'
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age, gender', # age, gender, headPose, smile, facialHair, and glasses.
}
payload = {
'url': image_url,
}
if __name__ == '__main__':
r = requests.post(url ,headers = headers, params = params, data = json.dumps(payload))
print(r.text)
image_URL의 얼굴을 검사하려면 다음과 같이 실행하십시오.$ python detect.py
결과 내보내기
[
{
"faceId": "xxxxxxxxxxxxxxxxxxxxxxxx",
"faceRectangle": {
"top": 119,
"left": 177,
"width": 144,
"height": 144
},
"faceAttributes": {
"gender": "female",
"age": 17.9
}
}
]
제이슨을 통해 결과를 알 수 있고 보답을 받았다.
파람스 변경을 통해서도 얼굴 부위의 위치 정보 등을 얻을 수 있다.
Reference
이 문제에 관하여([Python] Microsoft Cognitive Services의 Face API 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/1060ki/items/d5c76356ba04ecdf0f80
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Face Preview(무료)의 Subscription Key를 Cognitive Services에서 받으십시오.
Key1과 Key2가 있습니다. Key1만 있으면 됩니다.
Python에서 API
Version은 2.7입니다.3도 움직일 거야.
미리 pip로 Requests를 설치합니다.$ pip install requests
이미지 파일 버전
detect.pyimport sys
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age,gender', # age, gender, headPose, smile, facialHair, and glasses.
}
if __name__ == '__main__':
argv = sys.argv
if len(argv) == 1:
print 'Usage: # python %s [filename]' % argv[0]
quit()
r = requests.post(url ,headers = headers,params = params,data = open(argv[1],'rb'))
print(r.text)
image.png의 얼굴 검사를 진행하려면 다음과 같이 실행하십시오.$ python detect.py image.png
사진 링크판
URL을 사용하여 이미지를 지정할 때는 다음과 같습니다.
detect.pyimport sys
import json
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
image_url = 'http://example.com/image.png'
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age, gender', # age, gender, headPose, smile, facialHair, and glasses.
}
payload = {
'url': image_url,
}
if __name__ == '__main__':
r = requests.post(url ,headers = headers, params = params, data = json.dumps(payload))
print(r.text)
image_URL의 얼굴을 검사하려면 다음과 같이 실행하십시오.$ python detect.py
결과 내보내기
[
{
"faceId": "xxxxxxxxxxxxxxxxxxxxxxxx",
"faceRectangle": {
"top": 119,
"left": 177,
"width": 144,
"height": 144
},
"faceAttributes": {
"gender": "female",
"age": 17.9
}
}
]
제이슨을 통해 결과를 알 수 있고 보답을 받았다.
파람스 변경을 통해서도 얼굴 부위의 위치 정보 등을 얻을 수 있다.
Reference
이 문제에 관하여([Python] Microsoft Cognitive Services의 Face API 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/1060ki/items/d5c76356ba04ecdf0f80
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ pip install requests
import sys
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age,gender', # age, gender, headPose, smile, facialHair, and glasses.
}
if __name__ == '__main__':
argv = sys.argv
if len(argv) == 1:
print 'Usage: # python %s [filename]' % argv[0]
quit()
r = requests.post(url ,headers = headers,params = params,data = open(argv[1],'rb'))
print(r.text)
$ python detect.py image.png
import sys
import json
import requests
url = 'https://api.projectoxford.ai/face/v1.0/detect'
image_url = 'http://example.com/image.png'
headers = {
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '[your subscription key]',
}
params = {
'returnFaceId': 'true', # The default value is true.
'returnFaceLandmarks': 'false', # The default value is false.
'returnFaceAttributes': 'age, gender', # age, gender, headPose, smile, facialHair, and glasses.
}
payload = {
'url': image_url,
}
if __name__ == '__main__':
r = requests.post(url ,headers = headers, params = params, data = json.dumps(payload))
print(r.text)
$ python detect.py
[
{
"faceId": "xxxxxxxxxxxxxxxxxxxxxxxx",
"faceRectangle": {
"top": 119,
"left": 177,
"width": 144,
"height": 144
},
"faceAttributes": {
"gender": "female",
"age": 17.9
}
}
]
Reference
이 문제에 관하여([Python] Microsoft Cognitive Services의 Face API 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/1060ki/items/d5c76356ba04ecdf0f80텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)