Skip to content

Commit

Permalink
vie 19 may 2023 10:45:09 CST
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoValladares committed May 19, 2023
1 parent efca9cc commit b1079f8
Show file tree
Hide file tree
Showing 17 changed files with 485 additions and 414 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ RUN go mod download

RUN go build -o main .

EXPOSE 5000
EXPOSE 443

CMD ["./main"]
17 changes: 17 additions & 0 deletions Makefile
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

Empty file modified desktop.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docker-compose.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: '1'
version: '2'

services:
facedetect:
build:
context: .
dockerfile: Dockerfile
ports:
- "5000:5000"
- "443:443"
restart: unless-stopped
volumes:
- ./enrrolados:/docker/enrrolados
Expand Down
140 changes: 140 additions & 0 deletions enrrolar.html
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>
6 changes: 3 additions & 3 deletions go.mod
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
)
32 changes: 27 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
github.com/Kagami/go-face v0.0.0-20200513173138-d4af7c8eab1c/go.mod h1:9wdDJkRgo3SGTcFwbQ7elVIQhIr2bbBjecuY7VoqmPU=
github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e h1:lqIUFzxaqyYqUn4MhzAvSAh4wIte/iLNcIEWxpT/qbc=
github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e/go.mod h1:9wdDJkRgo3SGTcFwbQ7elVIQhIr2bbBjecuY7VoqmPU=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
Expand All @@ -7,9 +6,32 @@ github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/leandroveronezi/go-recognizer v1.0.0 h1:mluUOP9bAcHDufWO05kt52oCegLqAzAoR816iuHWPR0=
github.com/leandroveronezi/go-recognizer v1.0.0/go.mod h1:KlzwM1vzmGgncxPhH5Vfr9403ibeOrd/0kXIYidp6TA=
github.com/leandroveronezi/go-recognizer v1.0.1 h1:Z1r4uFxw3nMngq8K1OzVFcpH+x2aZ/4yvw3VilOSVQ0=
github.com/leandroveronezi/go-recognizer v1.0.1/go.mod h1:HZheSqJ3AxOeT5E87q9agqJb+m9bX6+4l4KnCq2CBDg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Empty file modified haarcascade_frontalface_default.xml
100644 → 100755
Empty file.
Loading

0 comments on commit b1079f8

Please sign in to comment.