Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
How to detect and use face landmark detection from face-api.js on the image snapshotted from the webcam?

I want to use face landmark detection from face-api.js library on the image snapshotted from a webcam when the capture button is pressed. How do i do that?

I know it is not the perfect code, but my process of thinking was take the snapshot from the webcam, place it in the <img src""> then use the face landmark detection on the snapshotted image.

HTML

    <img src="" id="originalImg" />
    <canvas id="canvas" width="320" height="240"></canvas>
    <canvas id="reflay" width="320" height="240" class="overlay"></canvas>
    <video id="player" width="320" height="240" autoplay></video>
    <button id="capture">Capture</button>


    <script>
      const player = document.getElementById('player');
      const canvas = document.getElementById('canvas');
      const context = canvas.getContext('2d');
      const captureButton = document.getElementById('capture');

      const constraints = {
        video: true,
      };

      captureButton.addEventListener('click', () => {
        // Draw the video frame to the canvas.
        context.drawImage(player, 0, 0, canvas.width, canvas.height);
      });

      // Attach the video stream to the video element and autoplay.
      navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
        player.srcObject = stream;
      });
    </script>

JavaScript

$(document).ready(function(){
                
    async function face(){
        
        const MODEL_URL = '/models'

        await faceapi.loadSsdMobilenetv1Model(MODEL_URL)
        await faceapi.loadFaceLandmarkModel(MODEL_URL)


        const img = convertCanvasToImage();
        let faceDescriptions = await faceapi.detectAllFaces(img).withFaceLandmarks()
        const canvas = $('#reflay').get(0)
        faceapi.matchDimensions(canvas, img)

        faceDescriptions = faceapi.resizeResults(faceDescriptions, img)
        faceapi.draw.drawDetections(canvas, faceDescriptions)
        faceapi.draw.drawFaceLandmarks(canvas, faceDescriptions)

    }
    
    return face()
})

function convertCanvasToImage(){
    var image = new Image();
    image.src = canvas.toDataURL("image/jpeg");
    return image = document.getElementById('originalImg');
}

Here is the JSFiddle if that makes it easier. Thank you.

JSFiddle

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda