justadudewhohacks / face-api.js

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

How to createCanvasFromMedia with actually canvas element #740

Closed viniciusxavier77 closed 3 years ago

viniciusxavier77 commented 3 years ago

Hi, i´m trying to implement a solution with my camera, which works with a live stream solution though the rtsp protocol plus JSMpegPlayer library. The stream is showed on a canvas element, like this:

HTML with canvas element - the video goes here

canvas id="video" /canvas

The JS script implemented

player = new JSMpeg.Player('ws://localhost:9999', {
  canvas: document.getElementById('video'), audio: false // Canvas should be a canvas DOM element
})  

How can i integrate this with face api? First i tried to use createCanvasFromMedia method, but HTMLCanvas element is not an acceptable parameter. So, i guess my doubt is how to createMedia from an external camera, not the camera from my notebook is it possible?

viniciusxavier77 commented 3 years ago

Got it, it's quite simple, you have only to get thecontent with the method captureStream, so, the video content will be

stream = video.captureStream(25); const videoEl = document.getElementById('myVideo') videoEl.srcObject = stream

Closing this.