• Fabricjsvideo和摄像头


    video被看做图片处理 new fabric.Image

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Document</title>
      <style>
        .canvas-container {
          border: 1px dotted #ccc;
          display: inline-block;
          vertical-align: top;
          -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    
          width: 1200px;
          height: 700px;
          position: relative;
          user-select: none;
        }
    
        #c {
          border: 1px solid rgb(204, 204, 204);
          position: absolute;
          width: 1200px;
          height: 700px;
          left: 0px;
          top: 0px;
          touch-action: none;
          user-select: none;
        }
      </style>
      <script src="../fabric.js"></script>
    </head>
    
    <body>
      <video id="video1" muted height="360" width="480">
        <source src="https://cloud.video.taobao.com/play/u/828291614/p/1/e/6/t/1/333154089379.mp4" />
      </video>
      <video id="webcam" height="360" width="500" style="display: none"></video>
      <div class="canvas-container">
        <canvas id="c" width="1200" height="700"></canvas>
      </div>
      <script>
        var canvas = new fabric.Canvas('c');
        var video1El = document.getElementById('video1');
        var webcamEl = document.getElementById('webcam');
        var video1 = new fabric.Image(video1El, {
          left: 200,
          top: 300,
          angle: -15,
          originX: 'center',
          originY: 'center',
          objectCaching: false
        });
        var webcam = new fabric.Image(webcamEl, {
          left: 539,
          top: 328,
          angle: 94.5,
          originX: 'center',
          originY: 'center',
          objectCaching: false
        });
        canvas.add(video1);
        video1.getElement().play();
        //下面是摄像头相关内容
        if (navigator.mediaDevices === undefined) {
          navigator.mediaDevices = {};
        }
        if (navigator.mediaDevices.getUserMedia === undefined) {
          navigator.mediaDevices.getUserMedia = function(constraints) {
            var getUserMedia =
              navigator.webkitGetUserMedia ||
              navigator.mozGetUserMedia ||
              navigator.msGetUserMedia;
            if (!getUserMedia) {
              return Promise.reject(
                new Error('getUserMedia is not implemented in this browser')
              );
            }
            return new Promise(function(resolve, reject) {
              getUserMedia.call(navigator, constraints, resolve, reject);
            });
          };
        }
        navigator.mediaDevices
          .getUserMedia({ video: true })
          .then(function getWebcamAllowed(localMediaStream) {
            webcamEl.srcObject = localMediaStream;
            canvas.add(webcam);
            webcam.moveTo(0);
            webcam.getElement().play();
          })
          .catch(function getWebcamAllowed(e) {});
        fabric.util.requestAnimFrame(function render() {
          canvas.renderAll();
          fabric.util.requestAnimFrame(render);
        });
      </script>
    </body>
    
    </html>
  • 相关阅读:
    1.Hello World
    1.Hello World
    1.Hello World
    32.IDEA新建MAVEN项目时速度缓慢
    31.最特殊的快捷键 Alt + Enter 介绍(新用户必看)
    HelloWorld
    mybatis要指定参数再数据库中的类型,类型要全大写
    递归函数,修改全局变量,高阶函数
    不定长参数
    函数返回值return,列表字典的拆包
  • 原文地址:https://www.cnblogs.com/em2464/p/16081682.html
Copyright © 2020-2023  润新知