나는 사진 얼굴 검출을 위해 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>
아마도'complete'는 jQuery의'ajax' 메소드의 complete 옵션과 마찬가지로 성공 또는 실패 여부에 관계없이 호출됩니다. –
콘솔에'coords' 로깅을 시도해 보았습니다. 얼굴이 인식되지 않을 때 그 값이 무엇인지 보셨습니까? – JCOC611