tensorflow.js+coco-ssd实现实时视频监控行人社交距离效果代码

代码语言:html

所属分类:其他

代码描述:tensorflow.js+coco-ssd实现实时视频监控行人社交距离效果代码

代码标签: tensorflow coco-ssd 视频监控 行人 社交 距离

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">


  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap");
html, body {
  height: 100%;
  font-family: "Roboto", sans-serif;
}

body {
  position: relative;
}

#app {
  display: none;
}

#loader {
  line-height: 100vh;
  text-align: center;
}

#canvas,
#video {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px auto;
}

#canvas {
  background: black;
}

:focus {
  outline: none;
}
</style>



</head>

<body  >
  <div id="loader">加载模型中...</div>
<div id="app">
   <video id="video" crossOrigin="anonymous" width="472" height="266" controls="true" loop>
     <source src="//repo.bfw.wiki/bfwrepo/video/61b97fcf80dc8.mp4" type="video/mp4">

   Your browser does not support mp4 and ogg extension.
  </video>
  <canvas id="canvas" width="472" height="266">
  </canvas>
</div>


<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/tf.2.0.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/coco-ssd.js"></script>
      <script  >
// Experiment using TensorFlow & COCO-SSD
const app = document.getElementById('app');
const loader = document.getElementById('loader');
const canvas = document.getElementById('canvas');
const video = document.getElementById('video');
const ctx = canvas.getContext('2d');

let modelPromise;
let model;
let predictions;
let maxDistance = 75;

window.onload = async () => {
  modelPromise = cocoSsd.load({ base: 'mobilenet_v2' });
  model = await modelPromise;

  video.addEventListener('play', () => requestAnimationFrame(updateCanvas), false);

  ctx.font = '14px Arial';
  ctx.fillStyle = 'lightgrey';
  const title = 'Real-time social distancing detection 😷';
  const textSize = ctx.measureText(title).width;
  ctx.fillText(
  title,
 .........完整代码请登录后点击上方下载按钮下载查看

网友评论0