从 webrtc 将网络摄像头帧传递给 python opencv
Posted
技术标签:
【中文标题】从 webrtc 将网络摄像头帧传递给 python opencv【英文标题】:passing webcam frames to python opencv from webrtc 【发布时间】:2016-03-03 01:46:18 【问题描述】:如何通过 webrtc 从网络摄像头获取帧以便与 python opencv 一起使用?
我在互联网上找不到一个很好的例子。可以举个例子吗?
谢谢
【问题讨论】:
【参考方案1】:这是从网络摄像头获取图像的示例
<!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" ></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>
【讨论】:
以上是关于从 webrtc 将网络摄像头帧传递给 python opencv的主要内容,如果未能解决你的问题,请参考以下文章
Android - 在使用WebRTC发送到Wowza Streaming Engine之前旋转视频帧
如何将多个 WebRTC 媒体流(屏幕捕获 + 网络摄像头)混合/组合成一个流?
使用 WebRTC 从网络摄像头捕获媒体流,将流发布到媒体服务器并从那里分发