1 카카오 API - Vision API

카카오 API - Vision API를 활용하면 현재 “얼굴검출”, “상품검출”, “썸네일” “멀티태그 생성” “성인이미지 판별” 작업을 수행할 수 있다.

이미 친숙한 How-Old.net 서비스나, 마이크로소프트 애져 Cognitive Services - Face와 유사하다.

2 카카오 API KEY

가장 먼저 카카오 API KEY를 받아야 사진 정보를 카카오 API에 던졌을 때 얼굴검출을 사진속에서 할 수 있다.

  1. 카카오 개발자 센터에 회원 가입한다. Kakao Developers
  2. “내 애플리케이션”에서 “앱 만들기”를 클릭하여 입을 생성한다.
  3. 생성한 앱에서 “앱정보” → “앱키” → “REST API키”를 복사하여 활용한다.

생성된 REST API키를 usethis::edit_r_environ() 명령어를 사용해서 .Renviron에 키-값 짝으로 저장시켜 추후 재사용한다.

3 얼굴인식 API 헬로월드

curl 명령어를 사용해서 앞서 준비한 API KEY를 사용해서 정상적으로 사진 속 이미지를 인식하는지 확인한다.

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 27.0.237.16...
* TCP_NODELAY set
* Connected to kapi.kakao.com (27.0.237.16) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [220 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [93 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4079 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=KR; ST=Jeju-do; L=Jeju-si; O=Kakao Corp.; CN=*.kakao.com
*  start date: Jul  9 00:00:00 2018 GMT
*  expire date: Oct  8 12:00:00 2020 GMT
*  subjectAltName: host "kapi.kakao.com" matched cert's "*.kakao.com"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=Thawte TLS RSA CA G1
*  SSL certificate verify ok.
> POST /v1/vision/face/detect HTTP/1.1
> Host: kapi.kakao.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: KakaoAK 335a10636ee663383134e1560da1faad
> Content-Length: 72
> Content-Type: application/x-www-form-urlencoded
> 
} [72 bytes data]
* upload completely sent off: 72 out of 72 bytes
< HTTP/1.1 200 OK
< Date: Mon, 22 Apr 2019 04:12:06 GMT
< Server: Apache
< Quota-Type: INC_AND_CHECK
< Content-Type: application/json;charset=UTF-8
< Content-Length: 3224
< 
{ [3224 bytes data]

100  3296  100  3224  100    72   7906    176 --:--:-- --:--:-- --:--:--  7921
* Connection #0 to host kapi.kakao.com left intact
{"result":{"width":900,"height":780,"faces":[{"facial_attributes":{"gender":{"male":1.852084242273122E-4,"female":0.9998148083686829},"age":26.83161163330078},"facial_points":{"jaw":[[0.39988815155929,0.4597163545375075],[0.40076365725357194,0.4919288974017492],[0.40546697996929376,0.5238266913226928],[0.4138891439360871,0.5546161695020512],[0.42467514802233847,0.5836692674509779],[0.43806688492406104,0.6110579700894445],[0.45364497658812786,0.6353582361319029],[0.47173999183849896,0.6556910619735179],[0.4964329642348522,0.6629302561661311],[0.5272498964440828,0.6558442937681535],[0.5574304000523214,0.6365127986404545],[0.5853054403708957,0.6116739215797226],[0.6075996216326539,0.5813461707437183],[0.621242128057884,0.5464769590386854],[0.6273095232652657,0.5079275694928798],[0.6287490368456476,0.4691592717577292],[0.6282002502785117,0.4302802243568629]],"right_eyebrow":[[0.39599309794482057,0.42201739908918495],[0.4051166985134195,0.4140428482233955],[0.4177621539408728,0.41333816389932526],[0.4316635831925265,0.4177477403616378],[0.44443900001597814,0.4254196985996625]],"left_eyebrow":[[0.4835053956530918,0.4206912659581911],[0.503182329137454,0.4094101500124181],[0.5255417504739469,0.40325481322780454],[0.5480393513535383,0.4043782347764472],[0.5686317072466676,0.41436874931622114]],"nose":[[0.4654094589327385,0.4547987133930385],[0.46318292807917333,0.47811415642314103],[0.46089826953399465,0.5013969935923374],[0.45857568737977356,0.5244732639693],[0.4496086377354352,0.5396099442091116],[0.45837532567714034,0.544609352031824],[0.4686119698371557,0.5475862513809354],[0.48168133558490733,0.5434536396547478],[0.4944650046839767,0.5382375997523046]],"right_eye":[[0.4142208936067651,0.45665297877468847],[0.42335795787565844,0.4505984248159411],[0.43540374794155495,0.4507062919345331],[0.4471211738857448,0.45759592609563415],[0.4353429172713271,0.4622121047913335],[0.4236897348491508,0.46282369308186716]],"left_eye":[[0.5045749364828938,0.4539066044373463],[0.516424535351039,0.44473413471897427],[0.531202388354105,0.44370407304356396],[0.5454936915551986,0.44806726491220333],[0.5323012720234628,0.4560796748053783],[0.5180910991350183,0.4574687632381]],"lip":[[0.4486181121102725,0.5803562757085547],[0.4549785006434541,0.5735871729714412],[0.4645470858921278,0.5698794297893226],[0.4747330560288295,0.5714956251314866],[0.48815476459493384,0.5673231775491484],[0.5075825189447206,0.5697361845240662],[0.5283479200747906,0.5750310613027585],[0.512129638847064,0.5931472556612033],[0.4945204566997903,0.6033978767619163],[0.47955683534832666,0.6064533924645459],[0.46720857105436964,0.6043426276437671],[0.45656514226431644,0.5950960780394812],[0.45424711285437747,0.5808172312223513],[0.46580626438415496,0.5805804055611318],[0.47638351115238037,0.5811021465905016],[0.4918218874900453,0.5782507561784437],[0.5203299026036047,0.5770582952634475],[0.4935242452635527,0.5859178904817328],[0.47769285856565696,0.5893859254555084],[0.4662694020228778,0.5874273055673349]]},"score":0.9966461062431335,"class_idx":0,"x":0.36406812879774303,"y":0.3577516213441506,"w":0.28629075792100694,"h":0.3303354899088542,"pitch":-0.2745622396469116,"yaw":0.3854277431964874,"roll":-0.002884101588279009}]}}