Skip to content

Commit

Permalink
map done detect face
Browse files Browse the repository at this point in the history
  • Loading branch information
codecrack3 committed Jun 13, 2018
1 parent efb8b38 commit dae4ead
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 27 deletions.
29 changes: 5 additions & 24 deletions public/assets/css/custom.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 68 additions & 3 deletions resources/views/modules/indexcontent.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<div class="card-body">
<div class="img-detection">
<img class="rounded" width="100%" src="{!!asset('assets/images/faces.png') !!}" alt="">
<span class="detected">Name</span>
<span class="undetected">Name</span>
<!-- <span class="detected">Name</span>
<span class="undetected">Name</span> -->
</div>
</div>
</div>
Expand Down Expand Up @@ -61,7 +61,12 @@
</div>
</div>
<script>
function remove(){
$('.detected').remove();
$('.undetected').remove();
}
function read(input){
remove()
if (input.files && input.files[0]) {
var reader = new FileReader();
Expand All @@ -72,12 +77,31 @@ function read(input){
reader.readAsDataURL(input.files[0]);
}
}
function detect_face()
{
var image = new Image();
image.src = $('.rounded').attr("src");
var nwidth = image.naturalWidth;
var nheight = image.naturalHeight;
var width = Math.round($('.rounded').width());
var height = Math.round($('.rounded').height());
console.log(width + ':' + height +'-' +nwidth +":" +nheight);
return {"nwdith":nwidth,'nheight':nheight,"width":width,"height":height};
}
$(document).ready(function () {
// $("#anhup").change(function(){
// $(".rounded").attr('src',formData.get('fileanh'))
// })
$("#data").submit(function(e) {
remove()
e.preventDefault();
// console.log($("#lophoc").val());
var formData = new FormData(this);
Expand All @@ -86,14 +110,55 @@ function read(input){
$('#img-detection').html('<img src="'+formData.get('fileanh')+'">');
}
reader.readAsDataURL(formData.get('fileanh'));
var toado = detect_face();
formData.append('malop',$("#lophoc").val());
formData.append('_token',"{{csrf_token()}}");
$.ajax({
url: '{{ route('diemdanh') }}',
type: 'POST',
data: formData,
success: function (data) {
console.log('data');
console.log(data);
$.each(data['images'],function(index,val1){
if('transaction' in val1){
var left = Math.round(val1['transaction'].topLeftX * toado.width / toado.nwdith);
var top = Math.round((val1['transaction'].topLeftY * toado.height) / toado.nheight);
var width = val1['transaction'].width * toado.width / toado.nwdith;
var height = val1['transaction'].height * toado.height / toado.nheight;
console.log(val1['transaction'].topLeftX)
console.log(left + '::' + top + '::'+width+'::'+height)
if(val1['transaction'].status === 'success')
{
$('<div>', {
'class':'detected',
'css': {
'position': 'absolute',
'left': left + 'px',
'top': top + 'px',
'width': width + 'px',
'height': height + 'px'
}
}).insertAfter($('.rounded'))
}
else{
$('<div>', {
'class':'undetected',
'css': {
'position': 'absolute',
'left': left + 'px',
'top': top + 'px',
'width': width + 'px',
'height': height + 'px'
}
}).insertAfter($('.rounded'))
}
}
})
},
cache: false,
contentType: false,
Expand Down

0 comments on commit dae4ead

Please sign in to comment.