Files
fe_service_ebtp_frontend/public/faceLoginIE/index.html

98 lines
4.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery-webcam-master</title>
<!-- <link href="cs.css" rel="stylesheet" type="text/css"> -->
<script src="jquery.js"></script>
<script src="jquery.webcam.min.js"></script>
<!-- <script src="excanvas.js"></script> -->
</head>
<body>
<div id="webcam" style="float: left; clear: both;"></div>
<!-- <input id="snapBtn" type="button" value="人脸识别" style="float: left; clear: both;"/>
<img id="base64image" src='' width="450" height="320" style="float: left; clear: both;"/> -->
<script type="text/javascript">
var pos = 0, ctx = null, saveCB,w = 380,h= 200, image = new Array();
var canvas = document.createElement("canvas");//创建画布指定宽度和高度
canvas.setAttribute('width', 320);
canvas.setAttribute('height', 240);
document.body.appendChild(canvas);
// canvas = window.G_vmlCanvasManager.initElement(canvas);
ctx = canvas.getContext("2d");//设置画布为2d未来可能支持3d
image = ctx.getImageData(0, 0, 320, 240);//截图320*240即整个画布作为有效区(cutx?)
$(document).ready(function() {
$("#webcam").webcam({
width: w,
height: h,
mode: "callback",
swffile: "jscam_canvas_only.swf", // 这里引入swf文件注意路径
onTick: function(remain) {},
onSave: function(data) {
var col = data.split(";");//把data切割为数组
var img = image;
//绘制图像
//参数data 只是每行的数据 例如320*240 大小的照片一张完整的照片下来需要240个data每个data有320个rgb
for(var i = 0; i < 320; i++) {
//转换为十进制
var tmp = parseInt(col[i]);
img.data[pos + 0] = (tmp >> 16) & 0xff;
img.data[pos + 1] = (tmp >> 8) & 0xff;
img.data[pos + 2] = tmp & 0xff;
img.data[pos + 3] = 0xff;
pos+= 4;
}
//当绘制320*240像素的图片时发给后端php
if (pos == 4 * 320 * 240) {
//把图像放到画布上,输出为png格式
ctx.putImageData(img, 0, 0);
window.parent.postMessage({"image": canvas.toDataURL("image/png")}, '*');
image = new Array();
pos = 0;
}
// image.push(data);
// pos += 4 * 320;
//post>= 4 * 320(x轴像素) * 240(y轴像素) 表示读取图像数据完毕
// if (pos >= 4 * 320 * 240) {
// window.parent.postMessage({"image":image.join('|')}, '*');
// image = new Array();
// pos = 0;
// }
},
onCapture: function(data) {
webcam.save();
// Show a flash for example
},
debug: function(type, string) {
console.log('type:' + type + ',string:' + string);
// Write debug information to console.log() or a div
},
onLoad: function() {
// Page load
}
});
// $('#snapBtn').on('click', function() {
// webcam.capture();
// });
function receiveMessageFromParent ( event ) {
if(event.data == 'releaseCamera'){
location.reload();
}else if(event.data = 'capture'){
webcam.capture();
}
//$('#base64image').attr('src', 'data:image/jpg;base64,' + event.data.data);
};
window.addEventListener('message', receiveMessageFromParent, false);
});
</script>
</body>
</html>