-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRWebcam.html
121 lines (101 loc) · 4.42 KB
/
QRWebcam.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>web调取摄像头</title>
<script type="text/javascript">
var scene = null;
var camera = null;
var renderer = null;
var mesh = null;
var id = null;
function init() {
renderer = new THREE.WebGLRenderer({//渲染器
canvas: document.getElementById('mainCanvas')//画布
});
renderer.setClearColor(0x000000);//画布颜色
scene = new THREE.Scene();//创建场景
camera = new THREE.OrthographicCamera(-5, 5, 3.75, -3.75, 0.1, 100);//正交投影照相机
camera.position.set(15, 25, 25);//相机位置
camera.lookAt(new THREE.Vector3(0, 2, 0));//lookAt()设置相机所看的位置
scene.add(camera);//把相机添加到场景中
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
}
};
var onError = function ( xhr ) { };
}
</script>
</head>
<body onload="init()">
<div style='position:relative'>
<div style='position:absolute; z-index:2; '>
<video src=""></video>
</div>
<script>
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function(constraints) {
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
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);
});
}
}
window.URL = (window.URL || window.webkitURL || window.mozURL || window.msURL);
var mediaOpts = {
audio: false,
// Prefer camera resolution nearest to 1280x720.
video: { width: 1280, height: 720 },
}
function successFunc(stream) {
var video = document.querySelector('video');
if ("srcObject" in video) {
video.srcObject = stream
} else {
video.src = window.URL && window.URL.createObjectURL(stream) || stream
}
video.play();
}
function errorFunc(err) {
alert(err.name);
}
navigator.getUserMedia(mediaOpts, successFunc, errorFunc);
// setInterval(function () {
// if(!flag){
// return;
// }
// context.drawImage(video, 0, 0, canvas.width = video.videoWidth, canvas.height = video.videoHeight);
// var image = canvas.toDataURL("image/png").replace("data:image/png;base64,", "");
// $.ajax({
// url : 'qRCodeAction_decoderQRCode.action',
// async : false,
// type : 'post',
// data : {
// 'time' : (new Date()).toString(),
// 'img' : image
// },
// success : function(result) {
//
// },
// });
// }, 5000);
// setInterval(function () {
// context.drawImage(video, 0, 0, canvas.width = video.videoWidth, canvas.height = video.videoHeight);
// $.post('/Home/QRcodeDecode', { "img": canvas.toDataURL().substr(22) }, function (data, status) {
// if (status == "success" && data != "no")location.href = "/Home/Result/" + data;
// }, "text");
// }, 500);
</script>
<div style='position:absolute; z-index:3;filter:alpha(Opacity=80);-moz-opacity:0.8;opacity: 0.8;'>
<canvas id="mainCanvas" width="1280px" height="720px" ></canvas>
</div>
</div>
</body>
</html>