Help us understand the problem. What is going on with this article?

HTML,Webカメラで残像パンチを打ってみた

More than 1 year has passed since last update.

パンチ.gif

やり方

Webカメラをブラウザ上に表示

CanvasにWebカメラの画像を書き出す
書き出す時の透明度を0.5に設定

setInterval で繰り返し

<body>
残像
<canvas id="canvas" width="400" height="300" style="border: solid 1px"></canvas>
元動画
<video id="camera" width="400" height="300" autoplay="1" class="camera" style="border: solid 1px"></video>


<script type="text/javascript">
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || window.navigator.mozGetUserMedia;
window.URL = window.URL || window.webkitURL;

var video = document.getElementById('camera');
var localStream = null;
navigator.getUserMedia({video: true, audio: false}, 
    function(stream) { // for success case
    console.log(stream);
    video.src = window.URL.createObjectURL(stream);
    localStream = stream;
    },
    function(err) { // for error case
    console.log(err);
    }
);

//canvasに描画権利を与える
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var img = document.getElementById('img');

//videoの縦幅横幅を取得
var w = video.offsetWidth;
var h = video.offsetHeight;

//同じサイズをcanvasに指定
canvas.setAttribute("width", w);
canvas.setAttribute("height", h);

var record = function(){
    //canvasにvideoタグ画像をコピー
    ctx.globalAlpha = 0.5;
    ctx.drawImage(video, 0, 0, w, h);
}

setInterval(function(){
    record();
},100);
</script>
 </body>


参考URL
カメラを使ってみよう ーWebRTC入門2016
https://html5experts.jp/mganeko/19728/

minowa_keita
インダストリアルデザイナー/3Dモデラー
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした