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.


                <div class="container-fluid text-center" id="app">  
  <div class="row my-5">
        <div class="text-nowrap col-sm-6 mx-auto">

    <button onclick="start()" type="button" class="btn btn-success">開始</button><br>
  <video id="webcam" width="400" height="290" muted autoplay playsinline></video>
  <p id="result"></p>




                // 作成したモデルのURL
const imageModelURL = '';

// メインの関数(ここでは定義しているだけでボタンクリックされたら実行)
async function start() {
  // カメラからの映像ストリーム取得
  const stream = await navigator.mediaDevices.getUserMedia({
    audio: false,
    video: true,
    video: { facingMode: "environment" },//背面カメラ
  // 「id="webcam"」となっているパーツ(videoタグ)を取得
  const video = document.getElementById('webcam');
  // videoにカメラ映像ストリームをセット
  video.srcObject = stream;
  // Googleのサーバーにアップロードした自作モデルを読み込みにいきます
  const classifier = ml5.imageClassifier(imageModelURL + 'model.json', video, () => {
    // 読み込みが完了次第ここが実行されます
  // 繰り返し処理
  function loop() {
    // 推論を実行し、エラーがあればerrに、結果をresultsに格納して、
    // 推論が完了次第 { } の中身を実行します
    classifier.classify(async (err, results) => {
      // 結果のresultsは配列ですが、先頭に中身があれば以下の処理を実行します
      if (results[0]) {
        document.getElementById("result").textContent = results[0].label;// 結果を画面表示
      // 推論終了1秒後に自分の関数を実行(ループになる)
      setTimeout(loop, 1000);

  // 最初の繰り返し処理を実行