daeun

modify cfr

Showing 1 changed file with 86 additions and 95 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);
427 - 430 +
428 - var cfrgender=cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json) 431 + var facenum = cfrdata.info.faceCount;
429 - var cfremotion=cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json) 432 + //인식된 얼굴이 없을 때
430 - 433 + if (facenum == 0) {
431 - var gender = cfrgender; //사용자 성별 434 +
432 - var emotion = cfremotion; //사용자 감정 435 +
433 - 436 + }
434 - 437 + //얼굴 1개 이상
435 - console.log(gender); 438 + else {
436 - console.log(emotion); 439 + //제일 잘 인식되는 얼굴 기준
440 + var cfrgender = cfrdata.faces[0].gender.value; //CFR의 성별 데이터 (json)
441 + var cfremotion = cfrdata.faces[0].emotion.value; //CFR의 감정 데이터 (json)
442 +
443 + var gender = cfrgender; //사용자 성별
444 + var emotion = cfremotion; //사용자 감정
445 +
446 + console.log(facenum);
447 + console.log(gender);
448 + console.log(emotion);
449 +
450 + if (gender == 'male') {
451 + if (emotion == 'angry') {
452 + menu = arrmenu[0];
453 + } else if (emotion == 'disgust') {
454 + menu = arrmenu[1];
455 + } else if (emotion == 'fear') {
456 + menu = arrmenu[2];
457 + } else if (emotion == 'laugh') {
458 + menu = arrmenu[3];
459 + } else if (emotion == 'neutral') {
460 + menu = arrmenu[4];
461 + } else if (emotion == 'sad') {
462 + menu = arrmenu[5];
463 + } else if (emotion == 'surprise') {
464 + menu = arrmenu[6];
465 + } else if (emotion == 'smile') {
466 + menu = arrmenu[7];
467 + } else if (emotion == 'talking') {
468 + menu = arrmenu[0];
469 + } else {
470 + menu = '';
471 + }
472 + }
473 + else if (gender == 'female') {
474 + if (emotion == 'angry') {
475 + menu = arrmenu[7];
476 + } else if (emotion == 'disgust') {
477 + menu = arrmenu[8];
478 + } else if (emotion == 'fear') {
479 + menu = arrmenu[2];
480 + } else if (emotion == 'laugh') {
481 + menu = arrmenu[6];
482 + } else if (emotion == 'neutral') {
483 + menu = arrmenu[5];
484 + } else if (emotion == 'sad') {
485 + menu = arrmenu[1];
486 + } else if (emotion == 'surprise') {
487 + menu = arrmenu[5];
488 + } else if (emotion == 'smile') {
489 + menu = arrmenu[3];
490 + } else if (emotion == 'talking') {
491 + menu = arrmenu[9];
492 + } else {
493 + menu = '';
494 + }
495 + } else {
496 + menu = '';
497 + }
437 498
438 - if(gender=='male'){ 499 + console.log(menu);
439 - if(emotion=='angry'){
440 - menu='술';
441 - }
442 - else if(emotion=='disgust'){
443 - menu='야식';
444 - }
445 - else if(emotion=='fear'){
446 - menu='한식';
447 - }
448 - else if(emotion=='laugh'){
449 - menu='치킨';
450 - }
451 - else if(emotion=='neutral'){
452 - menu='양식';
453 - }
454 - else if(emotion=='sad'){
455 - menu='중식';
456 - }
457 - else if(emotion=='surprise'){
458 - menu='일식';
459 - }
460 - else if(emotion=='smile'){
461 - menu='고기';
462 - }
463 - else if(emotion=='talking'){
464 - menu='술';
465 - }
466 - else{
467 - menu='';
468 - }
469 } 500 }
470 - else if(gender=='female'){ 501 + });
471 - if(emotion=='angry'){ 502 +}
472 - menu='고기';
473 - }
474 - else if(emotion=='disgust'){
475 - menu='디저트';
476 - }
477 - else if(emotion=='fear'){
478 - menu='한식';
479 - }
480 - else if(emotion=='laugh'){
481 - 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 - }
502 - else{
503 - menu='';
504 - }
505 -
506 - console.log(menu);
507 -
508 -
509 - //return {gender:gender,emotion:emotion};
510 - });
511 - }
512 503
513 //사용자가 보낸 사진 저장 504 //사용자가 보낸 사진 저장
514 const config = ({ 505 const config = ({
......