📚 Course contents

AI & Computer Vision, lesson 6 of 52

JavaScript for Computer Vision: Your Webcam in the Browser

beginner18 min readFull course

Introduction

Python is great on your laptop, but your friends won't install it to see your project. A web browser is already on every phone and laptop, and it can use the camera too. Today you rebuild the lesson 2 webcam loop in JavaScript, then change the pixels yourself to make live filters.

By the end of this lesson you'll be able to:

  • Ask for webcam access with navigator.mediaDevices.getUserMedia()
  • Show the stream in a <video> element and copy frames to a <canvas>
  • Read the pixels of a frame with getImageData() and change them
  • Write a loop that runs once per frame with requestAnimationFrame
  • Explain why the page must run from localhost or https
  • Compare the Python loop from lesson 2 with the JavaScript loop
JavaScript for Computer Vision: Your Webcam in the Browser