Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <div class="container-fluid text-center" id="app">  
  <div class="row my-5">
        <div class="text-nowrap col-sm-6 mx-auto">
          <h1>&#x1F93C;プロレス技図鑑&#x1F93C;</h1>
        </div>
  </div>

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

CSS

              
                
              
            
!

JS

              
                // 作成したモデルのURL
const imageModelURL = 'https://teachablemachine.withgoogle.com/models/5uartv7TV/';

// メインの関数(ここでは定義しているだけでボタンクリックされたら実行)
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, () => {
    // 読み込みが完了次第ここが実行されます
    console.log('モデルの読み込みが完了しました');
  });
  
  // 繰り返し処理
  function loop() {
    // 推論を実行し、エラーがあればerrに、結果をresultsに格納して、
    // 推論が完了次第 { } の中身を実行します
    classifier.classify(async (err, results) => {
      // 結果のresultsは配列ですが、先頭に中身があれば以下の処理を実行します
      if (results[0]) {
        document.getElementById("result").textContent = results[0].label;// 結果を画面表示
      }
      // 推論終了1秒後に自分の関数を実行(ループになる)
      setTimeout(loop, 1000);
    });
  }

  // 最初の繰り返し処理を実行
  loop();
}

              
            
!
999px

Console