mirror of
https://github.com/woodchen-ink/extractstamp.git
synced 2025-07-18 14:02:01 +08:00
63 lines
2.0 KiB
HTML
63 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>选择图片</title>
|
|
<script src="https://docs.opencv.org/4.x/opencv.js" type="text/javascript"></script>
|
|
<script src="extractStamp.js"></script>
|
|
<style>
|
|
#imageContainer {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
margin-top: 20px;
|
|
}
|
|
#imageContainer img {
|
|
max-width: 200px;
|
|
max-height: 200px;
|
|
object-fit: contain;
|
|
border: 1px solid #ddd;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>选择图片</h1>
|
|
<input type="file" id="imageInput" accept="image/*" onchange="selectImage()">
|
|
<div id="imageContainer"></div>
|
|
<script>
|
|
let isReady = false;
|
|
initOpenCV((ready) => {
|
|
isReady = ready;
|
|
console.log('OpenCV.js 已加载', isReady);
|
|
});
|
|
|
|
function selectImage() {
|
|
const file = document.getElementById('imageInput').files[0];
|
|
console.log('file', file);
|
|
if (file && isReady) {
|
|
extractStampWithFile(file, '#ff0000', '#ff0000', true).then(dstImgList => {
|
|
console.log('提取红色印章成功', dstImgList);
|
|
displayImages(dstImgList);
|
|
});
|
|
} else if (!isReady) {
|
|
console.log('OpenCV.js 尚未加载完成,请稍后再试');
|
|
} else {
|
|
console.log('请先选择一个图片文件');
|
|
}
|
|
}
|
|
|
|
function displayImages(imageList) {
|
|
const container = document.getElementById('imageContainer');
|
|
container.innerHTML = ''; // 清空之前的内容
|
|
imageList.forEach((imgSrc, index) => {
|
|
const img = document.createElement('img');
|
|
img.src = imgSrc;
|
|
img.alt = `提取的印章 ${index + 1}`;
|
|
container.appendChild(img);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|