-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efca9cc
commit b1079f8
Showing
17 changed files
with
485 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,6 @@ RUN go mod download | |
|
||
RUN go build -o main . | ||
|
||
EXPOSE 5000 | ||
EXPOSE 443 | ||
|
||
CMD ["./main"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
push: | ||
git status | ||
git add . | ||
git commit -m "$$(date)" | ||
git pull origin facedetection | ||
git push origin facedetection | ||
|
||
gorun: | ||
go run main.go | ||
|
||
run: | ||
./main | ||
|
||
compile: | ||
go build main.go | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<html oncontextmenu='return false' onkeydown='return false'> | ||
<head> | ||
<meta name='viewport' content='width=device-width, initial-scale=1.0'> | ||
<title>Enrrolar</title> | ||
<script async src='opencv.js' onload='openCvReady();'></script> | ||
<script src='utils.js'></script> | ||
<style> .labele { color: white; padding: 8px; font-family: Arial; background-color: #ff9800; } .labelt { color: white; padding: 8px; font-family: Arial; background-color: #04aa6d; } @media only screen and (max-width: 992px) { video.camara { height:640px; width:480px; display: block; margin-left: auto; margin-right: auto; } } @media only screen and (min-width: 993px) { video.camara { height:480px; width:640px; display: block; margin-left: auto; margin-right: auto;} } </style> | ||
</head> | ||
<body bgcolor='#000' onload="setTimeout('temporizador()',1000)"> | ||
<br> | ||
<center> | ||
<span id='Tiempo' class='labelt'>0</span> | ||
<span id='Estado' class='labele'>Iniciando...</span> | ||
</center> | ||
<br> | ||
<br> | ||
<center> | ||
<! canvas id='canvas_output' /><! /canvas> | ||
<video id='cam_input' height='480' width='640' class='camara'></video> | ||
</center> | ||
<script> | ||
/* variables globales para el funcionamiento */ | ||
let tiempo = 0; | ||
let stop = 0; | ||
/* aperturamos webcam con opencv */ | ||
function openCvReady() { | ||
cv['onRuntimeInitialized'] = () => { | ||
let video = document.getElementById('cam_input'); | ||
/*video.style.display='none';*/ | ||
navigator.mediaDevices.getUserMedia({ video: true, audio: false }).then(function (stream) { | ||
video.srcObject = stream; video.play(); | ||
}).catch(function (err) { | ||
console.log('Error: ' + err); | ||
}); | ||
let src = new cv.Mat(video.height, video.width, cv.CV_8UC4); | ||
let gray = new cv.Mat(); | ||
let cap = new cv.VideoCapture(cam_input); | ||
let faces = new cv.RectVector(); | ||
let faceClassifier = new cv.CascadeClassifier(); | ||
let utils = new Utils('errorMessage'); | ||
let faceCascade = 'haarcascade_frontalface_default.xml'; | ||
utils.createFileFromUrl(faceCascade, faceCascade, () => { faceClassifier.load(faceCascade); }); | ||
const FPS = 40; | ||
function processVideo() { | ||
let begin = Date.now(); | ||
cap.read(src); | ||
cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0); | ||
let detectado=0; | ||
try { | ||
faceClassifier.detectMultiScale(gray, faces, 1.1, 3, 0); | ||
for (let i = 0; i < faces.size(); ++i) { | ||
let face = faces.get(i); | ||
let point1 = new cv.Point(face.x, face.y); | ||
let point2 = new cv.Point(face.x + face.width, face.y + face.height); | ||
cv.rectangle(src, point1, point2, [0, 255, 0, 255]); | ||
detectado = 1; | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
if(detectado==1){ | ||
document.getElementById('Estado').innerHTML = 'Rostro detectado'; | ||
document.getElementById('Estado').style.backgroundColor='#04aa6d'; | ||
} else { | ||
document.getElementById('Estado').innerHTML = 'Rostro no detectado'; | ||
document.getElementById('Estado').style.backgroundColor='#f44336'; | ||
} | ||
/*cv.imshow('canvas_output', src);*/ | ||
let delay = 1000 / FPS - (Date.now() - begin); | ||
setTimeout(processVideo, delay); | ||
} | ||
setTimeout(processVideo, 0); | ||
} | ||
} | ||
|
||
/* temporizador que usa la variable global tiempo para contar los segundos */ | ||
function temporizador() { | ||
if(stop==0){ | ||
if(document.getElementById('Estado').textContent=='Rostro detectado'){ | ||
tiempo = tiempo + 1; | ||
document.getElementById('Tiempo').innerHTML = tiempo; | ||
} else { | ||
tiempo = 0;document.getElementById('Tiempo').innerHTML = tiempo; | ||
} | ||
/*cuando haya pasado 3 segundos de la deteccion de un rostro ejecutar()*/ | ||
if(tiempo == 3){ | ||
stop = 1; | ||
tiempo = 0; | ||
document.getElementById('Tiempo').innerHTML = tiempo; | ||
ejecutar(); | ||
} | ||
} | ||
setTimeout('temporizador()',1000); | ||
} | ||
|
||
/* generamos el archivo de imagen sin el recuadro */ | ||
function ejecutar(){ | ||
let imageCanvas = document.createElement('canvas'); | ||
let imageCtx = imageCanvas.getContext('2d'); | ||
let v = document.getElementById('cam_input'); | ||
imageCanvas.width = v.videoWidth; | ||
imageCanvas.height = v.videoHeight; | ||
imageCtx.drawImage(v, 0, 0, v.videoWidth, v.videoHeight); | ||
imageCanvas.toBlob(postFile, 'image/jpeg'); | ||
} | ||
|
||
/* enviamos el 'file' y el 'identificador' a la url 'enrrolar' por metodo 'POST' */ | ||
function postFile(file) { | ||
let formdata = new FormData(); | ||
let identificador = prompt('Ingrese un identificador:'); | ||
if(identificador==null){ | ||
stop = 0; | ||
return | ||
} | ||
formdata.append('id', identificador); | ||
formdata.append('image', file); | ||
let xhr = new XMLHttpRequest(); | ||
xhr.open('POST', 'enrrolar', true); | ||
xhr.onload = function () { | ||
if (this.status === 200){ | ||
alert(this.response); | ||
stop = 0; | ||
} else { | ||
alert(this.response); | ||
stop = 0; | ||
} | ||
}; | ||
xhr.onerror = function () { | ||
alert('Error de comunicacion con el servidor'); | ||
stop = 0; | ||
}; | ||
xhr.onabort = function () { | ||
alert('Peticion de reconocimiento abortada'); | ||
stop = 0; | ||
}; | ||
xhr.send(formdata); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module github.com/RicardoValladares/FaceDetect | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require github.com/leandroveronezi/go-recognizer v1.0.0 | ||
require github.com/leandroveronezi/go-recognizer v1.0.1 | ||
|
||
require ( | ||
github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e // indirect | ||
github.com/disintegration/imaging v1.6.2 // indirect | ||
github.com/fogleman/gg v1.3.0 // indirect | ||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect | ||
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect | ||
golang.org/x/image v0.5.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.