justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.53k stars 3.69k forks source link

Syntax for changing landmark line and point draw color with DrawFaceLandmarksOptions() #738

Open cthompto opened 3 years ago

cthompto commented 3 years ago

Looking for clear documentation on how to change the point and line color for landmarks being draw onto a live webcam feed, using the following is unsuccessful:

const options = { lineColor: "#FFFFFF" }

const detections = await faceapi.detectSingleFace(video, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceExpressions()

const resizedDetections = faceapi.resizeResults(detections, displaySize)

canvas.getContext("2d").clearRect(0, 0, canvas.width, canvas.height)

faceapi.draw.drawFaceLandmarks(canvas, resizedDetections, options)

faceapi.draw.drawFaceExpressions(canvas, resizedDetections)

cindyloo commented 3 years ago

you'll need to pass in options. Here's a start:

function getFaceDetectorOptions() {
  if (selected_face_detector == "tiny_face_detector") {
    return new self.faceapi.TinyFaceDetectorOptions({
      inputSize,
      scoreThreshold,
      drawLines: true,
      drawPoints: false
    });
  } 
}

and then

result = await self.faceapi
      .detectSingleFace(imgCanvas, detector_options)
      .withFaceLandmarks(true);
svkmedia commented 1 year ago

In case somebody will need to adjust lines and dots in FaceLandmarks this is how to do it:

const faceLandmarksConfig = new DrawFaceLandmarksOptions({
                drawPoints: false,
                pointSize: 2,
                pointColor: '#fff',
                drawLines: true,
                lineColor: '#fff',
                lineWidth: 2
            })

new DrawFaceLandmarks(resizeResults.landmarks, faceLandmarksConfig).draw(canvasElem)