<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ตัวอย่าง Face Recognition</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 2rem;
color: #333;
}
h1 {
color: #fff;
text-align: center;
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 2rem;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
h2 {
font-size: 1.25rem;
font-weight: 600;
color: #374151;
margin-bottom: 1rem;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
max-width: 1200px;
margin: 0 auto;
}
.panel {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border: none;
padding: 1.5rem;
border-radius: 16px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.panel:hover {
transform: translateY(-2px);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}
#video-container,
#image-container {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
}
video,
#refImage {
border-radius: 12px;
width: 100%;
max-width: 320px;
height: 240px;
object-fit: cover;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
#refImage {
background: #f8fafc;
border: 2px dashed #e2e8f0;
display: none;
/* ซ่อนไว้ก่อนจนกว่าจะมีรูป */
}
#refImage.loaded {
display: block !important;
border: 2px solid #e2e8f0;
}
input[type="file"] {
margin-bottom: 1rem;
padding: 0.5rem;
border: 1px solid #e2e8f0;
border-radius: 8px;
background: #f8fafc;
font-size: 0.9rem;
}
#status {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border: none;
border-radius: 12px;
padding: 1rem 2rem;
margin: 2rem auto;
max-width: 600px;
text-align: center;
font-size: 1.1rem;
font-weight: 500;
color: #374151;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
#result {
font-size: 1.3rem;
font-weight: 600;
text-align: center;
margin-top: 1rem;
padding: 1rem;
border-radius: 8px;
background: #f0f9ff;
color: #0369a1;
}
.result-panel {
grid-column: 1 / -1;
margin-top: 1rem;
}
@media (max-width: 768px) {
.container {
grid-template-columns: 1fr;
gap: 1.5rem;
}
h1 {
font-size: 2rem;
}
body {
padding: 1rem;
}
}
</style>
<!-- 1. โหลดไลบรารี face-api.js -->
<script defer src="https://cdn.jsdelivr.net/npm/face-api.js@0.22.2/dist/face-api.min.js"></script>
<!-- 2. โหลดสคริปต์ของเรา -->
<script defer src="script.js"></script>
</head>
<body>
<h1>🔍 Face Recognition</h1>
<div id="status">กำลังโหลดโมเดล...</div>
<div class="container">
<!-- ส่วนที่ 1: อัปโหลดรูปภาพต้นฉบับ -->
<div class="panel" id="image-container">
<h2>📷 อัปโหลดรูปภาพต้นฉบับ</h2>
<input type="file" id="imageUpload" accept="image/*">
<img id="refImage" src="" alt="รูปภาพต้นฉบับจะแสดงที่นี่">
</div>
<!-- ส่วนที่ 2: กล้อง Webcam -->
<div class="panel" id="video-container">
<h2>📹 ตรวจสอบกับกล้อง</h2>
<video id="video" autoplay muted></video>
</div>
</div>
<!-- ส่วนที่ 3: แสดงผลการตรวจสอบ -->
<div class="panel result-panel">
<h2>📊 ผลการตรวจสอบ</h2>
<div id="result">รอการเปรียบเทียบ...</div>
</div>
</body>
</html>