简体   繁体   English

从webrtc传递网络摄像头帧到python opencv

[英]passing webcam frames to python opencv from webrtc

How can I get frames from webcams through webrtc in order to use it with python opencv? 如何通过webrtc从网络摄像头获取帧以便与python opencv一起使用?

I couldn't find a good example on the internet. 我在互联网上找不到一个好的例子。 Could you give an example? 你举个例子吗?

Thanks 谢谢

This is a sample for getting an image from webcam 这是从网络摄像头获取图像的示例

<!DOCTYPE html>
    <html>
      <head>
      </head>
      <body onload="init();">
        <h1>Take a snapshot of the current video stream</h1>
       Click on the Start WebCam button.
         <p>
        <button onclick="startWebcam();">Start WebCam</button>
        <button onclick="stopWebcam();">Stop WebCam</button> 
           <button onclick="snapshot();">Take Snapshot</button> 
        </p>
        <video onclick="snapshot(this);" width=400 height=400 id="video" controls autoplay></video>
      <p>

            Screenshots : <p>
          <canvas  id="myCanvas" width="400" height="350"></canvas>  
      </body>
      <script>
          //--------------------
          // GET USER MEDIA CODE
          //--------------------
              navigator.getUserMedia = ( navigator.getUserMedia ||
                                 navigator.webkitGetUserMedia ||
                                 navigator.mozGetUserMedia ||
                                 navigator.msGetUserMedia);

          var video;
          var webcamStream;

          function startWebcam() {
            if (navigator.getUserMedia) {
               navigator.getUserMedia (

                  // constraints
                  {
                     video: true,
                     audio: false
                  },

                  // successCallback
                  function(localMediaStream) {
                      video = document.querySelector('video');
                     video.src = window.URL.createObjectURL(localMediaStream);
                     webcamStream = localMediaStream;
                  },

                  // errorCallback
                  function(err) {
                     console.log("The following error occured: " + err);
                  }
               );
            } else {
               console.log("getUserMedia not supported");
            }  
          }

          function stopWebcam() {
              webcamStream.stop();
          }
          //---------------------
          // TAKE A SNAPSHOT CODE
          //---------------------
          var canvas, ctx;

          function init() {
            // Get the canvas and obtain a context for
            // drawing in it
            canvas = document.getElementById("myCanvas");
            ctx = canvas.getContext('2d');
          }

          function snapshot() {
             // Draws current image from the video element into the canvas
            ctx.drawImage(video, 0,0, canvas.width, canvas.height);
          }

      </script>
    </html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM