srivatsavdamaraju commited on
Commit
898404d
·
verified ·
1 Parent(s): 5c4ac32

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +62 -45
index.html CHANGED
@@ -101,8 +101,10 @@
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 = {
@@ -128,6 +130,15 @@
128
  video.className = 'night-vision';
129
  }
130
 
 
 
 
 
 
 
 
 
 
131
  // Start detection loop
132
  requestAnimationFrame(detect);
133
  }
@@ -144,58 +155,64 @@
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
155
- ctx.strokeStyle = '#00ff00';
156
- ctx.lineWidth = 2;
157
- ctx.strokeRect(
158
- prediction.bbox[0],
159
- prediction.bbox[1],
160
- prediction.bbox[2],
161
- prediction.bbox[3]
162
- );
163
-
164
- // Draw label background
165
- ctx.fillStyle = '#00ff00';
166
- ctx.fillRect(
167
- prediction.bbox[0],
168
- prediction.bbox[1] - 20,
169
- prediction.bbox[2],
170
- 20
171
- );
172
-
173
- // Draw label text
174
- ctx.fillStyle = '#000000';
175
- ctx.font = '16px monospace';
176
- ctx.fillText(
177
- `${prediction.class} ${Math.round(prediction.score * 100)}%`,
178
- prediction.bbox[0] + 5,
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
 
196
  // Start application
197
  init().catch(err => {
198
- console.error('Error initializing camera:', err);
199
  });
200
 
201
  // Add image processing for better night vision
 
101
 
102
  // Initialize camera and AI model
103
  async function init() {
104
+ console.log('Loading COCO-SSD model...');
105
  // Load COCO-SSD model
106
  model = await cocoSsd.load();
107
+ console.log('COCO-SSD model loaded.');
108
 
109
  // Setup camera
110
  const constraints = {
 
130
  video.className = 'night-vision';
131
  }
132
 
133
+ // Check if video is playing
134
+ video.onplaying = () => {
135
+ console.log('Video stream started successfully.');
136
+ };
137
+
138
+ video.onerror = (e) => {
139
+ console.error('Error starting video stream:', e);
140
+ };
141
+
142
  // Start detection loop
143
  requestAnimationFrame(detect);
144
  }
 
155
  }
156
 
157
  // Detect objects
158
+ try {
159
+ const predictions = await model.detect(video);
160
+
161
+ // Clear previous detections
162
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
163
+
164
+ // Draw new detections
165
+ predictions.forEach(prediction => {
166
+ // Draw bounding box
167
+ ctx.strokeStyle = '#00ff00';
168
+ ctx.lineWidth = 2;
169
+ ctx.strokeRect(
170
+ prediction.bbox[0],
171
+ prediction.bbox[1],
172
+ prediction.bbox[2],
173
+ prediction.bbox[3]
174
+ );
175
+
176
+ // Draw label background
177
+ ctx.fillStyle = '#00ff00';
178
+ ctx.fillRect(
179
+ prediction.bbox[0],
180
+ prediction.bbox[1] - 20,
181
+ prediction.bbox[2],
182
+ 20
183
+ );
184
+
185
+ // Draw label text
186
+ ctx.fillStyle = '#000000';
187
+ ctx.font = '16px monospace';
188
+ ctx.fillText(
189
+ `${prediction.class} ${Math.round(prediction.score * 100)}%`,
190
+ prediction.bbox[0] + 5,
191
+ prediction.bbox[1] - 5
192
+ );
193
+ });
194
+
195
+ // Update detection info
196
+ document.getElementById('objects').textContent =
197
+ `Objects detected: ${predictions.length}`;
198
+
199
+ document.getElementById('detections').innerHTML =
200
+ predictions.map(p =>
201
+ `Detected ${p.class} (${Math.round(p.score * 100)}% confidence)`
202
+ ).join('<br>');
203
+
204
+ } catch (error) {
205
+ console.error('Error in detection:', error);
206
+ }
207
  }
208
 
209
+ // Continue calling the detection loop
210
  requestAnimationFrame(detect);
211
  }
212
 
213
  // Start application
214
  init().catch(err => {
215
+ console.error('Error initializing application:', err);
216
  });
217
 
218
  // Add image processing for better night vision