Spaces:
Running
Running
Update index.html
Browse files- index.html +250 -11
index.html
CHANGED
|
@@ -1,28 +1,267 @@
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html
|
| 3 |
<head>
|
| 4 |
-
<
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
<style>
|
| 8 |
-
body
|
| 9 |
margin: 0;
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
overflow: hidden;
|
| 14 |
}
|
| 15 |
-
|
|
|
|
| 16 |
width: 100%;
|
| 17 |
height: 100%;
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
position: absolute;
|
| 20 |
top: 0;
|
| 21 |
left: 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
</style>
|
| 24 |
</head>
|
| 25 |
<body>
|
| 26 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
</body>
|
| 28 |
</html>
|
|
|
|
| 1 |
+
|
| 2 |
<!DOCTYPE html>
|
| 3 |
+
<html>
|
| 4 |
<head>
|
| 5 |
+
<title>AI Night Vision Camera</title>
|
| 6 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd"></script>
|
| 8 |
<style>
|
| 9 |
+
body {
|
| 10 |
margin: 0;
|
| 11 |
+
background: #000;
|
| 12 |
+
color: #fff;
|
| 13 |
+
font-family: monospace;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.container {
|
| 17 |
+
max-width: 1200px;
|
| 18 |
+
margin: 0 auto;
|
| 19 |
+
padding: 20px;
|
| 20 |
+
display: flex;
|
| 21 |
+
flex-direction: column;
|
| 22 |
+
align-items: center;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.video-container {
|
| 26 |
+
position: relative;
|
| 27 |
+
width: 640px;
|
| 28 |
+
height: 480px;
|
| 29 |
+
border: 2px solid #0f0;
|
| 30 |
+
border-radius: 8px;
|
| 31 |
overflow: hidden;
|
| 32 |
}
|
| 33 |
+
|
| 34 |
+
#video {
|
| 35 |
width: 100%;
|
| 36 |
height: 100%;
|
| 37 |
+
object-fit: cover;
|
| 38 |
+
transform: scaleX(-1);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
#canvas {
|
| 42 |
position: absolute;
|
| 43 |
top: 0;
|
| 44 |
left: 0;
|
| 45 |
+
transform: scaleX(-1);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.controls {
|
| 49 |
+
margin-top: 20px;
|
| 50 |
+
display: flex;
|
| 51 |
+
gap: 10px;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
button {
|
| 55 |
+
background: #0f0;
|
| 56 |
+
color: #000;
|
| 57 |
+
border: none;
|
| 58 |
+
padding: 10px 20px;
|
| 59 |
+
border-radius: 4px;
|
| 60 |
+
cursor: pointer;
|
| 61 |
+
font-weight: bold;
|
| 62 |
+
transition: all 0.3s;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
button:hover {
|
| 66 |
+
background: #0f0;
|
| 67 |
+
box-shadow: 0 0 10px #0f0;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.detection-info {
|
| 71 |
+
margin-top: 20px;
|
| 72 |
+
padding: 10px;
|
| 73 |
+
background: rgba(0, 255, 0, 0.1);
|
| 74 |
+
border: 1px solid #0f0;
|
| 75 |
+
border-radius: 4px;
|
| 76 |
+
width: 100%;
|
| 77 |
+
max-width: 620px;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.stats {
|
| 81 |
+
display: flex;
|
| 82 |
+
justify-content: space-between;
|
| 83 |
+
margin-top: 10px;
|
| 84 |
+
font-size: 14px;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.night-vision {
|
| 88 |
+
filter: brightness(2) contrast(1.2) hue-rotate(120deg) grayscale(0.5);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.detection-box {
|
| 92 |
+
position: absolute;
|
| 93 |
+
border: 2px solid #0f0;
|
| 94 |
+
background: rgba(0, 255, 0, 0.1);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
.detection-label {
|
| 98 |
+
position: absolute;
|
| 99 |
+
top: -25px;
|
| 100 |
+
left: 0;
|
| 101 |
+
background: #0f0;
|
| 102 |
+
color: #000;
|
| 103 |
+
padding: 2px 6px;
|
| 104 |
+
font-size: 12px;
|
| 105 |
+
border-radius: 2px;
|
| 106 |
}
|
| 107 |
</style>
|
| 108 |
</head>
|
| 109 |
<body>
|
| 110 |
+
<div class="container">
|
| 111 |
+
<div class="video-container">
|
| 112 |
+
<video id="video" autoplay playsinline></video>
|
| 113 |
+
<canvas id="canvas"></canvas>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<div class="controls">
|
| 117 |
+
<button onclick="toggleNightVision()">Toggle Night Vision</button>
|
| 118 |
+
<button onclick="toggleDetection()">Toggle Detection</button>
|
| 119 |
+
</div>
|
| 120 |
+
|
| 121 |
+
<div class="detection-info">
|
| 122 |
+
<div id="detections"></div>
|
| 123 |
+
<div class="stats">
|
| 124 |
+
<span id="fps">FPS: 0</span>
|
| 125 |
+
<span id="objects">Objects detected: 0</span>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
<script>
|
| 131 |
+
let video = document.getElementById('video');
|
| 132 |
+
let canvas = document.getElementById('canvas');
|
| 133 |
+
let ctx = canvas.getContext('2d');
|
| 134 |
+
let model;
|
| 135 |
+
let isNightVision = false;
|
| 136 |
+
let isDetecting = false;
|
| 137 |
+
let lastTime = performance.now();
|
| 138 |
+
let frameCount = 0;
|
| 139 |
+
|
| 140 |
+
// Initialize camera and AI model
|
| 141 |
+
async function init() {
|
| 142 |
+
// Load COCO-SSD model
|
| 143 |
+
model = await cocoSsd.load();
|
| 144 |
+
|
| 145 |
+
// Setup camera
|
| 146 |
+
const constraints = {
|
| 147 |
+
video: {
|
| 148 |
+
width: 640,
|
| 149 |
+
height: 480,
|
| 150 |
+
facingMode: 'environment',
|
| 151 |
+
advanced: [{
|
| 152 |
+
exposureMode: 'manual',
|
| 153 |
+
exposureCompensation: 2
|
| 154 |
+
}]
|
| 155 |
+
}
|
| 156 |
+
};
|
| 157 |
+
|
| 158 |
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
| 159 |
+
video.srcObject = stream;
|
| 160 |
+
|
| 161 |
+
// Set canvas size
|
| 162 |
+
canvas.width = 640;
|
| 163 |
+
canvas.height = 480;
|
| 164 |
+
|
| 165 |
+
// Start detection loop
|
| 166 |
+
requestAnimationFrame(detect);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function toggleNightVision() {
|
| 170 |
+
isNightVision = !isNightVision;
|
| 171 |
+
video.className = isNightVision ? 'night-vision' : '';
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
function toggleDetection() {
|
| 175 |
+
isDetecting = !isDetecting;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
async function detect() {
|
| 179 |
+
if (isDetecting) {
|
| 180 |
+
// Calculate FPS
|
| 181 |
+
const now = performance.now();
|
| 182 |
+
frameCount++;
|
| 183 |
+
if (now - lastTime >= 1000) {
|
| 184 |
+
document.getElementById('fps').textContent = `FPS: ${frameCount}`;
|
| 185 |
+
frameCount = 0;
|
| 186 |
+
lastTime = now;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
// Detect objects
|
| 190 |
+
const predictions = await model.detect(video);
|
| 191 |
+
|
| 192 |
+
// Clear previous detections
|
| 193 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 194 |
+
|
| 195 |
+
// Draw new detections
|
| 196 |
+
predictions.forEach(prediction => {
|
| 197 |
+
// Draw bounding box
|
| 198 |
+
ctx.strokeStyle = '#00ff00';
|
| 199 |
+
ctx.lineWidth = 2;
|
| 200 |
+
ctx.strokeRect(
|
| 201 |
+
prediction.bbox[0],
|
| 202 |
+
prediction.bbox[1],
|
| 203 |
+
prediction.bbox[2],
|
| 204 |
+
prediction.bbox[3]
|
| 205 |
+
);
|
| 206 |
+
|
| 207 |
+
// Draw label background
|
| 208 |
+
ctx.fillStyle = '#00ff00';
|
| 209 |
+
ctx.fillRect(
|
| 210 |
+
prediction.bbox[0],
|
| 211 |
+
prediction.bbox[1] - 20,
|
| 212 |
+
prediction.bbox[2],
|
| 213 |
+
20
|
| 214 |
+
);
|
| 215 |
+
|
| 216 |
+
// Draw label text
|
| 217 |
+
ctx.fillStyle = '#000000';
|
| 218 |
+
ctx.font = '16px monospace';
|
| 219 |
+
ctx.fillText(
|
| 220 |
+
`${prediction.class} ${Math.round(prediction.score * 100)}%`,
|
| 221 |
+
prediction.bbox[0] + 5,
|
| 222 |
+
prediction.bbox[1] - 5
|
| 223 |
+
);
|
| 224 |
+
});
|
| 225 |
+
|
| 226 |
+
// Update detection info
|
| 227 |
+
document.getElementById('objects').textContent =
|
| 228 |
+
`Objects detected: ${predictions.length}`;
|
| 229 |
+
|
| 230 |
+
document.getElementById('detections').innerHTML =
|
| 231 |
+
predictions.map(p =>
|
| 232 |
+
`Detected ${p.class} (${Math.round(p.score * 100)}% confidence)`
|
| 233 |
+
).join('<br>');
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
requestAnimationFrame(detect);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
// Start application
|
| 240 |
+
init().catch(err => {
|
| 241 |
+
console.error('Error initializing camera:', err);
|
| 242 |
+
});
|
| 243 |
+
|
| 244 |
+
// Add image processing for better night vision
|
| 245 |
+
const imageProcessor = new ImageCapture(video.srcObject.getVideoTracks()[0]);
|
| 246 |
+
|
| 247 |
+
async function enhanceNightVision() {
|
| 248 |
+
if (isNightVision) {
|
| 249 |
+
try {
|
| 250 |
+
const photoCapabilities = await imageProcessor.getPhotoCapabilities();
|
| 251 |
+
await imageProcessor.setOptions({
|
| 252 |
+
brightness: photoCapabilities.brightness.max,
|
| 253 |
+
contrast: photoCapabilities.contrast.max,
|
| 254 |
+
saturation: 0,
|
| 255 |
+
sharpness: photoCapabilities.sharpness.max,
|
| 256 |
+
exposureMode: 'manual',
|
| 257 |
+
exposureCompensation: 2,
|
| 258 |
+
whiteBalanceMode: 'manual'
|
| 259 |
+
});
|
| 260 |
+
} catch (err) {
|
| 261 |
+
console.log('Night vision enhancement not supported');
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
</script>
|
| 266 |
</body>
|
| 267 |
</html>
|