Spaces:
Running
Running
Update index.html
Browse files- index.html +22 -45
index.html
CHANGED
@@ -39,25 +39,6 @@
|
|
39 |
left: 0;
|
40 |
transform: scaleX(-1);
|
41 |
}
|
42 |
-
.controls {
|
43 |
-
margin-top: 20px;
|
44 |
-
display: flex;
|
45 |
-
gap: 10px;
|
46 |
-
}
|
47 |
-
button {
|
48 |
-
background: #0f0;
|
49 |
-
color: #000;
|
50 |
-
border: none;
|
51 |
-
padding: 10px 20px;
|
52 |
-
border-radius: 4px;
|
53 |
-
cursor: pointer;
|
54 |
-
font-weight: bold;
|
55 |
-
transition: all 0.3s;
|
56 |
-
}
|
57 |
-
button:hover {
|
58 |
-
background: #0f0;
|
59 |
-
box-shadow: 0 0 10px #0f0;
|
60 |
-
}
|
61 |
.detection-info {
|
62 |
margin-top: 20px;
|
63 |
padding: 10px;
|
@@ -99,12 +80,6 @@
|
|
99 |
<video id="video" autoplay playsinline></video>
|
100 |
<canvas id="canvas"></canvas>
|
101 |
</div>
|
102 |
-
|
103 |
-
<div class="controls">
|
104 |
-
<button onclick="toggleNightVision()">Toggle Night Vision</button>
|
105 |
-
<button onclick="toggleDetection()">Toggle Detection</button>
|
106 |
-
</div>
|
107 |
-
|
108 |
<div class="detection-info">
|
109 |
<div id="detections"></div>
|
110 |
<div class="stats">
|
@@ -119,14 +94,16 @@
|
|
119 |
let canvas = document.getElementById('canvas');
|
120 |
let ctx = canvas.getContext('2d');
|
121 |
let model;
|
122 |
-
let isNightVision =
|
123 |
-
let isDetecting =
|
124 |
let lastTime = performance.now();
|
125 |
let frameCount = 0;
|
|
|
126 |
// Initialize camera and AI model
|
127 |
async function init() {
|
128 |
// Load COCO-SSD model
|
129 |
model = await cocoSsd.load();
|
|
|
130 |
// Setup camera
|
131 |
const constraints = {
|
132 |
video: {
|
@@ -141,26 +118,20 @@
|
|
141 |
};
|
142 |
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
143 |
video.srcObject = stream;
|
|
|
144 |
// Set canvas size
|
145 |
canvas.width = 640;
|
146 |
canvas.height = 480;
|
147 |
-
|
148 |
-
//
|
149 |
-
|
|
|
|
|
150 |
|
151 |
// Start detection loop
|
152 |
requestAnimationFrame(detect);
|
153 |
}
|
154 |
|
155 |
-
function toggleNightVision() {
|
156 |
-
isNightVision = !isNightVision;
|
157 |
-
video.className = isNightVision ? 'night-vision' : '';
|
158 |
-
}
|
159 |
-
|
160 |
-
function toggleDetection() {
|
161 |
-
isDetecting = !isDetecting;
|
162 |
-
}
|
163 |
-
|
164 |
async function detect() {
|
165 |
if (isDetecting) {
|
166 |
// Calculate FPS
|
@@ -171,11 +142,13 @@
|
|
171 |
frameCount = 0;
|
172 |
lastTime = now;
|
173 |
}
|
|
|
174 |
// Detect objects
|
175 |
const predictions = await model.detect(video);
|
176 |
-
|
177 |
// Clear previous detections
|
178 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
|
179 |
// Draw new detections
|
180 |
predictions.forEach(prediction => {
|
181 |
// Draw bounding box
|
@@ -187,6 +160,7 @@
|
|
187 |
prediction.bbox[2],
|
188 |
prediction.bbox[3]
|
189 |
);
|
|
|
190 |
// Draw label background
|
191 |
ctx.fillStyle = '#00ff00';
|
192 |
ctx.fillRect(
|
@@ -195,6 +169,7 @@
|
|
195 |
prediction.bbox[2],
|
196 |
20
|
197 |
);
|
|
|
198 |
// Draw label text
|
199 |
ctx.fillStyle = '#000000';
|
200 |
ctx.font = '16px monospace';
|
@@ -204,15 +179,17 @@
|
|
204 |
prediction.bbox[1] - 5
|
205 |
);
|
206 |
});
|
|
|
207 |
// Update detection info
|
208 |
-
document.getElementById('objects').textContent =
|
209 |
`Objects detected: ${predictions.length}`;
|
210 |
-
|
211 |
-
document.getElementById('detections').innerHTML =
|
212 |
-
predictions.map(p =>
|
213 |
`Detected ${p.class} (${Math.round(p.score * 100)}% confidence)`
|
214 |
).join('<br>');
|
215 |
}
|
|
|
216 |
requestAnimationFrame(detect);
|
217 |
}
|
218 |
|
@@ -223,7 +200,7 @@
|
|
223 |
|
224 |
// Add image processing for better night vision
|
225 |
const imageProcessor = new ImageCapture(video.srcObject.getVideoTracks()[0]);
|
226 |
-
|
227 |
async function enhanceNightVision() {
|
228 |
if (isNightVision) {
|
229 |
try {
|
|
|
39 |
left: 0;
|
40 |
transform: scaleX(-1);
|
41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
.detection-info {
|
43 |
margin-top: 20px;
|
44 |
padding: 10px;
|
|
|
80 |
<video id="video" autoplay playsinline></video>
|
81 |
<canvas id="canvas"></canvas>
|
82 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
<div class="detection-info">
|
84 |
<div id="detections"></div>
|
85 |
<div class="stats">
|
|
|
94 |
let canvas = document.getElementById('canvas');
|
95 |
let ctx = canvas.getContext('2d');
|
96 |
let model;
|
97 |
+
let isNightVision = true; // Night vision is enabled by default
|
98 |
+
let isDetecting = true; // Detection is enabled by default
|
99 |
let lastTime = performance.now();
|
100 |
let frameCount = 0;
|
101 |
+
|
102 |
// Initialize camera and AI model
|
103 |
async function init() {
|
104 |
// Load COCO-SSD model
|
105 |
model = await cocoSsd.load();
|
106 |
+
|
107 |
// Setup camera
|
108 |
const constraints = {
|
109 |
video: {
|
|
|
118 |
};
|
119 |
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
120 |
video.srcObject = stream;
|
121 |
+
|
122 |
// Set canvas size
|
123 |
canvas.width = 640;
|
124 |
canvas.height = 480;
|
125 |
+
|
126 |
+
// Enable night vision by default
|
127 |
+
if (isNightVision) {
|
128 |
+
video.className = 'night-vision';
|
129 |
+
}
|
130 |
|
131 |
// Start detection loop
|
132 |
requestAnimationFrame(detect);
|
133 |
}
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
async function detect() {
|
136 |
if (isDetecting) {
|
137 |
// Calculate FPS
|
|
|
142 |
frameCount = 0;
|
143 |
lastTime = now;
|
144 |
}
|
145 |
+
|
146 |
// Detect objects
|
147 |
const predictions = await model.detect(video);
|
148 |
+
|
149 |
// Clear previous detections
|
150 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
151 |
+
|
152 |
// Draw new detections
|
153 |
predictions.forEach(prediction => {
|
154 |
// Draw bounding box
|
|
|
160 |
prediction.bbox[2],
|
161 |
prediction.bbox[3]
|
162 |
);
|
163 |
+
|
164 |
// Draw label background
|
165 |
ctx.fillStyle = '#00ff00';
|
166 |
ctx.fillRect(
|
|
|
169 |
prediction.bbox[2],
|
170 |
20
|
171 |
);
|
172 |
+
|
173 |
// Draw label text
|
174 |
ctx.fillStyle = '#000000';
|
175 |
ctx.font = '16px monospace';
|
|
|
179 |
prediction.bbox[1] - 5
|
180 |
);
|
181 |
});
|
182 |
+
|
183 |
// Update detection info
|
184 |
+
document.getElementById('objects').textContent =
|
185 |
`Objects detected: ${predictions.length}`;
|
186 |
+
|
187 |
+
document.getElementById('detections').innerHTML =
|
188 |
+
predictions.map(p =>
|
189 |
`Detected ${p.class} (${Math.round(p.score * 100)}% confidence)`
|
190 |
).join('<br>');
|
191 |
}
|
192 |
+
|
193 |
requestAnimationFrame(detect);
|
194 |
}
|
195 |
|
|
|
200 |
|
201 |
// Add image processing for better night vision
|
202 |
const imageProcessor = new ImageCapture(video.srcObject.getVideoTracks()[0]);
|
203 |
+
|
204 |
async function enhanceNightVision() {
|
205 |
if (isNightVision) {
|
206 |
try {
|