2013-04-10 2 views
0

나는 사진 얼굴 검출을 위해 this plugin을 사용하고 있습니다. 작동하지만 그림에 얼굴이 감지되지 않으면 오류 기능이 호출되지 않습니다. 대신 "complete"함수가 호출됩니다.이 Jquery 플러그인은 항상 배열을 반환합니까?

나는 그것이 어떤 배열을 반환, 얼굴을 인식하지 못하는, 또는 정의되지 않은 객체, 또는 null, 또는 뭔가를 반환 할 때내는, 그래서 나는 시도했다 :

//also tried null this way 
if(typeof coords[i].confidence === 'undefined') { 
alert("you have little aptitude for programming."); 
} 


if(coords instanceof Array) { 

     alert("good job!!"); 
} else { 
alert("not even close!!"); 
} 


if(!(coords.length)) { 
alert("you have a distorted perception of your own abilities."); 
} 


if (positionX > coords.length) { 

alert(coords[i].confidence); 
} 

얼굴이 표시 감지되면 적절한 경고가 나오지 만 얼굴이 감지되지 않으면 경고가 표시되지 않습니다. 그냥 "완료"기능을 호출합니다.

다음은 스크립트입니다. 더 많은 코드를 제공해야하는지 알려주세요.

<script> 
    $(function() { 
     $('#try').click(function() { 
      var $this = $(this); 

      var coords = $('img').faceDetection({ 


       complete:function(img, coords) { 
        $this.text('Done!'); 

       }, 
       error:function(img, code, message) { 
        $this.text('error!'); 
        alert('Error: '+message); 
       } 

      }); 



      for (var i = 0; i < coords.length; i++) { 

//Here is where I have been putting those conditional statements. 

//This part, which appends a bordered div (#face) to the div containing the face pic, works fine. 

       $('<div>', { 
        'class':'face', 
        'id':'face', 
        'css': { 
         'position': 'absolute', 
         'left':  coords[i].positionX +'px', 
         'top':  coords[i].positionY +'px', 
         'width': coords[i].width +'px', 
         'height': coords[i].height +'px' 
        } 

       }) 
       .appendTo('#content');        


      } 
     }); 


     return false; 
    }); 
    </script> 

<a href="#" id="try">TRY IT NOW!</a>    

<div id="content"> 
<img src="pic.jpg" id="myPicture"/> 
</div> 
+0

아마도'complete'는 jQuery의'ajax' 메소드의 complete 옵션과 마찬가지로 성공 또는 실패 여부에 관계없이 호출됩니다. –

+0

콘솔에'coords' 로깅을 시도해 보았습니다. 얼굴이 인식되지 않을 때 그 값이 무엇인지 보셨습니까? – JCOC611

답변

0

complete 실제로 성공 여부에 관계없이 호출됩니다. 얼굴을 감지하지 못하는 경우 플러그인은 빈 배열을 반환하므로 알림이 표시되지 않습니다. for 루프가 실행되지 않습니다.

+0

맞습니다. 나는 내가 설정 한 어떤 조건도 실패했을 때 그 경고를 호출하지 못하는 이유를 이해할 수 없었다.하지만 나는 잘못된 지점에 배치하고있는 것으로 나타났다. 이제 나는 if (! (coords.length)) { alert ("fail"); } 루프를 따라 가면 작동합니다. 당신의 도움을 주셔서 감사합니다! – user1877124

관련 문제