console
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>实时文档扫描 - 矩形检测</title>
<style>
</style>
</head>
<body>
<video id="video" width="320" height="240"></video>
<canvas id="canvas" width="320" height="240"></canvas>
<canvas id="result" width="320" height="240"></canvas>
<script src="https://docs.opencv.org/4.7.0/opencv.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ColonelParrot/jscanify@master/src/jscanify.min.js"></script>
<script>
const scanner = new jscanify();
const canvasCtx = canvas.getContext("2d");
const resultCtx = result.getContext("2d");
navigator.mediaDevices.getUserMedia({
video: {
width: 'max',
height: 'max',
facingMode: 'environment',
}
}).then((stream) => {
video.srcObject = stream;
video.muted = true;
video.onloadedmetadata = () => {
setInterval(() => {
canvasCtx.drawImage(video, 0, 0);
const resultCanvas = scanner.highlightPaper(canvas);
resultCtx.drawImage(resultCanvas, 0, 0);
}, 10);
};
video.play();
});
</script>
</body>
</html>