Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


  <script src=""></script>
  <script src=""></script>

<body onload="setup()">
  <div style="text-align:center">
    <h1>What's on camera?</h1>
    <video id="video">Video stream not available.</video>
    <pre id="predictions"></pre>
    <canvas id="canvas" style="display:none"></canvas>


                * {
  background: rgb(32,32,32);
  color: whitesmoke;
  font-family: avenir, arial;
  padding: 10px;
  border-radius: 10px;


                // body calls setup() onload:
function setup() {

  let video = document.getElementById("video");
  let canvas = document.getElementById("canvas");
  let predictionsText = document.getElementById("predictions");
  let model = null;


  async function main() {
    model = await mobilenet.load();
    await startCamera();

  async function startCamera() {
    let stream = await navigator.mediaDevices.getUserMedia({ video: true });
    video.srcObject = stream;
    setInterval(() => takeSnapshot(), 1000);

  function takeSnapshot() {
    let context = canvas.getContext("2d");
    let width = video.videoWidth;
    let height = video.videoHeight;
    let hasWidthAndHeight = width && height;
    if (hasWidthAndHeight) {
      // Setup a canvas with the same dimensions as the video.
      canvas.width = width;
      canvas.height = height;
      // Make a copy of the current frame in the video on the canvas.
      context.drawImage(video, 0, 0, width, height);

  async function classifyImage() {
    predictions = await model.classify(canvas);

  function displayPredictions(predictions) {
    let outputString = "";
    for (prediction of predictions) {
      let percent = (prediction.probability * 100).toFixed(2);
      outputString += `${percent}% | ${prediction.className}\n`;
    predictionsText.innerHTML = outputString;