Skip to content

Instantly share code, notes, and snippets.

@dagingaa
Created March 22, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagingaa/31980b9f12e14981ac117d39b90ed835 to your computer and use it in GitHub Desktop.
Save dagingaa/31980b9f12e14981ac117d39b90ed835 to your computer and use it in GitHub Desktop.
// run in console on a https page
stream = await navigator.mediaDevices.getUserMedia({ video: true, audio:true })
video = document.createElement("video");
video.muted = true;
video.srcObject = stream;
await video.play();
canvas = document.createElement("canvas")
ctx = canvas.getContext("2d")
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
imageData = ctx.getImageData(0,0,video.videoWidth, video.videoHeight)
value = imageData.data.reduce((cur, i) => cur + i,0)
result = value / imageData.data.length
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment