最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - passing webcam frames to python opencv from webrtc - Stack Overflow

programmeradmin0浏览0评论

How can I get frames from webcams through webrtc in order to use it with python opencv?

I couldn't find a good example on the internet. Could you give an example?

Thanks

How can I get frames from webcams through webrtc in order to use it with python opencv?

I couldn't find a good example on the internet. Could you give an example?

Thanks

Share Improve this question asked Nov 29, 2015 at 9:47 yusufyusuf 3,7818 gold badges50 silver badges89 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

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>
发布评论

评论列表(0)

  1. 暂无评论