Spaces:
Running
Running
undefined - Initial Deployment
Browse files- README.md +7 -5
- index.html +629 -19
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: xydistance
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: pink
|
| 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,629 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Smart Distance Estimation</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 9 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.1/fabric.min.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
.camera-feed {
|
| 12 |
+
position: relative;
|
| 13 |
+
width: 100%;
|
| 14 |
+
height: 0;
|
| 15 |
+
padding-bottom: 75%; /* 4:3 aspect ratio */
|
| 16 |
+
background-color: #f0f0f0;
|
| 17 |
+
border-radius: 0.5rem;
|
| 18 |
+
overflow: hidden;
|
| 19 |
+
}
|
| 20 |
+
#canvas {
|
| 21 |
+
position: absolute;
|
| 22 |
+
top: 0;
|
| 23 |
+
left: 0;
|
| 24 |
+
width: 100%;
|
| 25 |
+
height: 100%;
|
| 26 |
+
}
|
| 27 |
+
.measurement-line {
|
| 28 |
+
stroke: #3b82f6;
|
| 29 |
+
stroke-width: 2;
|
| 30 |
+
stroke-dasharray: 5;
|
| 31 |
+
}
|
| 32 |
+
.dimension-text {
|
| 33 |
+
font-size: 12px;
|
| 34 |
+
fill: #3b82f6;
|
| 35 |
+
font-weight: bold;
|
| 36 |
+
background-color: rgba(255, 255, 255, 0.7);
|
| 37 |
+
padding: 2px 4px;
|
| 38 |
+
border-radius: 3px;
|
| 39 |
+
}
|
| 40 |
+
.object-label {
|
| 41 |
+
font-size: 10px;
|
| 42 |
+
fill: white;
|
| 43 |
+
background-color: rgba(59, 130, 246, 0.9);
|
| 44 |
+
padding: 2px 4px;
|
| 45 |
+
border-radius: 3px;
|
| 46 |
+
}
|
| 47 |
+
.depth-map {
|
| 48 |
+
position: relative;
|
| 49 |
+
width: 100%;
|
| 50 |
+
height: 0;
|
| 51 |
+
padding-bottom: 75%;
|
| 52 |
+
background-color: #1e293b;
|
| 53 |
+
border-radius: 0.5rem;
|
| 54 |
+
overflow: hidden;
|
| 55 |
+
}
|
| 56 |
+
.toggle-container {
|
| 57 |
+
position: relative;
|
| 58 |
+
display: inline-block;
|
| 59 |
+
width: 60px;
|
| 60 |
+
height: 30px;
|
| 61 |
+
}
|
| 62 |
+
.toggle-checkbox {
|
| 63 |
+
opacity: 0;
|
| 64 |
+
width: 0;
|
| 65 |
+
height: 0;
|
| 66 |
+
}
|
| 67 |
+
.toggle-slider {
|
| 68 |
+
position: absolute;
|
| 69 |
+
cursor: pointer;
|
| 70 |
+
top: 0;
|
| 71 |
+
left: 0;
|
| 72 |
+
right: 0;
|
| 73 |
+
bottom: 0;
|
| 74 |
+
background-color: #ccc;
|
| 75 |
+
transition: .4s;
|
| 76 |
+
border-radius: 34px;
|
| 77 |
+
}
|
| 78 |
+
.toggle-slider:before {
|
| 79 |
+
position: absolute;
|
| 80 |
+
content: "";
|
| 81 |
+
height: 22px;
|
| 82 |
+
width: 22px;
|
| 83 |
+
left: 4px;
|
| 84 |
+
bottom: 4px;
|
| 85 |
+
background-color: white;
|
| 86 |
+
transition: .4s;
|
| 87 |
+
border-radius: 50%;
|
| 88 |
+
}
|
| 89 |
+
.toggle-checkbox:checked + .toggle-slider {
|
| 90 |
+
background-color: #3b82f6;
|
| 91 |
+
}
|
| 92 |
+
.toggle-checkbox:checked + .toggle-slider:before {
|
| 93 |
+
transform: translateX(30px);
|
| 94 |
+
}
|
| 95 |
+
</style>
|
| 96 |
+
</head>
|
| 97 |
+
<body class="bg-gray-100 min-h-screen">
|
| 98 |
+
<div class="container mx-auto px-4 py-8">
|
| 99 |
+
<header class="mb-8">
|
| 100 |
+
<h1 class="text-3xl font-bold text-gray-800 mb-2">Smart Distance Estimation</h1>
|
| 101 |
+
<p class="text-gray-600">Measure real-world distances between objects using your smartphone's camera and LiDAR</p>
|
| 102 |
+
</header>
|
| 103 |
+
|
| 104 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
|
| 105 |
+
<!-- Camera Feed Section -->
|
| 106 |
+
<div class="bg-white rounded-lg shadow-md p-4">
|
| 107 |
+
<div class="flex justify-between items-center mb-4">
|
| 108 |
+
<h2 class="text-xl font-semibold text-gray-700">Camera Feed</h2>
|
| 109 |
+
<div class="flex items-center space-x-4">
|
| 110 |
+
<div class="flex items-center">
|
| 111 |
+
<span class="mr-2 text-sm text-gray-600">LiDAR</span>
|
| 112 |
+
<label class="toggle-container">
|
| 113 |
+
<input type="checkbox" id="lidarToggle" class="toggle-checkbox" checked>
|
| 114 |
+
<span class="toggle-slider"></span>
|
| 115 |
+
</label>
|
| 116 |
+
</div>
|
| 117 |
+
<button id="captureBtn" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-md text-sm">
|
| 118 |
+
Capture Image
|
| 119 |
+
</button>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
+
<div class="camera-feed">
|
| 124 |
+
<video id="video" autoplay playsinline class="w-full h-full object-cover" style="display: none;"></video>
|
| 125 |
+
<canvas id="canvas" width="640" height="480"></canvas>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<div class="mt-4 flex justify-center">
|
| 129 |
+
<button id="startCameraBtn" class="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded-md text-sm mr-2">
|
| 130 |
+
Start Camera
|
| 131 |
+
</button>
|
| 132 |
+
<button id="stopCameraBtn" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-md text-sm">
|
| 133 |
+
Stop Camera
|
| 134 |
+
</button>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
<!-- Depth Map Section -->
|
| 139 |
+
<div class="bg-white rounded-lg shadow-md p-4">
|
| 140 |
+
<div class="flex justify-between items-center mb-4">
|
| 141 |
+
<h2 class="text-xl font-semibold text-gray-700">Depth Estimation</h2>
|
| 142 |
+
<div class="flex items-center space-x-4">
|
| 143 |
+
<div class="flex items-center">
|
| 144 |
+
<span class="mr-2 text-sm text-gray-600">Auto-detect</span>
|
| 145 |
+
<label class="toggle-container">
|
| 146 |
+
<input type="checkbox" id="autoDetectToggle" class="toggle-checkbox" checked>
|
| 147 |
+
<span class="toggle-slider"></span>
|
| 148 |
+
</label>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<div class="depth-map">
|
| 154 |
+
<canvas id="depthCanvas" width="640" height="480"></canvas>
|
| 155 |
+
</div>
|
| 156 |
+
|
| 157 |
+
<div class="mt-4">
|
| 158 |
+
<div class="flex justify-between mb-2">
|
| 159 |
+
<span class="text-sm text-gray-600">Near</span>
|
| 160 |
+
<span class="text-sm text-gray-600">Far</span>
|
| 161 |
+
</div>
|
| 162 |
+
<div class="w-full bg-gray-200 rounded-full h-2.5">
|
| 163 |
+
<div class="bg-gradient-to-r from-blue-500 via-purple-500 to-red-500 h-2.5 rounded-full" style="width: 100%"></div>
|
| 164 |
+
</div>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
</div>
|
| 168 |
+
|
| 169 |
+
<!-- Measurement Results -->
|
| 170 |
+
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
|
| 171 |
+
<h2 class="text-xl font-semibold text-gray-700 mb-4">Measurement Results</h2>
|
| 172 |
+
|
| 173 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 174 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 175 |
+
<h3 class="text-sm font-medium text-gray-500 mb-1">Horizontal Distance</h3>
|
| 176 |
+
<p class="text-2xl font-bold text-gray-800">
|
| 177 |
+
<span id="horizontalDistance">0.00</span> <span class="text-sm">meters</span>
|
| 178 |
+
</p>
|
| 179 |
+
</div>
|
| 180 |
+
|
| 181 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 182 |
+
<h3 class="text-sm font-medium text-gray-500 mb-1">Vertical Distance</h3>
|
| 183 |
+
<p class="text-2xl font-bold text-gray-800">
|
| 184 |
+
<span id="verticalDistance">0.00</span> <span class="text-sm">meters</span>
|
| 185 |
+
</p>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
<div class="bg-gray-50 p-4 rounded-lg">
|
| 189 |
+
<h3 class="text-sm font-medium text-gray-500 mb-1">Depth Distance</h3>
|
| 190 |
+
<p class="text-2xl font-bold text-gray-800">
|
| 191 |
+
<span id="depthDistance">0.00</span> <span class="text-sm">meters</span>
|
| 192 |
+
</p>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
|
| 196 |
+
<div class="mt-6">
|
| 197 |
+
<h3 class="text-lg font-medium text-gray-700 mb-2">Detected Objects</h3>
|
| 198 |
+
<div class="overflow-x-auto">
|
| 199 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 200 |
+
<thead class="bg-gray-50">
|
| 201 |
+
<tr>
|
| 202 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Object</th>
|
| 203 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Width (m)</th>
|
| 204 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Height (m)</th>
|
| 205 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Distance (m)</th>
|
| 206 |
+
</tr>
|
| 207 |
+
</thead>
|
| 208 |
+
<tbody id="objectTableBody" class="bg-white divide-y divide-gray-200">
|
| 209 |
+
<!-- Objects will be added here dynamically -->
|
| 210 |
+
</tbody>
|
| 211 |
+
</table>
|
| 212 |
+
</div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
|
| 216 |
+
<!-- Controls Section -->
|
| 217 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 218 |
+
<h2 class="text-xl font-semibold text-gray-700 mb-4">Measurement Controls</h2>
|
| 219 |
+
|
| 220 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
| 221 |
+
<div>
|
| 222 |
+
<h3 class="text-lg font-medium text-gray-700 mb-3">Measurement Mode</h3>
|
| 223 |
+
<div class="space-y-3">
|
| 224 |
+
<div class="flex items-center">
|
| 225 |
+
<input id="singleMeasurement" name="measurementMode" type="radio" checked class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
| 226 |
+
<label for="singleMeasurement" class="ml-2 block text-sm text-gray-700">Single Measurement</label>
|
| 227 |
+
</div>
|
| 228 |
+
<div class="flex items-center">
|
| 229 |
+
<input id="multiMeasurement" name="measurementMode" type="radio" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
| 230 |
+
<label for="multiMeasurement" class="ml-2 block text-sm text-gray-700">Multi Measurement</label>
|
| 231 |
+
</div>
|
| 232 |
+
<div class="flex items-center">
|
| 233 |
+
<input id="autoMeasurement" name="measurementMode" type="radio" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
| 234 |
+
<label for="autoMeasurement" class="ml-2 block text-sm text-gray-700">Auto Detect Objects</label>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
|
| 238 |
+
<div class="mt-6">
|
| 239 |
+
<h3 class="text-lg font-medium text-gray-700 mb-3">Reference Points</h3>
|
| 240 |
+
<div class="flex items-center space-x-4">
|
| 241 |
+
<div class="flex items-center">
|
| 242 |
+
<input id="floorCeiling" name="referencePoints" type="radio" checked class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
| 243 |
+
<label for="floorCeiling" class="ml-2 block text-sm text-gray-700">Floor/Ceiling</label>
|
| 244 |
+
</div>
|
| 245 |
+
<div class="flex items-center">
|
| 246 |
+
<input id="wallEdge" name="referencePoints" type="radio" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300">
|
| 247 |
+
<label for="wallEdge" class="ml-2 block text-sm text-gray-700">Wall Edge</label>
|
| 248 |
+
</div>
|
| 249 |
+
</div>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<div>
|
| 254 |
+
<h3 class="text-lg font-medium text-gray-700 mb-3">Settings</h3>
|
| 255 |
+
<div class="space-y-4">
|
| 256 |
+
<div>
|
| 257 |
+
<label for="unitSelect" class="block text-sm font-medium text-gray-700">Measurement Unit</label>
|
| 258 |
+
<select id="unitSelect" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded-md">
|
| 259 |
+
<option value="meters">Meters</option>
|
| 260 |
+
<option value="feet">Feet</option>
|
| 261 |
+
<option value="inches">Inches</option>
|
| 262 |
+
</select>
|
| 263 |
+
</div>
|
| 264 |
+
|
| 265 |
+
<div>
|
| 266 |
+
<label for="confidenceThreshold" class="block text-sm font-medium text-gray-700">Confidence Threshold</label>
|
| 267 |
+
<input type="range" id="confidenceThreshold" min="0" max="100" value="70" class="mt-1 w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer">
|
| 268 |
+
<div class="flex justify-between text-xs text-gray-500">
|
| 269 |
+
<span>0%</span>
|
| 270 |
+
<span id="confidenceValue">70%</span>
|
| 271 |
+
<span>100%</span>
|
| 272 |
+
</div>
|
| 273 |
+
</div>
|
| 274 |
+
|
| 275 |
+
<div class="flex items-center">
|
| 276 |
+
<input id="showDepthMap" type="checkbox" checked class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
|
| 277 |
+
<label for="showDepthMap" class="ml-2 block text-sm text-gray-700">Show Depth Map</label>
|
| 278 |
+
</div>
|
| 279 |
+
</div>
|
| 280 |
+
</div>
|
| 281 |
+
</div>
|
| 282 |
+
</div>
|
| 283 |
+
</div>
|
| 284 |
+
|
| 285 |
+
<script>
|
| 286 |
+
// DOM Elements
|
| 287 |
+
const video = document.getElementById('video');
|
| 288 |
+
const canvas = document.getElementById('canvas');
|
| 289 |
+
const depthCanvas = document.getElementById('depthCanvas');
|
| 290 |
+
const startCameraBtn = document.getElementById('startCameraBtn');
|
| 291 |
+
const stopCameraBtn = document.getElementById('stopCameraBtn');
|
| 292 |
+
const captureBtn = document.getElementById('captureBtn');
|
| 293 |
+
const horizontalDistanceEl = document.getElementById('horizontalDistance');
|
| 294 |
+
const verticalDistanceEl = document.getElementById('verticalDistance');
|
| 295 |
+
const depthDistanceEl = document.getElementById('depthDistance');
|
| 296 |
+
const objectTableBody = document.getElementById('objectTableBody');
|
| 297 |
+
const confidenceThreshold = document.getElementById('confidenceThreshold');
|
| 298 |
+
const confidenceValue = document.getElementById('confidenceValue');
|
| 299 |
+
const lidarToggle = document.getElementById('lidarToggle');
|
| 300 |
+
const autoDetectToggle = document.getElementById('autoDetectToggle');
|
| 301 |
+
const showDepthMap = document.getElementById('showDepthMap');
|
| 302 |
+
|
| 303 |
+
// Canvas context
|
| 304 |
+
const ctx = canvas.getContext('2d');
|
| 305 |
+
const depthCtx = depthCanvas.getContext('2d');
|
| 306 |
+
|
| 307 |
+
// State variables
|
| 308 |
+
let isCameraOn = false;
|
| 309 |
+
let measurements = [];
|
| 310 |
+
let selectedPoints = [];
|
| 311 |
+
let detectedObjects = [];
|
| 312 |
+
|
| 313 |
+
// Event Listeners
|
| 314 |
+
startCameraBtn.addEventListener('click', startCamera);
|
| 315 |
+
stopCameraBtn.addEventListener('click', stopCamera);
|
| 316 |
+
captureBtn.addEventListener('click', captureImage);
|
| 317 |
+
canvas.addEventListener('click', handleCanvasClick);
|
| 318 |
+
confidenceThreshold.addEventListener('input', updateConfidenceValue);
|
| 319 |
+
showDepthMap.addEventListener('change', toggleDepthMap);
|
| 320 |
+
|
| 321 |
+
// Initialize
|
| 322 |
+
function init() {
|
| 323 |
+
// Set up initial UI state
|
| 324 |
+
stopCameraBtn.disabled = true;
|
| 325 |
+
captureBtn.disabled = true;
|
| 326 |
+
|
| 327 |
+
// Mock data for demonstration
|
| 328 |
+
setTimeout(() => {
|
| 329 |
+
mockDetectObjects();
|
| 330 |
+
}, 1000);
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
// Camera functions
|
| 334 |
+
async function startCamera() {
|
| 335 |
+
try {
|
| 336 |
+
const stream = await navigator.mediaDevices.getUserMedia({
|
| 337 |
+
video: {
|
| 338 |
+
facingMode: 'environment',
|
| 339 |
+
width: { ideal: 1280 },
|
| 340 |
+
height: { ideal: 720 }
|
| 341 |
+
}
|
| 342 |
+
});
|
| 343 |
+
video.srcObject = stream;
|
| 344 |
+
video.style.display = 'block';
|
| 345 |
+
isCameraOn = true;
|
| 346 |
+
startCameraBtn.disabled = true;
|
| 347 |
+
stopCameraBtn.disabled = false;
|
| 348 |
+
captureBtn.disabled = false;
|
| 349 |
+
|
| 350 |
+
// Start processing frames
|
| 351 |
+
processVideo();
|
| 352 |
+
} catch (err) {
|
| 353 |
+
console.error("Error accessing camera:", err);
|
| 354 |
+
alert("Could not access the camera. Please ensure you've granted camera permissions.");
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
function stopCamera() {
|
| 359 |
+
const stream = video.srcObject;
|
| 360 |
+
if (stream) {
|
| 361 |
+
const tracks = stream.getTracks();
|
| 362 |
+
tracks.forEach(track => track.stop());
|
| 363 |
+
video.srcObject = null;
|
| 364 |
+
video.style.display = 'none';
|
| 365 |
+
}
|
| 366 |
+
isCameraOn = false;
|
| 367 |
+
startCameraBtn.disabled = false;
|
| 368 |
+
stopCameraBtn.disabled = true;
|
| 369 |
+
captureBtn.disabled = true;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function processVideo() {
|
| 373 |
+
if (!isCameraOn) return;
|
| 374 |
+
|
| 375 |
+
// Draw video frame to canvas
|
| 376 |
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 377 |
+
|
| 378 |
+
// Simulate object detection (in a real app, this would call your backend)
|
| 379 |
+
if (autoDetectToggle.checked) {
|
| 380 |
+
simulateObjectDetection();
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
// Draw measurements
|
| 384 |
+
drawMeasurements();
|
| 385 |
+
|
| 386 |
+
// Continue processing
|
| 387 |
+
requestAnimationFrame(processVideo);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
function captureImage() {
|
| 391 |
+
// In a real app, this would send the image to your backend for processing
|
| 392 |
+
alert("Image captured! In a real implementation, this would be sent to the backend for processing.");
|
| 393 |
+
|
| 394 |
+
// For demo purposes, simulate detection
|
| 395 |
+
simulateObjectDetection();
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
// Measurement functions
|
| 399 |
+
function handleCanvasClick(event) {
|
| 400 |
+
if (!isCameraOn) return;
|
| 401 |
+
|
| 402 |
+
const rect = canvas.getBoundingClientRect();
|
| 403 |
+
const x = event.clientX - rect.left;
|
| 404 |
+
const y = event.clientY - rect.top;
|
| 405 |
+
|
| 406 |
+
selectedPoints.push({ x, y });
|
| 407 |
+
|
| 408 |
+
if (selectedPoints.length === 2) {
|
| 409 |
+
// Calculate distance between points (in a real app, this would use your backend)
|
| 410 |
+
const distance = calculateDistance(selectedPoints[0], selectedPoints[1]);
|
| 411 |
+
|
| 412 |
+
measurements.push({
|
| 413 |
+
points: [...selectedPoints],
|
| 414 |
+
distance: distance,
|
| 415 |
+
type: 'manual'
|
| 416 |
+
});
|
| 417 |
+
|
| 418 |
+
selectedPoints = [];
|
| 419 |
+
updateMeasurementsUI();
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
drawMeasurements();
|
| 423 |
+
}
|
| 424 |
+
|
| 425 |
+
function calculateDistance(point1, point2) {
|
| 426 |
+
// Simple pixel distance (in a real app, this would convert to real-world units)
|
| 427 |
+
const dx = point2.x - point1.x;
|
| 428 |
+
const dy = point2.y - point1.y;
|
| 429 |
+
return Math.sqrt(dx * dx + dy * dy) / 100; // Simplified conversion
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
function drawMeasurements() {
|
| 433 |
+
// Clear canvas
|
| 434 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 435 |
+
|
| 436 |
+
// Draw video frame
|
| 437 |
+
if (isCameraOn) {
|
| 438 |
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
// Draw selected points
|
| 442 |
+
selectedPoints.forEach(point => {
|
| 443 |
+
ctx.beginPath();
|
| 444 |
+
ctx.arc(point.x, point.y, 5, 0, 2 * Math.PI);
|
| 445 |
+
ctx.fillStyle = '#3b82f6';
|
| 446 |
+
ctx.fill();
|
| 447 |
+
});
|
| 448 |
+
|
| 449 |
+
// Draw measurements
|
| 450 |
+
measurements.forEach(measurement => {
|
| 451 |
+
const [point1, point2] = measurement.points;
|
| 452 |
+
|
| 453 |
+
// Draw line
|
| 454 |
+
ctx.beginPath();
|
| 455 |
+
ctx.moveTo(point1.x, point1.y);
|
| 456 |
+
ctx.lineTo(point2.x, point2.y);
|
| 457 |
+
ctx.strokeStyle = '#3b82f6';
|
| 458 |
+
ctx.lineWidth = 2;
|
| 459 |
+
ctx.setLineDash([5, 5]);
|
| 460 |
+
ctx.stroke();
|
| 461 |
+
ctx.setLineDash([]);
|
| 462 |
+
|
| 463 |
+
// Draw distance text
|
| 464 |
+
const midX = (point1.x + point2.x) / 2;
|
| 465 |
+
const midY = (point1.y + point2.y) / 2;
|
| 466 |
+
|
| 467 |
+
ctx.font = '12px Arial';
|
| 468 |
+
ctx.fillStyle = '#3b82f6';
|
| 469 |
+
ctx.textAlign = 'center';
|
| 470 |
+
ctx.fillText(`${measurement.distance.toFixed(2)} m`, midX, midY - 10);
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
// Draw detected objects
|
| 474 |
+
detectedObjects.forEach(obj => {
|
| 475 |
+
// Draw bounding box
|
| 476 |
+
ctx.strokeStyle = '#10b981';
|
| 477 |
+
ctx.lineWidth = 2;
|
| 478 |
+
ctx.strokeRect(obj.x, obj.y, obj.width, obj.height);
|
| 479 |
+
|
| 480 |
+
// Draw label
|
| 481 |
+
ctx.fillStyle = 'rgba(16, 185, 129, 0.8)';
|
| 482 |
+
ctx.fillRect(obj.x, obj.y - 20, ctx.measureText(`${obj.label} (${obj.confidence}%)`).width + 10, 20);
|
| 483 |
+
ctx.fillStyle = 'white';
|
| 484 |
+
ctx.font = '12px Arial';
|
| 485 |
+
ctx.textAlign = 'left';
|
| 486 |
+
ctx.fillText(`${obj.label} (${obj.confidence}%)`, obj.x + 5, obj.y - 5);
|
| 487 |
+
|
| 488 |
+
// Draw center point
|
| 489 |
+
ctx.beginPath();
|
| 490 |
+
ctx.arc(obj.x + obj.width/2, obj.y + obj.height/2, 3, 0, 2 * Math.PI);
|
| 491 |
+
ctx.fillStyle = '#10b981';
|
| 492 |
+
ctx.fill();
|
| 493 |
+
});
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
function updateMeasurementsUI() {
|
| 497 |
+
if (measurements.length > 0) {
|
| 498 |
+
const lastMeasurement = measurements[measurements.length - 1];
|
| 499 |
+
const dx = Math.abs(lastMeasurement.points[1].x - lastMeasurement.points[0].x);
|
| 500 |
+
const dy = Math.abs(lastMeasurement.points[1].y - lastMeasurement.points[0].y);
|
| 501 |
+
|
| 502 |
+
// Determine if measurement is more horizontal or vertical
|
| 503 |
+
if (dx > dy) {
|
| 504 |
+
horizontalDistanceEl.textContent = lastMeasurement.distance.toFixed(2);
|
| 505 |
+
} else {
|
| 506 |
+
verticalDistanceEl.textContent = lastMeasurement.distance.toFixed(2);
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
// Object detection simulation
|
| 512 |
+
function simulateObjectDetection() {
|
| 513 |
+
// Clear previous detections
|
| 514 |
+
detectedObjects = [];
|
| 515 |
+
|
| 516 |
+
// Generate mock objects
|
| 517 |
+
const mockObjects = [
|
| 518 |
+
{ label: 'Chair', confidence: 85, x: 150, y: 200, width: 80, height: 120 },
|
| 519 |
+
{ label: 'Table', confidence: 92, x: 300, y: 180, width: 150, height: 90 },
|
| 520 |
+
{ label: 'Window', confidence: 78, x: 100, y: 50, width: 200, height: 150 }
|
| 521 |
+
];
|
| 522 |
+
|
| 523 |
+
// Filter by confidence threshold
|
| 524 |
+
const threshold = parseInt(confidenceThreshold.value) / 100;
|
| 525 |
+
detectedObjects = mockObjects.filter(obj => obj.confidence / 100 >= threshold);
|
| 526 |
+
|
| 527 |
+
// Update object table
|
| 528 |
+
updateObjectTable();
|
| 529 |
+
|
| 530 |
+
// Simulate depth map
|
| 531 |
+
simulateDepthMap();
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
+
function mockDetectObjects() {
|
| 535 |
+
// For demo when camera is off
|
| 536 |
+
simulateObjectDetection();
|
| 537 |
+
drawMeasurements();
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
function updateObjectTable() {
|
| 541 |
+
// Clear table
|
| 542 |
+
objectTableBody.innerHTML = '';
|
| 543 |
+
|
| 544 |
+
// Add rows for each detected object
|
| 545 |
+
detectedObjects.forEach(obj => {
|
| 546 |
+
// Calculate approximate real-world dimensions (simplified)
|
| 547 |
+
const width = (obj.width / 100).toFixed(2);
|
| 548 |
+
const height = (obj.height / 100).toFixed(2);
|
| 549 |
+
const distance = (Math.sqrt(obj.x*obj.x + obj.y*obj.y) / 200).toFixed(2);
|
| 550 |
+
|
| 551 |
+
const row = document.createElement('tr');
|
| 552 |
+
row.innerHTML = `
|
| 553 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${obj.label}</td>
|
| 554 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${width}</td>
|
| 555 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${height}</td>
|
| 556 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${distance}</td>
|
| 557 |
+
`;
|
| 558 |
+
objectTableBody.appendChild(row);
|
| 559 |
+
});
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// Depth map simulation
|
| 563 |
+
function simulateDepthMap() {
|
| 564 |
+
// Create gradient for depth effect
|
| 565 |
+
const gradient = depthCtx.createLinearGradient(0, 0, depthCanvas.width, depthCanvas.height);
|
| 566 |
+
gradient.addColorStop(0, '#0000ff'); // Near (blue)
|
| 567 |
+
gradient.addColorStop(0.5, '#ff00ff'); // Medium (purple)
|
| 568 |
+
gradient.addColorStop(1, '#ff0000'); // Far (red)
|
| 569 |
+
|
| 570 |
+
depthCtx.fillStyle = gradient;
|
| 571 |
+
depthCtx.fillRect(0, 0, depthCanvas.width, depthCanvas.height);
|
| 572 |
+
|
| 573 |
+
// Add noise for realism
|
| 574 |
+
const imageData = depthCtx.getImageData(0, 0, depthCanvas.width, depthCanvas.height);
|
| 575 |
+
const data = imageData.data;
|
| 576 |
+
|
| 577 |
+
for (let i = 0; i < data.length; i += 4) {
|
| 578 |
+
// Add some noise
|
| 579 |
+
const noise = Math.random() * 30 - 15;
|
| 580 |
+
data[i] = Math.min(255, Math.max(0, data[i] + noise));
|
| 581 |
+
data[i + 1] = Math.min(255, Math.max(0, data[i + 1] + noise));
|
| 582 |
+
data[i + 2] = Math.min(255, Math.max(0, data[i + 2] + noise));
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
depthCtx.putImageData(imageData, 0, 0);
|
| 586 |
+
|
| 587 |
+
// Add detected objects to depth map
|
| 588 |
+
detectedObjects.forEach(obj => {
|
| 589 |
+
depthCtx.strokeStyle = 'white';
|
| 590 |
+
depthCtx.lineWidth = 2;
|
| 591 |
+
depthCtx.strokeRect(obj.x, obj.y, obj.width, obj.height);
|
| 592 |
+
|
| 593 |
+
// Add depth text
|
| 594 |
+
const depthValue = (Math.sqrt(obj.x*obj.x + obj.y*obj.y) / 200).toFixed(2);
|
| 595 |
+
depthCtx.fillStyle = 'white';
|
| 596 |
+
depthCtx.font = '10px Arial';
|
| 597 |
+
depthCtx.textAlign = 'center';
|
| 598 |
+
depthCtx.fillText(`${depthValue}m`, obj.x + obj.width/2, obj.y + obj.height/2);
|
| 599 |
+
});
|
| 600 |
+
|
| 601 |
+
// Update depth distance display
|
| 602 |
+
if (detectedObjects.length > 0) {
|
| 603 |
+
const avgDepth = detectedObjects.reduce((sum, obj) => {
|
| 604 |
+
return sum + (Math.sqrt(obj.x*obj.x + obj.y*obj.y) / 200);
|
| 605 |
+
}, 0) / detectedObjects.length;
|
| 606 |
+
depthDistanceEl.textContent = avgDepth.toFixed(2);
|
| 607 |
+
}
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
// UI functions
|
| 611 |
+
function updateConfidenceValue() {
|
| 612 |
+
confidenceValue.textContent = `${confidenceThreshold.value}%`;
|
| 613 |
+
|
| 614 |
+
// If auto-detect is on, update detection
|
| 615 |
+
if (autoDetectToggle.checked && (isCameraOn || measurements.length > 0)) {
|
| 616 |
+
simulateObjectDetection();
|
| 617 |
+
drawMeasurements();
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
function toggleDepthMap() {
|
| 622 |
+
depthCanvas.style.display = showDepthMap.checked ? 'block' : 'none';
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
// Initialize the app
|
| 626 |
+
init();
|
| 627 |
+
</script>
|
| 628 |
+
<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=designfailure/xydistance" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 629 |
+
</html>
|