extractstamp/index.html
2024-10-25 17:50:56 +08:00

89 lines
2.9 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;
}
#loading {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 20px;
border-radius: 5px;
z-index: 1000;
}
</style>
</head>
<body>
<h1>选择图片</h1>
<input type="file" id="imageInput" accept="image/*" onchange="selectImage()">
<div id="imageContainer"></div>
<div id="loading">处理中,请稍候...</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) {
showLoading();
extractStampWithFile(file, '#ff0000', '#ff0000', true).then(dstImgList => {
console.log('提取红色印章成功', dstImgList);
displayImages(dstImgList);
hideLoading();
}).catch(error => {
console.error('处理图片时出错:', error);
hideLoading();
});
} 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);
});
}
function showLoading() {
document.getElementById('loading').style.display = 'block';
}
function hideLoading() {
document.getElementById('loading').style.display = 'none';
}
</script>
</body>
</html>