Showing
1 changed file
with
72 additions
and
81 deletions
... | @@ -406,109 +406,100 @@ function RecommendationResult(replyToken, query) { | ... | @@ -406,109 +406,100 @@ function RecommendationResult(replyToken, query) { |
406 | 406 | ||
407 | } | 407 | } |
408 | 408 | ||
409 | -imgtodata = function(dir){ | 409 | +var arrmenu=new Array('술','야식','한식','치킨','양식','중식','일식','고기','디저트','카페'); |
410 | +imgtodata = function(dir) { | ||
410 | var api_url = 'https://openapi.naver.com/v1/vision/face'; // 얼굴 감지 | 411 | var api_url = 'https://openapi.naver.com/v1/vision/face'; // 얼굴 감지 |
411 | 412 | ||
412 | var _formData = { | 413 | var _formData = { |
413 | - image:'image', | 414 | + image: 'image', |
414 | image: fs.createReadStream(path.join(__dirname, dir)) // FILE 이름 | 415 | image: fs.createReadStream(path.join(__dirname, dir)) // FILE 이름 |
415 | }; | 416 | }; |
416 | 417 | ||
417 | - request.post( | 418 | + request.post({ |
418 | - { url:api_url, | 419 | + url: api_url, |
419 | - formData:_formData, | 420 | + formData: _formData, |
420 | - headers: {'X-Naver-Client-Id':client_id, | 421 | + headers: { |
421 | - 'X-Naver-Client-Secret': client_secret} | 422 | + 'X-Naver-Client-Id': client_id, |
422 | - }, (err,response,body) =>{ | 423 | + 'X-Naver-Client-Secret': client_secret |
424 | + } | ||
425 | + }, (err, response, body) => { | ||
423 | console.log(response.statusCode); // 200 | 426 | console.log(response.statusCode); // 200 |
424 | //console.log(response.headers['content-type']) | 427 | //console.log(response.headers['content-type']) |
425 | console.log(body); | 428 | console.log(body); |
426 | - var cfrdata=JSON.parse(body); | 429 | + var cfrdata = JSON.parse(body); |
430 | + | ||
431 | + var facenum = cfrdata.info.faceCount; | ||
432 | + //인식된 얼굴이 없을 때 | ||
433 | + if (facenum == 0) { | ||
427 | 434 | ||
428 | - var cfrgender=cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json) | 435 | + |
429 | - var cfremotion=cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json) | 436 | + } |
437 | + //얼굴 1개 이상 | ||
438 | + else { | ||
439 | + //제일 잘 인식되는 얼굴 기준 | ||
440 | + var cfrgender = cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json) | ||
441 | + var cfremotion = cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json) | ||
430 | 442 | ||
431 | var gender = cfrgender; //사용자 성별 | 443 | var gender = cfrgender; //사용자 성별 |
432 | var emotion = cfremotion; //사용자 감정 | 444 | var emotion = cfremotion; //사용자 감정 |
433 | 445 | ||
434 | - | 446 | + console.log(facenum); |
435 | console.log(gender); | 447 | console.log(gender); |
436 | console.log(emotion); | 448 | console.log(emotion); |
437 | 449 | ||
438 | - if(gender=='male'){ | 450 | + if (gender == 'male') { |
439 | - if(emotion=='angry'){ | 451 | + if (emotion == 'angry') { |
440 | - menu='술'; | 452 | + menu = arrmenu[0]; |
441 | - } | 453 | + } else if (emotion == 'disgust') { |
442 | - else if(emotion=='disgust'){ | 454 | + menu = arrmenu[1]; |
443 | - menu='야식'; | 455 | + } else if (emotion == 'fear') { |
444 | - } | 456 | + menu = arrmenu[2]; |
445 | - else if(emotion=='fear'){ | 457 | + } else if (emotion == 'laugh') { |
446 | - menu='한식'; | 458 | + menu = arrmenu[3]; |
447 | - } | 459 | + } else if (emotion == 'neutral') { |
448 | - else if(emotion=='laugh'){ | 460 | + menu = arrmenu[4]; |
449 | - menu='치킨'; | 461 | + } else if (emotion == 'sad') { |
450 | - } | 462 | + menu = arrmenu[5]; |
451 | - else if(emotion=='neutral'){ | 463 | + } else if (emotion == 'surprise') { |
452 | - menu='양식'; | 464 | + menu = arrmenu[6]; |
453 | - } | 465 | + } else if (emotion == 'smile') { |
454 | - else if(emotion=='sad'){ | 466 | + menu = arrmenu[7]; |
455 | - menu='중식'; | 467 | + } else if (emotion == 'talking') { |
456 | - } | 468 | + menu = arrmenu[0]; |
457 | - else if(emotion=='surprise'){ | 469 | + } else { |
458 | - menu='일식'; | 470 | + menu = ''; |
459 | - } | 471 | + } |
460 | - else if(emotion=='smile'){ | 472 | + } |
461 | - menu='고기'; | 473 | + else if (gender == 'female') { |
462 | - } | 474 | + if (emotion == 'angry') { |
463 | - else if(emotion=='talking'){ | 475 | + menu = arrmenu[7]; |
464 | - menu='술'; | 476 | + } else if (emotion == 'disgust') { |
465 | - } | 477 | + menu = arrmenu[8]; |
466 | - else{ | 478 | + } else if (emotion == 'fear') { |
467 | - menu=''; | 479 | + menu = arrmenu[2]; |
468 | - } | 480 | + } else if (emotion == 'laugh') { |
469 | - } | 481 | + menu = arrmenu[6]; |
470 | - else if(gender=='female'){ | 482 | + } else if (emotion == 'neutral') { |
471 | - if(emotion=='angry'){ | 483 | + menu = arrmenu[5]; |
472 | - menu='고기'; | 484 | + } else if (emotion == 'sad') { |
473 | - } | 485 | + menu = arrmenu[1]; |
474 | - else if(emotion=='disgust'){ | 486 | + } else if (emotion == 'surprise') { |
475 | - menu='디저트'; | 487 | + menu = arrmenu[5]; |
476 | - } | 488 | + } else if (emotion == 'smile') { |
477 | - else if(emotion=='fear'){ | 489 | + menu = arrmenu[3]; |
478 | - menu='한식'; | 490 | + } else if (emotion == 'talking') { |
479 | - } | 491 | + menu = arrmenu[9]; |
480 | - else if(emotion=='laugh'){ | 492 | + } else { |
481 | - menu='일식'; | 493 | + menu = ''; |
482 | - } | ||
483 | - else if(emotion=='neutral'){ | ||
484 | - menu='중식'; | ||
485 | - } | ||
486 | - else if(emotion=='sad'){ | ||
487 | - menu='야식'; | ||
488 | - } | ||
489 | - else if(emotion=='surprise'){ | ||
490 | - menu='중식'; | ||
491 | - } | ||
492 | - else if(emotion=='smile'){ | ||
493 | - menu='치킨'; | ||
494 | - } | ||
495 | - else if(emotion=='talking'){ | ||
496 | - menu='카페'; | ||
497 | - } | ||
498 | - else{ | ||
499 | - menu=''; | ||
500 | - } | ||
501 | } | 494 | } |
502 | - else{ | 495 | + } else { |
503 | - menu=''; | 496 | + menu = ''; |
504 | } | 497 | } |
505 | 498 | ||
506 | console.log(menu); | 499 | console.log(menu); |
507 | - | ||
508 | - | ||
509 | - //return {gender:gender,emotion:emotion}; | ||
510 | - }); | ||
511 | } | 500 | } |
501 | + }); | ||
502 | +} | ||
512 | 503 | ||
513 | //사용자가 보낸 사진 저장 | 504 | //사용자가 보낸 사진 저장 |
514 | const config = ({ | 505 | const config = ({ | ... | ... |
-
Please register or login to post a comment