54 lines
2.6 KiB
HTML
54 lines
2.6 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>Web Serial KNN Classifier</title>
|
|
<!-- TensorFlow.js 核心库 -->
|
|
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
|
|
<!-- MobileNet 模型 -->
|
|
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@latest"></script>
|
|
<!-- KNN 分类器 -->
|
|
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/knn-classifier@latest"></script>
|
|
<style>
|
|
body { font-family: sans-serif; margin: 20px; text-align: center; background-color: #f0f0f0; }
|
|
h1 { color: #333; }
|
|
.container { max-width: 800px; margin: 20px auto; padding: 20px; background-color: white; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
|
|
video { width: 100%; max-width: 640px; border: 1px solid #ccc; background-color: black; margin-top: 15px; border-radius: 4px;}
|
|
button { padding: 10px 20px; font-size: 16px; margin: 5px; cursor: pointer; border: none; border-radius: 4px; transition: background-color 0.3s; }
|
|
button:hover:not(:disabled) { background-color: #007bff; color: white; }
|
|
button:disabled { background-color: #ccc; cursor: not-allowed; }
|
|
.status-message { margin-top: 15px; padding: 10px; border-radius: 4px; }
|
|
.status-info { background-color: #e0f7fa; color: #007bff; }
|
|
.status-success { background-color: #e8f5e9; color: #4caf50; }
|
|
.status-error { background-color: #ffebee; color: #f44336; }
|
|
#prediction { font-size: 1.2em; font-weight: bold; margin-top: 20px; color: #333; }
|
|
#serialStatus { margin-top: 10px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>📦 Web Serial 实时分类器</h1>
|
|
|
|
<div id="serialStatus" class="status-message status-info">正在检查 Web Serial API 兼容性...</div>
|
|
<button id="connectSerialBtn" disabled>连接串口</button>
|
|
<button id="disconnectSerialBtn" disabled>断开串口</button>
|
|
|
|
<hr style="margin: 20px 0;">
|
|
|
|
<div id="modelStatus" class="status-message status-info">正在加载 MobileNet 和 KNN 模型...</div>
|
|
<button id="loadModelBtn">加载模型文件</button>
|
|
|
|
<hr style="margin: 20px 0;">
|
|
|
|
<button id="startWebcamBtn" disabled>启动摄像头</button>
|
|
<button id="stopWebcamBtn" disabled>停止摄像头</button>
|
|
<video id="webcam" autoplay playsinline muted></video>
|
|
|
|
<div id="prediction">等待识别...</div>
|
|
</div>
|
|
|
|
<script src="script.js"></script>
|
|
</body>
|
|
</html>
|