-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.html
58 lines (47 loc) · 1.71 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<script src="https://docs.opencv.org/master/opencv.js" type="text/javascript"></script>
<script src="https://docs.opencv.org/master/utils.js" type="text/javascript"></script>
<script type='text/javascript'>
cv['onRuntimeInitialized']=()=>{
// Create a camera object.
var output = document.getElementById('output');
var camera = document.createElement("video");
camera.setAttribute("width", 640);
camera.setAttribute("height", 480);
// Get a permission from user to use a camera.
navigator.mediaDevices.getUserMedia({video: true, audio: false})
.then(function(stream) {
camera.srcObject = stream;
camera.onloadedmetadata = function(e) {
camera.play();
};
});
// Open camera stream and start a capturing loop.
var cap = new cv.VideoCapture(camera);
var frame = new cv.Mat(camera.height, camera.width, cv.CV_8UC4);
var frameBGR = new cv.Mat(camera.height, camera.width, cv.CV_8UC3);
var net;
function captureFrame() {
var begin = Date.now();
cap.read(frame); // Read a frame from camera
// Visualize frame
cv.imshow(output, frame);
setTimeout(captureFrame, 0);
};
// Download models
var utils = new Utils('');
utils.createFileFromUrl("opencv_face_detector.prototxt", "opencv_face_detector.prototxt", () => {
utils.createFileFromUrl("opencv_face_detector.caffemodel", "opencv_face_detector.caffemodel", () => {
net = cv.readNet("opencv_face_detector.prototxt", "opencv_face_detector.caffemodel");
captureFrame();
});
});
};
</script>
</head>
<body>
<canvas id="output" width=640 height=480 style="max-width: 100%"></canvas>
</body>
</html>