zoukankan      html  css  js  c++  java
  • [ML] Tensorflow.js + Image segmentPerson

    <!DOCTYPE html>
    <html>
      <head>
        <title>Parcel Sandbox</title>
        <meta charset="UTF-8" />
        <!-- Load TensorFlow.js -->
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.2"></script> 
        <!-- Load BodyPix -->
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix@2.0"></script> 
      </head>
    
      <body>
        <img
          id="image"
          src="image/image.jpg"
        />
        <canvas id="canvas"/>
    
        <script>
          const img = document.getElementById("image");
    
          function loadAndPredict() {
            bodyPix.load()
              .then((net)=> net.segmentPersonParts(img))
              .then(partSegmentation  => {
                const coloredPartImage = bodyPix.toColoredPartMask(partSegmentation);
                const opacity = 0.7;
                const flipHorizontal = false;
                const maskBlurAmount = 0;
                const pixelCellWidth = 10.0;
                const canvas = document.getElementById('canvas');
                // Draw the pixelated colored part image on top of the original image onto a
                // canvas.  Each pixel cell's width will be set to 10 px. The pixelated colored
                // part image will be drawn semi-transparent, with an opacity of 0.7, allowing
                // for the original image to be visible under.
                bodyPix.drawPixelatedMask(
                    canvas, img, coloredPartImage, opacity, maskBlurAmount,
                    flipHorizontal, pixelCellWidth);
              });
          }
          loadAndPredict();
        </script>
      </body>
    </html>

  • 相关阅读:
    python完成简单购物功能
    Java对字符串进行加密
    python完成留言板功能
    webpack4 学习
    webpack学习之 vue-cli3和4
    节点操作
    new 做了什么
    从url输入网址后发生什么
    防抖节流
    BFC原理和解决方案
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11937216.html
Copyright © 2011-2022 走看看