Spaces:
Running
Running
Add 3 files
Browse files- README.md +7 -5
- index.html +573 -19
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: objdetect
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,573 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Object Detection App</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.18.0/dist/tf.min.js"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd@2.2.2/dist/coco-ssd.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.video-container {
|
| 12 |
+
position: relative;
|
| 13 |
+
display: inline-block;
|
| 14 |
+
}
|
| 15 |
+
.canvas-overlay {
|
| 16 |
+
position: absolute;
|
| 17 |
+
top: 0;
|
| 18 |
+
left: 0;
|
| 19 |
+
pointer-events: none;
|
| 20 |
+
}
|
| 21 |
+
.detection-box {
|
| 22 |
+
position: absolute;
|
| 23 |
+
border: 2px solid;
|
| 24 |
+
display: flex;
|
| 25 |
+
flex-direction: column;
|
| 26 |
+
align-items: center;
|
| 27 |
+
justify-content: flex-end;
|
| 28 |
+
}
|
| 29 |
+
.detection-label {
|
| 30 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 31 |
+
color: white;
|
| 32 |
+
padding: 2px 5px;
|
| 33 |
+
font-size: 12px;
|
| 34 |
+
border-radius: 4px;
|
| 35 |
+
margin-bottom: 2px;
|
| 36 |
+
}
|
| 37 |
+
.loading-bar {
|
| 38 |
+
width: 100%;
|
| 39 |
+
height: 4px;
|
| 40 |
+
background-color: #e5e7eb;
|
| 41 |
+
border-radius: 2px;
|
| 42 |
+
overflow: hidden;
|
| 43 |
+
}
|
| 44 |
+
.loading-progress {
|
| 45 |
+
height: 100%;
|
| 46 |
+
background-color: #3b82f6;
|
| 47 |
+
transition: width 0.3s ease;
|
| 48 |
+
}
|
| 49 |
+
.toggle-switch {
|
| 50 |
+
position: relative;
|
| 51 |
+
display: inline-block;
|
| 52 |
+
width: 60px;
|
| 53 |
+
height: 34px;
|
| 54 |
+
}
|
| 55 |
+
.toggle-switch input {
|
| 56 |
+
opacity: 0;
|
| 57 |
+
width: 0;
|
| 58 |
+
height: 0;
|
| 59 |
+
}
|
| 60 |
+
.slider {
|
| 61 |
+
position: absolute;
|
| 62 |
+
cursor: pointer;
|
| 63 |
+
top: 0;
|
| 64 |
+
left: 0;
|
| 65 |
+
right: 0;
|
| 66 |
+
bottom: 0;
|
| 67 |
+
background-color: #ccc;
|
| 68 |
+
transition: .4s;
|
| 69 |
+
border-radius: 34px;
|
| 70 |
+
}
|
| 71 |
+
.slider:before {
|
| 72 |
+
position: absolute;
|
| 73 |
+
content: "";
|
| 74 |
+
height: 26px;
|
| 75 |
+
width: 26px;
|
| 76 |
+
left: 4px;
|
| 77 |
+
bottom: 4px;
|
| 78 |
+
background-color: white;
|
| 79 |
+
transition: .4s;
|
| 80 |
+
border-radius: 50%;
|
| 81 |
+
}
|
| 82 |
+
input:checked + .slider {
|
| 83 |
+
background-color: #3b82f6;
|
| 84 |
+
}
|
| 85 |
+
input:checked + .slider:before {
|
| 86 |
+
transform: translateX(26px);
|
| 87 |
+
}
|
| 88 |
+
</style>
|
| 89 |
+
</head>
|
| 90 |
+
<body class="bg-gray-100 min-h-screen">
|
| 91 |
+
<div class="container mx-auto px-4 py-8">
|
| 92 |
+
<div class="max-w-4xl mx-auto bg-white rounded-xl shadow-md overflow-hidden">
|
| 93 |
+
<div class="p-6">
|
| 94 |
+
<h1 class="text-3xl font-bold text-gray-800 mb-2">Object Detection App</h1>
|
| 95 |
+
<p class="text-gray-600 mb-6">Detect and label man-made objects using your camera or a video URL</p>
|
| 96 |
+
|
| 97 |
+
<div class="flex flex-col md:flex-row gap-6 mb-6">
|
| 98 |
+
<div class="flex-1">
|
| 99 |
+
<div class="mb-4">
|
| 100 |
+
<label class="block text-gray-700 font-medium mb-2" for="source-select">Detection Source</label>
|
| 101 |
+
<select id="source-select" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 102 |
+
<option value="camera">Camera</option>
|
| 103 |
+
<option value="video-url">Video URL</option>
|
| 104 |
+
<option value="file-upload">Upload Video</option>
|
| 105 |
+
</select>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div id="camera-controls" class="space-y-4">
|
| 109 |
+
<div class="flex items-center space-x-4">
|
| 110 |
+
<button id="start-camera" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">Start Camera</button>
|
| 111 |
+
<button id="stop-camera" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition" disabled>Stop Camera</button>
|
| 112 |
+
</div>
|
| 113 |
+
<div class="flex items-center space-x-4">
|
| 114 |
+
<span class="text-gray-700">Show labels:</span>
|
| 115 |
+
<label class="toggle-switch">
|
| 116 |
+
<input type="checkbox" id="show-labels" checked>
|
| 117 |
+
<span class="slider"></span>
|
| 118 |
+
</label>
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<div id="video-url-controls" class="hidden space-y-4">
|
| 123 |
+
<div class="mb-4">
|
| 124 |
+
<label class="block text-gray-700 font-medium mb-2" for="video-url">Video URL</label>
|
| 125 |
+
<input type="text" id="video-url" placeholder="https://example.com/video.mp4" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 126 |
+
</div>
|
| 127 |
+
<button id="load-video" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">Load Video</button>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
<div id="file-upload-controls" class="hidden space-y-4">
|
| 131 |
+
<div class="mb-4">
|
| 132 |
+
<label class="block text-gray-700 font-medium mb-2" for="video-upload">Upload Video</label>
|
| 133 |
+
<input type="file" id="video-upload" accept="video/*" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 134 |
+
</div>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<div class="flex-1">
|
| 139 |
+
<div class="bg-gray-200 rounded-lg p-4">
|
| 140 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-2">Detection Settings</h2>
|
| 141 |
+
<div class="space-y-4">
|
| 142 |
+
<div>
|
| 143 |
+
<label class="block text-gray-700 font-medium mb-2">Confidence Threshold</label>
|
| 144 |
+
<input type="range" id="confidence-slider" min="0" max="1" step="0.05" value="0.5" class="w-full">
|
| 145 |
+
<div class="flex justify-between text-sm text-gray-600">
|
| 146 |
+
<span>0%</span>
|
| 147 |
+
<span id="confidence-value">50%</span>
|
| 148 |
+
<span>100%</span>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
<div>
|
| 152 |
+
<label class="block text-gray-700 font-medium mb-2">Detection Speed</label>
|
| 153 |
+
<select id="speed-select" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 154 |
+
<option value="fast">Fast (less accurate)</option>
|
| 155 |
+
<option value="medium" selected>Medium</option>
|
| 156 |
+
<option value="slow">Slow (more accurate)</option>
|
| 157 |
+
</select>
|
| 158 |
+
</div>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<div class="mb-6">
|
| 165 |
+
<div class="loading-bar mb-2 hidden" id="model-loading-bar">
|
| 166 |
+
<div class="loading-progress" id="model-loading-progress" style="width: 0%"></div>
|
| 167 |
+
</div>
|
| 168 |
+
<p class="text-sm text-gray-600" id="status-message">Click "Start Camera" or load a video to begin detection</p>
|
| 169 |
+
</div>
|
| 170 |
+
|
| 171 |
+
<div class="video-container mx-auto">
|
| 172 |
+
<video id="video" autoplay playsinline muted class="w-full max-h-[500px] bg-gray-900 rounded-lg hidden"></video>
|
| 173 |
+
<canvas id="canvas" class="canvas-overlay"></canvas>
|
| 174 |
+
</div>
|
| 175 |
+
|
| 176 |
+
<div class="mt-6 hidden" id="results-container">
|
| 177 |
+
<h2 class="text-xl font-semibold text-gray-800 mb-2">Detection Results</h2>
|
| 178 |
+
<div class="bg-gray-100 rounded-lg p-4">
|
| 179 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4" id="detection-results">
|
| 180 |
+
<!-- Detection results will be added here -->
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<script>
|
| 189 |
+
// DOM elements
|
| 190 |
+
const sourceSelect = document.getElementById('source-select');
|
| 191 |
+
const cameraControls = document.getElementById('camera-controls');
|
| 192 |
+
const videoUrlControls = document.getElementById('video-url-controls');
|
| 193 |
+
const fileUploadControls = document.getElementById('file-upload-controls');
|
| 194 |
+
const startCameraBtn = document.getElementById('start-camera');
|
| 195 |
+
const stopCameraBtn = document.getElementById('stop-camera');
|
| 196 |
+
const loadVideoBtn = document.getElementById('load-video');
|
| 197 |
+
const videoUrlInput = document.getElementById('video-url');
|
| 198 |
+
const videoUploadInput = document.getElementById('video-upload');
|
| 199 |
+
const videoElement = document.getElementById('video');
|
| 200 |
+
const canvasElement = document.getElementById('canvas');
|
| 201 |
+
const confidenceSlider = document.getElementById('confidence-slider');
|
| 202 |
+
const confidenceValue = document.getElementById('confidence-value');
|
| 203 |
+
const speedSelect = document.getElementById('speed-select');
|
| 204 |
+
const showLabelsToggle = document.getElementById('show-labels');
|
| 205 |
+
const statusMessage = document.getElementById('status-message');
|
| 206 |
+
const modelLoadingBar = document.getElementById('model-loading-bar');
|
| 207 |
+
const modelLoadingProgress = document.getElementById('model-loading-progress');
|
| 208 |
+
const resultsContainer = document.getElementById('results-container');
|
| 209 |
+
const detectionResults = document.getElementById('detection-results');
|
| 210 |
+
|
| 211 |
+
// App state
|
| 212 |
+
let model = null;
|
| 213 |
+
let isDetecting = false;
|
| 214 |
+
let detectionInterval = null;
|
| 215 |
+
let stream = null;
|
| 216 |
+
let showLabels = true;
|
| 217 |
+
let confidenceThreshold = 0.5;
|
| 218 |
+
let detectionSpeed = 'medium';
|
| 219 |
+
|
| 220 |
+
// Initialize the app
|
| 221 |
+
init();
|
| 222 |
+
|
| 223 |
+
function init() {
|
| 224 |
+
// Event listeners
|
| 225 |
+
sourceSelect.addEventListener('change', handleSourceChange);
|
| 226 |
+
startCameraBtn.addEventListener('click', startCamera);
|
| 227 |
+
stopCameraBtn.addEventListener('click', stopCamera);
|
| 228 |
+
loadVideoBtn.addEventListener('click', loadVideoFromUrl);
|
| 229 |
+
videoUploadInput.addEventListener('change', handleVideoUpload);
|
| 230 |
+
confidenceSlider.addEventListener('input', updateConfidenceThreshold);
|
| 231 |
+
speedSelect.addEventListener('change', updateDetectionSpeed);
|
| 232 |
+
showLabelsToggle.addEventListener('change', toggleLabels);
|
| 233 |
+
|
| 234 |
+
// Set canvas size to match video when it loads
|
| 235 |
+
videoElement.addEventListener('loadedmetadata', () => {
|
| 236 |
+
canvasElement.width = videoElement.videoWidth;
|
| 237 |
+
canvasElement.height = videoElement.videoHeight;
|
| 238 |
+
});
|
| 239 |
+
|
| 240 |
+
// Load the model
|
| 241 |
+
loadModel();
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
function handleSourceChange() {
|
| 245 |
+
const source = sourceSelect.value;
|
| 246 |
+
|
| 247 |
+
// Hide all controls
|
| 248 |
+
cameraControls.classList.add('hidden');
|
| 249 |
+
videoUrlControls.classList.add('hidden');
|
| 250 |
+
fileUploadControls.classList.add('hidden');
|
| 251 |
+
|
| 252 |
+
// Show the appropriate controls
|
| 253 |
+
if (source === 'camera') {
|
| 254 |
+
cameraControls.classList.remove('hidden');
|
| 255 |
+
} else if (source === 'video-url') {
|
| 256 |
+
videoUrlControls.classList.remove('hidden');
|
| 257 |
+
} else if (source === 'file-upload') {
|
| 258 |
+
fileUploadControls.classList.remove('hidden');
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Stop any ongoing detection
|
| 262 |
+
stopDetection();
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
async function loadModel() {
|
| 266 |
+
try {
|
| 267 |
+
modelLoadingBar.classList.remove('hidden');
|
| 268 |
+
modelLoadingProgress.style.width = '10%';
|
| 269 |
+
statusMessage.textContent = 'Loading object detection model...';
|
| 270 |
+
|
| 271 |
+
// Simulate progress for demo purposes
|
| 272 |
+
const progressInterval = setInterval(() => {
|
| 273 |
+
const currentWidth = parseInt(modelLoadingProgress.style.width);
|
| 274 |
+
if (currentWidth < 90) {
|
| 275 |
+
modelLoadingProgress.style.width = `${currentWidth + 10}%`;
|
| 276 |
+
}
|
| 277 |
+
}, 300);
|
| 278 |
+
|
| 279 |
+
// Load the COCO-SSD model
|
| 280 |
+
model = await cocoSsd.load({
|
| 281 |
+
base: speedSelect.value === 'fast' ? 'mobilenet_v1' :
|
| 282 |
+
speedSelect.value === 'slow' ? 'resnet50' : 'lite_mobilenet_v2'
|
| 283 |
+
});
|
| 284 |
+
|
| 285 |
+
clearInterval(progressInterval);
|
| 286 |
+
modelLoadingProgress.style.width = '100%';
|
| 287 |
+
statusMessage.textContent = 'Model loaded successfully!';
|
| 288 |
+
|
| 289 |
+
setTimeout(() => {
|
| 290 |
+
modelLoadingBar.classList.add('hidden');
|
| 291 |
+
}, 1000);
|
| 292 |
+
} catch (error) {
|
| 293 |
+
console.error('Error loading model:', error);
|
| 294 |
+
statusMessage.textContent = 'Failed to load model. Please refresh the page.';
|
| 295 |
+
modelLoadingBar.classList.add('hidden');
|
| 296 |
+
}
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
async function startCamera() {
|
| 300 |
+
try {
|
| 301 |
+
statusMessage.textContent = 'Accessing camera...';
|
| 302 |
+
stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
| 303 |
+
videoElement.srcObject = stream;
|
| 304 |
+
videoElement.classList.remove('hidden');
|
| 305 |
+
|
| 306 |
+
startCameraBtn.disabled = true;
|
| 307 |
+
stopCameraBtn.disabled = false;
|
| 308 |
+
|
| 309 |
+
statusMessage.textContent = 'Camera started. Detecting objects...';
|
| 310 |
+
|
| 311 |
+
// Start detection
|
| 312 |
+
startDetection();
|
| 313 |
+
} catch (error) {
|
| 314 |
+
console.error('Error accessing camera:', error);
|
| 315 |
+
statusMessage.textContent = 'Could not access camera. Please check permissions.';
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
function stopCamera() {
|
| 320 |
+
if (stream) {
|
| 321 |
+
stream.getTracks().forEach(track => track.stop());
|
| 322 |
+
stream = null;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
videoElement.srcObject = null;
|
| 326 |
+
videoElement.classList.add('hidden');
|
| 327 |
+
|
| 328 |
+
startCameraBtn.disabled = false;
|
| 329 |
+
stopCameraBtn.disabled = true;
|
| 330 |
+
|
| 331 |
+
// Stop detection
|
| 332 |
+
stopDetection();
|
| 333 |
+
|
| 334 |
+
statusMessage.textContent = 'Camera stopped.';
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
function loadVideoFromUrl() {
|
| 338 |
+
const videoUrl = videoUrlInput.value.trim();
|
| 339 |
+
|
| 340 |
+
if (!videoUrl) {
|
| 341 |
+
statusMessage.textContent = 'Please enter a valid video URL.';
|
| 342 |
+
return;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
stopDetection();
|
| 346 |
+
|
| 347 |
+
videoElement.src = videoUrl;
|
| 348 |
+
videoElement.classList.remove('hidden');
|
| 349 |
+
|
| 350 |
+
statusMessage.textContent = 'Loading video...';
|
| 351 |
+
|
| 352 |
+
videoElement.onerror = () => {
|
| 353 |
+
statusMessage.textContent = 'Failed to load video. Please check the URL.';
|
| 354 |
+
};
|
| 355 |
+
|
| 356 |
+
videoElement.onloadeddata = () => {
|
| 357 |
+
statusMessage.textContent = 'Video loaded. Detecting objects...';
|
| 358 |
+
startDetection();
|
| 359 |
+
};
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
function handleVideoUpload(event) {
|
| 363 |
+
const file = event.target.files[0];
|
| 364 |
+
|
| 365 |
+
if (!file) return;
|
| 366 |
+
|
| 367 |
+
stopDetection();
|
| 368 |
+
|
| 369 |
+
const videoURL = URL.createObjectURL(file);
|
| 370 |
+
videoElement.src = videoURL;
|
| 371 |
+
videoElement.classList.remove('hidden');
|
| 372 |
+
|
| 373 |
+
statusMessage.textContent = 'Loading video...';
|
| 374 |
+
|
| 375 |
+
videoElement.onloadeddata = () => {
|
| 376 |
+
statusMessage.textContent = 'Video loaded. Detecting objects...';
|
| 377 |
+
startDetection();
|
| 378 |
+
};
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
function startDetection() {
|
| 382 |
+
if (!model) {
|
| 383 |
+
statusMessage.textContent = 'Model not loaded yet. Please wait...';
|
| 384 |
+
return;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
if (isDetecting) return;
|
| 388 |
+
|
| 389 |
+
isDetecting = true;
|
| 390 |
+
|
| 391 |
+
// Clear previous results
|
| 392 |
+
detectionResults.innerHTML = '';
|
| 393 |
+
resultsContainer.classList.remove('hidden');
|
| 394 |
+
|
| 395 |
+
// Start detecting objects in the video
|
| 396 |
+
detectObjects();
|
| 397 |
+
|
| 398 |
+
// Set up interval for continuous detection
|
| 399 |
+
const interval = detectionSpeed === 'fast' ? 300 :
|
| 400 |
+
detectionSpeed === 'slow' ? 1000 : 500;
|
| 401 |
+
|
| 402 |
+
detectionInterval = setInterval(detectObjects, interval);
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
function stopDetection() {
|
| 406 |
+
if (detectionInterval) {
|
| 407 |
+
clearInterval(detectionInterval);
|
| 408 |
+
detectionInterval = null;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
isDetecting = false;
|
| 412 |
+
|
| 413 |
+
// Clear canvas
|
| 414 |
+
const ctx = canvasElement.getContext('2d');
|
| 415 |
+
ctx.clearRect(0, 0, canvasElement.width, canvasElement.height);
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
async function detectObjects() {
|
| 419 |
+
if (!isDetecting || videoElement.readyState < 2) return;
|
| 420 |
+
|
| 421 |
+
try {
|
| 422 |
+
// Get predictions from the model
|
| 423 |
+
const predictions = await model.detect(videoElement);
|
| 424 |
+
|
| 425 |
+
// Filter predictions based on confidence threshold
|
| 426 |
+
const filteredPredictions = predictions.filter(
|
| 427 |
+
pred => pred.score >= confidenceThreshold
|
| 428 |
+
);
|
| 429 |
+
|
| 430 |
+
// Filter for man-made objects (you can expand this list)
|
| 431 |
+
const manMadeObjects = filteredPredictions.filter(pred => {
|
| 432 |
+
const objectClass = pred.class.toLowerCase();
|
| 433 |
+
return [
|
| 434 |
+
'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train',
|
| 435 |
+
'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign',
|
| 436 |
+
'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep',
|
| 437 |
+
'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella',
|
| 438 |
+
'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard',
|
| 439 |
+
'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard',
|
| 440 |
+
'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork',
|
| 441 |
+
'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange',
|
| 442 |
+
'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair',
|
| 443 |
+
'couch', 'potted plant', 'bed', 'dining table', 'toilet', 'tv',
|
| 444 |
+
'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
|
| 445 |
+
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase',
|
| 446 |
+
'scissors', 'teddy bear', 'hair drier', 'toothbrush'
|
| 447 |
+
].includes(objectClass);
|
| 448 |
+
});
|
| 449 |
+
|
| 450 |
+
// Draw bounding boxes and labels
|
| 451 |
+
drawDetections(manMadeObjects);
|
| 452 |
+
|
| 453 |
+
// Update results display
|
| 454 |
+
updateResultsDisplay(manMadeObjects);
|
| 455 |
+
|
| 456 |
+
} catch (error) {
|
| 457 |
+
console.error('Error detecting objects:', error);
|
| 458 |
+
statusMessage.textContent = 'Error detecting objects.';
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
function drawDetections(predictions) {
|
| 463 |
+
const ctx = canvasElement.getContext('2d');
|
| 464 |
+
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
| 465 |
+
|
| 466 |
+
// Font settings
|
| 467 |
+
const font = "16px sans-serif";
|
| 468 |
+
ctx.font = font;
|
| 469 |
+
ctx.textBaseline = "top";
|
| 470 |
+
|
| 471 |
+
predictions.forEach(prediction => {
|
| 472 |
+
// Draw bounding box
|
| 473 |
+
const [x, y, width, height] = prediction.bbox;
|
| 474 |
+
ctx.strokeStyle = "#00FFFF";
|
| 475 |
+
ctx.lineWidth = 2;
|
| 476 |
+
ctx.strokeRect(x, y, width, height);
|
| 477 |
+
|
| 478 |
+
if (showLabels) {
|
| 479 |
+
// Draw label background
|
| 480 |
+
const text = `${prediction.class} ${(prediction.score * 100).toFixed(1)}%`;
|
| 481 |
+
const textWidth = ctx.measureText(text).width;
|
| 482 |
+
const textHeight = parseInt(font, 10);
|
| 483 |
+
|
| 484 |
+
ctx.fillStyle = "rgba(0, 0, 0, 0.7)";
|
| 485 |
+
ctx.fillRect(x, y, textWidth + 4, textHeight + 4);
|
| 486 |
+
|
| 487 |
+
// Draw text
|
| 488 |
+
ctx.fillStyle = "#FFFFFF";
|
| 489 |
+
ctx.fillText(text, x, y);
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
function updateResultsDisplay(predictions) {
|
| 495 |
+
// Clear previous results
|
| 496 |
+
detectionResults.innerHTML = '';
|
| 497 |
+
|
| 498 |
+
// Group predictions by class and count them
|
| 499 |
+
const objectCounts = {};
|
| 500 |
+
predictions.forEach(pred => {
|
| 501 |
+
if (!objectCounts[pred.class]) {
|
| 502 |
+
objectCounts[pred.class] = 0;
|
| 503 |
+
}
|
| 504 |
+
objectCounts[pred.class]++;
|
| 505 |
+
});
|
| 506 |
+
|
| 507 |
+
// Sort by count (descending)
|
| 508 |
+
const sortedClasses = Object.keys(objectCounts).sort(
|
| 509 |
+
(a, b) => objectCounts[b] - objectCounts[a]
|
| 510 |
+
);
|
| 511 |
+
|
| 512 |
+
// Create cards for each detected object class
|
| 513 |
+
sortedClasses.forEach(className => {
|
| 514 |
+
const count = objectCounts[className];
|
| 515 |
+
|
| 516 |
+
const card = document.createElement('div');
|
| 517 |
+
card.className = 'bg-white rounded-lg shadow p-4 flex items-center';
|
| 518 |
+
|
| 519 |
+
// You could add icons for common objects here
|
| 520 |
+
const icon = document.createElement('div');
|
| 521 |
+
icon.className = 'w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-4';
|
| 522 |
+
icon.innerHTML = `<span class="text-blue-600 font-bold">${count}</span>`;
|
| 523 |
+
|
| 524 |
+
const content = document.createElement('div');
|
| 525 |
+
content.className = 'flex-1';
|
| 526 |
+
|
| 527 |
+
const title = document.createElement('h3');
|
| 528 |
+
title.className = 'font-semibold text-gray-800 capitalize';
|
| 529 |
+
title.textContent = className;
|
| 530 |
+
|
| 531 |
+
const countText = document.createElement('p');
|
| 532 |
+
countText.className = 'text-sm text-gray-600';
|
| 533 |
+
countText.textContent = `${count} detected`;
|
| 534 |
+
|
| 535 |
+
content.appendChild(title);
|
| 536 |
+
content.appendChild(countText);
|
| 537 |
+
|
| 538 |
+
card.appendChild(icon);
|
| 539 |
+
card.appendChild(content);
|
| 540 |
+
|
| 541 |
+
detectionResults.appendChild(card);
|
| 542 |
+
});
|
| 543 |
+
|
| 544 |
+
// Show message if no objects detected
|
| 545 |
+
if (sortedClasses.length === 0) {
|
| 546 |
+
const message = document.createElement('div');
|
| 547 |
+
message.className = 'col-span-3 text-center py-8 text-gray-500';
|
| 548 |
+
message.textContent = 'No man-made objects detected. Try adjusting the confidence threshold.';
|
| 549 |
+
detectionResults.appendChild(message);
|
| 550 |
+
}
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
function updateConfidenceThreshold() {
|
| 554 |
+
confidenceThreshold = parseFloat(confidenceSlider.value);
|
| 555 |
+
confidenceValue.textContent = `${Math.round(confidenceThreshold * 100)}%`;
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
function updateDetectionSpeed() {
|
| 559 |
+
detectionSpeed = speedSelect.value;
|
| 560 |
+
|
| 561 |
+
// If detection is running, restart with new speed
|
| 562 |
+
if (isDetecting) {
|
| 563 |
+
stopDetection();
|
| 564 |
+
startDetection();
|
| 565 |
+
}
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
function toggleLabels() {
|
| 569 |
+
showLabels = showLabelsToggle.checked;
|
| 570 |
+
}
|
| 571 |
+
</script>
|
| 572 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Danyray101/objdetect" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 573 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|