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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<style>
|
5 |
+
* {
|
6 |
+
box-sizing: border-box;
|
7 |
+
margin: 0;
|
8 |
+
padding: 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
body {
|
12 |
+
font-family: system-ui;
|
13 |
+
background-color: #f5f5f5;
|
14 |
+
min-height: 100vh;
|
15 |
+
padding: 1rem; /* Reduced padding for a more compact layout */
|
16 |
+
}
|
17 |
+
|
18 |
+
.page-title {
|
19 |
+
text-align: center;
|
20 |
+
padding: 0.5rem 0;
|
21 |
+
color: #333;
|
22 |
+
margin-bottom: 1.5rem; /* Reduced margin for compactness */
|
23 |
+
font-size: 1.8rem;
|
24 |
+
}
|
25 |
+
|
26 |
+
.main-container {
|
27 |
+
max-width: 1200px;
|
28 |
+
margin: 0 auto;
|
29 |
+
}
|
30 |
+
|
31 |
+
/* Top Section: Image and Controls Side by Side */
|
32 |
+
.top-section {
|
33 |
+
display: flex;
|
34 |
+
gap: 20px; /* Slightly increased gap for better separation */
|
35 |
+
margin-bottom: 30px; /* Increased margin to separate from the table */
|
36 |
+
}
|
37 |
+
|
38 |
+
/* Image Section */
|
39 |
+
.image-section {
|
40 |
+
flex: 0 0 640px; /* Fixed width for image container */
|
41 |
+
display: flex;
|
42 |
+
flex-direction: column;
|
43 |
+
align-items: center;
|
44 |
+
background: #fff;
|
45 |
+
padding: 15px;
|
46 |
+
border-radius: 8px;
|
47 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
48 |
+
}
|
49 |
+
|
50 |
+
.image-container {
|
51 |
+
position: relative;
|
52 |
+
width: 100%;
|
53 |
+
}
|
54 |
+
|
55 |
+
#image {
|
56 |
+
display: block;
|
57 |
+
width: 100%;
|
58 |
+
height: auto;
|
59 |
+
border: 1px solid #ddd;
|
60 |
+
border-radius: 8px;
|
61 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
62 |
+
}
|
63 |
+
|
64 |
+
#canvas {
|
65 |
+
position: absolute;
|
66 |
+
top: 0;
|
67 |
+
left: 0;
|
68 |
+
cursor: crosshair;
|
69 |
+
}
|
70 |
+
|
71 |
+
.labels-container {
|
72 |
+
position: absolute;
|
73 |
+
top: 0;
|
74 |
+
left: 0;
|
75 |
+
pointer-events: none;
|
76 |
+
width: 100%;
|
77 |
+
height: 100%;
|
78 |
+
}
|
79 |
+
|
80 |
+
/* Controls Section */
|
81 |
+
.controls-section {
|
82 |
+
flex: 1;
|
83 |
+
background: #fff;
|
84 |
+
padding: 15px;
|
85 |
+
border-radius: 8px;
|
86 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
87 |
+
display: flex;
|
88 |
+
flex-direction: column;
|
89 |
+
}
|
90 |
+
|
91 |
+
.coordinates {
|
92 |
+
display: flex;
|
93 |
+
flex-direction: column;
|
94 |
+
flex-grow: 1;
|
95 |
+
}
|
96 |
+
|
97 |
+
.format-controls {
|
98 |
+
margin-bottom: 20px;
|
99 |
+
}
|
100 |
+
|
101 |
+
.format-controls h2 {
|
102 |
+
margin-bottom: 10px;
|
103 |
+
color: #333;
|
104 |
+
font-size: 1.2rem;
|
105 |
+
}
|
106 |
+
|
107 |
+
.radio-group {
|
108 |
+
margin-bottom: 15px; /* Reduced margin */
|
109 |
+
padding: 10px; /* Reduced padding */
|
110 |
+
background: #f9f9f9;
|
111 |
+
border-radius: 4px;
|
112 |
+
border: 1px solid #ddd;
|
113 |
+
}
|
114 |
+
|
115 |
+
.radio-option {
|
116 |
+
margin-bottom: 8px; /* Reduced margin */
|
117 |
+
}
|
118 |
+
|
119 |
+
.radio-option label {
|
120 |
+
margin-left: 5px;
|
121 |
+
color: #555;
|
122 |
+
}
|
123 |
+
|
124 |
+
.format-controls h2:last-of-type {
|
125 |
+
margin-top: 20px;
|
126 |
+
}
|
127 |
+
|
128 |
+
.format {
|
129 |
+
margin-bottom: 15px; /* Reduced margin */
|
130 |
+
}
|
131 |
+
|
132 |
+
.format-title {
|
133 |
+
font-weight: bold;
|
134 |
+
margin-bottom: 5px; /* Reduced margin */
|
135 |
+
color: #333;
|
136 |
+
}
|
137 |
+
|
138 |
+
.coords {
|
139 |
+
font-family: monospace;
|
140 |
+
background: #f9f9f9;
|
141 |
+
padding: 8px; /* Reduced padding */
|
142 |
+
border-radius: 4px;
|
143 |
+
border: 1px solid #ddd;
|
144 |
+
min-height: 20px; /* Reduced min-height */
|
145 |
+
}
|
146 |
+
|
147 |
+
.clear-button-container {
|
148 |
+
display: flex;
|
149 |
+
justify-content: center;
|
150 |
+
padding-top: 10px; /* Reduced padding */
|
151 |
+
}
|
152 |
+
|
153 |
+
.clear-button {
|
154 |
+
background-color: #f44336;
|
155 |
+
color: white;
|
156 |
+
border: none;
|
157 |
+
padding: 8px 16px; /* Reduced padding */
|
158 |
+
border-radius: 4px;
|
159 |
+
cursor: pointer;
|
160 |
+
font-size: 14px;
|
161 |
+
transition: background-color 0.2s;
|
162 |
+
}
|
163 |
+
|
164 |
+
.clear-button:hover {
|
165 |
+
background-color: #d32f2f;
|
166 |
+
}
|
167 |
+
|
168 |
+
.label {
|
169 |
+
position: absolute;
|
170 |
+
background: rgba(0, 0, 0, 0.7);
|
171 |
+
color: #fff;
|
172 |
+
padding: 3px 5px; /* Reduced padding */
|
173 |
+
border-radius: 3px;
|
174 |
+
font-size: 11px; /* Reduced font size */
|
175 |
+
pointer-events: none;
|
176 |
+
white-space: nowrap;
|
177 |
+
}
|
178 |
+
|
179 |
+
/* Bottom Section: Model Explanation Table */
|
180 |
+
.bottom-section {
|
181 |
+
background: #fff;
|
182 |
+
padding: 15px;
|
183 |
+
border-radius: 8px;
|
184 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
185 |
+
overflow-x: auto;
|
186 |
+
}
|
187 |
+
|
188 |
+
.model-explanation table {
|
189 |
+
width: 100%;
|
190 |
+
border-collapse: collapse;
|
191 |
+
background: white;
|
192 |
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
193 |
+
border-radius: 8px;
|
194 |
+
overflow: hidden;
|
195 |
+
font-size: 0.9rem; /* Slightly smaller font for compactness */
|
196 |
+
}
|
197 |
+
|
198 |
+
.model-explanation th,
|
199 |
+
.model-explanation td {
|
200 |
+
border: 1px solid #ddd;
|
201 |
+
padding: 8px; /* Further reduced padding */
|
202 |
+
text-align: left;
|
203 |
+
}
|
204 |
+
|
205 |
+
.model-explanation th {
|
206 |
+
background-color: #f2f2f2;
|
207 |
+
position: sticky;
|
208 |
+
top: 0;
|
209 |
+
z-index: 1;
|
210 |
+
}
|
211 |
+
|
212 |
+
/* Responsive Design */
|
213 |
+
@media (max-width: 1200px) {
|
214 |
+
.top-section {
|
215 |
+
flex-direction: column;
|
216 |
+
}
|
217 |
+
|
218 |
+
.image-section,
|
219 |
+
.controls-section,
|
220 |
+
.bottom-section {
|
221 |
+
width: 100%;
|
222 |
+
max-width: 100%;
|
223 |
+
margin: 0 auto;
|
224 |
+
}
|
225 |
+
|
226 |
+
.image-section {
|
227 |
+
flex: none;
|
228 |
+
}
|
229 |
+
|
230 |
+
.controls-section {
|
231 |
+
flex: none;
|
232 |
+
}
|
233 |
+
}
|
234 |
+
|
235 |
+
/* Ensure the entire layout fits within typical laptop screen heights */
|
236 |
+
@media (max-height: 900px) {
|
237 |
+
body {
|
238 |
+
overflow: auto;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
</style>
|
242 |
+
</head>
|
243 |
+
<body>
|
244 |
+
<h1 class="page-title">Bounding Box Coordinate Tool</h1>
|
245 |
+
|
246 |
+
<div class="main-container">
|
247 |
+
<!-- Top Section: Image and Controls -->
|
248 |
+
<div class="top-section">
|
249 |
+
<!-- Image Section -->
|
250 |
+
<div class="image-section">
|
251 |
+
<div class="image-container">
|
252 |
+
<img id="image" src="demo-image.jpg" alt="Image created by Flux Pro with prompt 'an image of a living room with plenty of different furniture objects'" width="640">
|
253 |
+
<canvas id="canvas"></canvas>
|
254 |
+
<div id="labels-container" class="labels-container"></div>
|
255 |
+
</div>
|
256 |
+
</div>
|
257 |
+
|
258 |
+
<!-- Controls Section -->
|
259 |
+
<div class="controls-section">
|
260 |
+
<div class="coordinates">
|
261 |
+
<div class="format-controls">
|
262 |
+
<h2>Display Format</h2>
|
263 |
+
<div class="radio-group">
|
264 |
+
<div class="radio-option">
|
265 |
+
<input type="radio" id="xyxy-radio" name="format" value="xyxy" checked>
|
266 |
+
<label for="xyxy-radio">XYXY (x1, y1, x2, y2)</label>
|
267 |
+
</div>
|
268 |
+
<div class="radio-option">
|
269 |
+
<input type="radio" id="xywh-radio" name="format" value="xywh">
|
270 |
+
<label for="xywh-radio">XYWH (x, y, width, height)</label>
|
271 |
+
</div>
|
272 |
+
<div class="radio-option">
|
273 |
+
<input type="radio" id="normalized-radio" name="format" value="normalized">
|
274 |
+
<label for="normalized-radio">Normalized XYWH (0-1)</label>
|
275 |
+
</div>
|
276 |
+
<div class="radio-option">
|
277 |
+
<input type="radio" id="center-radio" name="format" value="center">
|
278 |
+
<label for="center-radio">Center XYWH (cx, cy, w, h)</label>
|
279 |
+
</div>
|
280 |
+
</div>
|
281 |
+
|
282 |
+
<h2>Bounding Box Coordinates</h2>
|
283 |
+
<div class="format">
|
284 |
+
<div class="format-title">XYXY (x₁, y₁, x₂, y₂)</div>
|
285 |
+
<div id="xyxy" class="coords">No box drawn</div>
|
286 |
+
</div>
|
287 |
+
|
288 |
+
<div class="format">
|
289 |
+
<div class="format-title">XYWH (x, y, width, height)</div>
|
290 |
+
<div id="xywh" class="coords">No box drawn</div>
|
291 |
+
</div>
|
292 |
+
|
293 |
+
<div class="format">
|
294 |
+
<div class="format-title">Normalized XYWH (0-1)</div>
|
295 |
+
<div id="normalized" class="coords">No box drawn</div>
|
296 |
+
</div>
|
297 |
+
|
298 |
+
<div class="format">
|
299 |
+
<div class="format-title">Center XYWH (cx, cy, w, h)</div>
|
300 |
+
<div id="center" class="coords">No box drawn</div>
|
301 |
+
</div>
|
302 |
+
</div>
|
303 |
+
|
304 |
+
<div class="clear-button-container">
|
305 |
+
<button id="clear-button" class="clear-button">Clear Box</button>
|
306 |
+
</div>
|
307 |
+
</div>
|
308 |
+
</div>
|
309 |
+
</div>
|
310 |
+
|
311 |
+
<!-- Bottom Section: Model Explanation Table -->
|
312 |
+
<div class="bottom-section">
|
313 |
+
<div class="model-explanation">
|
314 |
+
<table>
|
315 |
+
<thead>
|
316 |
+
<tr>
|
317 |
+
<th>Model</th>
|
318 |
+
<th>Summary</th>
|
319 |
+
<th>Bounding Box Format</th>
|
320 |
+
</tr>
|
321 |
+
</thead>
|
322 |
+
<tbody>
|
323 |
+
<tr>
|
324 |
+
<td><strong>YOLO</strong></td>
|
325 |
+
<td>Real-time object detection system. Training format uses normalized coordinates for better generalization across different image sizes.</td>
|
326 |
+
<td><strong>Normalized XYWH</strong> (x, y, w, h) in range [0,1]</td>
|
327 |
+
</tr>
|
328 |
+
<tr>
|
329 |
+
<td><strong>Faster R-CNN</strong></td>
|
330 |
+
<td>Region proposal network based detection. Typically uses absolute coordinates during inference, but may use normalized coordinates during training.</td>
|
331 |
+
<td><strong>XYXY</strong> (x₁, y₁, x₂, y₂) or normalized coordinates</td>
|
332 |
+
</tr>
|
333 |
+
<tr>
|
334 |
+
<td><strong>SSD</strong></td>
|
335 |
+
<td>Single Shot MultiBox Detector uses normalized coordinates for anchor boxes and predictions to handle multiple scales efficiently.</td>
|
336 |
+
<td><strong>Normalized XYWH</strong> (x, y, w, h) in range [0,1]</td>
|
337 |
+
</tr>
|
338 |
+
<tr>
|
339 |
+
<td><strong>RetinaNet</strong></td>
|
340 |
+
<td>Dense object detector with focal loss. Uses normalized coordinates for anchor boxes and predictions.</td>
|
341 |
+
<td><strong>Normalized XYWH</strong> (x, y, w, h) in range [0,1]</td>
|
342 |
+
</tr>
|
343 |
+
<tr>
|
344 |
+
<td><strong>CornerNet</strong></td>
|
345 |
+
<td>Anchor-free detector that predicts keypoint heatmaps. Uses normalized coordinates for better scale invariance.</td>
|
346 |
+
<td><strong>Normalized Corners</strong> (x₁, y₁, x₂, y₂) in range [0,1]</td>
|
347 |
+
</tr>
|
348 |
+
</tbody>
|
349 |
+
</table>
|
350 |
+
</div>
|
351 |
+
</div>
|
352 |
+
</div>
|
353 |
+
|
354 |
+
<script>
|
355 |
+
const image = document.getElementById('image');
|
356 |
+
const canvas = document.getElementById('canvas');
|
357 |
+
const ctx = canvas.getContext('2d');
|
358 |
+
const labelsContainer = document.getElementById('labels-container');
|
359 |
+
|
360 |
+
let isDrawing = false;
|
361 |
+
let startX = 0;
|
362 |
+
let startY = 0;
|
363 |
+
let lastCoords = null;
|
364 |
+
let labelElements = [];
|
365 |
+
|
366 |
+
function initCanvas() {
|
367 |
+
canvas.width = image.width;
|
368 |
+
canvas.height = image.height;
|
369 |
+
canvas.style.width = image.width + 'px';
|
370 |
+
canvas.style.height = image.height + 'px';
|
371 |
+
labelsContainer.style.width = image.width + 'px';
|
372 |
+
labelsContainer.style.height = image.height + 'px';
|
373 |
+
}
|
374 |
+
|
375 |
+
if (image.complete) {
|
376 |
+
initCanvas();
|
377 |
+
} else {
|
378 |
+
image.onload = initCanvas;
|
379 |
+
}
|
380 |
+
|
381 |
+
function clearCanvas() {
|
382 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
383 |
+
clearLabels();
|
384 |
+
}
|
385 |
+
|
386 |
+
function clearLabels() {
|
387 |
+
labelElements.forEach(label => labelsContainer.removeChild(label));
|
388 |
+
labelElements = [];
|
389 |
+
}
|
390 |
+
|
391 |
+
function createLabel(text, x, y, positionClass) {
|
392 |
+
const label = document.createElement('div');
|
393 |
+
label.classList.add('label', positionClass);
|
394 |
+
label.textContent = text;
|
395 |
+
label.style.left = `${x}px`;
|
396 |
+
label.style.top = `${y}px`;
|
397 |
+
|
398 |
+
const labelRect = label.getBoundingClientRect();
|
399 |
+
const containerRect = labelsContainer.getBoundingClientRect();
|
400 |
+
|
401 |
+
label.style.visibility = 'hidden';
|
402 |
+
labelsContainer.appendChild(label);
|
403 |
+
const tempRect = label.getBoundingClientRect();
|
404 |
+
label.style.visibility = 'visible';
|
405 |
+
|
406 |
+
if (x + tempRect.width > containerRect.width) {
|
407 |
+
label.style.left = `${containerRect.width - tempRect.width - 5}px`;
|
408 |
+
}
|
409 |
+
|
410 |
+
if (y + tempRect.height > containerRect.height) {
|
411 |
+
label.style.top = `${containerRect.height - tempRect.height - 5}px`;
|
412 |
+
}
|
413 |
+
|
414 |
+
labelsContainer.appendChild(label);
|
415 |
+
labelElements.push(label);
|
416 |
+
}
|
417 |
+
|
418 |
+
function drawBox(x1, y1, x2, y2) {
|
419 |
+
clearCanvas();
|
420 |
+
ctx.strokeStyle = '#00ff00';
|
421 |
+
ctx.lineWidth = 2;
|
422 |
+
const width = x2 - x1;
|
423 |
+
const height = y2 - y1;
|
424 |
+
ctx.strokeRect(x1, y1, width, height);
|
425 |
+
createLabels(x1, y1, x2, y2);
|
426 |
+
lastCoords = { x1, y1, x2, y2 };
|
427 |
+
}
|
428 |
+
|
429 |
+
function createLabels(x1, y1, x2, y2) {
|
430 |
+
const width = x2 - x1;
|
431 |
+
const height = y2 - y1;
|
432 |
+
const format = document.querySelector('input[name="format"]:checked').value;
|
433 |
+
let labels = [];
|
434 |
+
|
435 |
+
switch(format) {
|
436 |
+
case 'xyxy':
|
437 |
+
labels = [
|
438 |
+
{ text: `(${Math.round(x1)}, ${Math.round(y1)})`, x: x1, y: y1, position: 'top-left' },
|
439 |
+
{ text: `(${Math.round(x2)}, ${Math.round(y2)})`, x: x2, y: y2, position: 'bottom-right' }
|
440 |
+
];
|
441 |
+
break;
|
442 |
+
case 'xywh':
|
443 |
+
labels = [
|
444 |
+
{ text: `x: ${Math.round(x1)}, y: ${Math.round(y1)}`, x: x1, y: y1, position: 'top-left' },
|
445 |
+
{ text: `w: ${Math.round(width)}, h: ${Math.round(height)}`, x: x1, y: y1 - 15, position: 'top-left' }
|
446 |
+
];
|
447 |
+
break;
|
448 |
+
case 'normalized':
|
449 |
+
const normalizedX = (x1 / canvas.width).toFixed(3);
|
450 |
+
const normalizedY = (y1 / canvas.height).toFixed(3);
|
451 |
+
const normalizedW = (width / canvas.width).toFixed(3);
|
452 |
+
const normalizedH = (height / canvas.height).toFixed(3);
|
453 |
+
labels = [
|
454 |
+
{ text: `x: ${normalizedX}, y: ${normalizedY}`, x: x1, y: y1, position: 'top-left' },
|
455 |
+
{ text: `w: ${normalizedW}, h: ${normalizedH}`, x: x1, y: y1 - 15, position: 'top-left' }
|
456 |
+
];
|
457 |
+
break;
|
458 |
+
case 'center':
|
459 |
+
const centerX = Math.round(x1 + width / 2);
|
460 |
+
const centerY = Math.round(y1 + height / 2);
|
461 |
+
labels = [
|
462 |
+
{ text: `cx: ${centerX}, cy: ${centerY}`, x: centerX, y: centerY, position: 'top-left' },
|
463 |
+
{ text: `w: ${Math.round(width)}, h: ${Math.round(height)}`, x: x1, y: y1 - 15, position: 'top-left' }
|
464 |
+
];
|
465 |
+
break;
|
466 |
+
}
|
467 |
+
|
468 |
+
labels.forEach(label => {
|
469 |
+
createLabel(label.text, label.x, label.y, label.position);
|
470 |
+
});
|
471 |
+
}
|
472 |
+
|
473 |
+
function updateCoordinates(x1, y1, x2, y2) {
|
474 |
+
if (x1 === null || y1 === null || x2 === null || y2 === null) {
|
475 |
+
document.getElementById('xyxy').textContent = 'No box drawn';
|
476 |
+
document.getElementById('xywh').textContent = 'No box drawn';
|
477 |
+
document.getElementById('normalized').textContent = 'No box drawn';
|
478 |
+
document.getElementById('center').textContent = 'No box drawn';
|
479 |
+
return;
|
480 |
+
}
|
481 |
+
|
482 |
+
const width = x2 - x1;
|
483 |
+
const height = y2 - y1;
|
484 |
+
|
485 |
+
document.getElementById('xyxy').textContent =
|
486 |
+
`[${Math.round(x1)}, ${Math.round(y1)}, ${Math.round(x2)}, ${Math.round(y2)}]`;
|
487 |
+
|
488 |
+
document.getElementById('xywh').textContent =
|
489 |
+
`[${Math.round(x1)}, ${Math.round(y1)}, ${Math.round(width)}, ${Math.round(height)}]`;
|
490 |
+
|
491 |
+
const normalizedX = (x1 / canvas.width).toFixed(3);
|
492 |
+
const normalizedY = (y1 / canvas.height).toFixed(3);
|
493 |
+
const normalizedW = (width / canvas.width).toFixed(3);
|
494 |
+
const normalizedH = (height / canvas.height).toFixed(3);
|
495 |
+
document.getElementById('normalized').textContent =
|
496 |
+
`[${normalizedX}, ${normalizedY}, ${normalizedW}, ${normalizedH}]`;
|
497 |
+
|
498 |
+
const centerX = x1 + width / 2;
|
499 |
+
const centerY = y1 + height / 2;
|
500 |
+
document.getElementById('center').textContent =
|
501 |
+
`[${Math.round(centerX)}, ${Math.round(centerY)}, ${Math.round(width)}, ${Math.round(height)}]`;
|
502 |
+
}
|
503 |
+
|
504 |
+
document.querySelectorAll('input[name="format"]').forEach(radio => {
|
505 |
+
radio.addEventListener('change', () => {
|
506 |
+
if (lastCoords) {
|
507 |
+
drawBox(lastCoords.x1, lastCoords.y1, lastCoords.x2, lastCoords.y2);
|
508 |
+
updateCoordinates(lastCoords.x1, lastCoords.y1, lastCoords.x2, lastCoords.y2);
|
509 |
+
}
|
510 |
+
});
|
511 |
+
});
|
512 |
+
|
513 |
+
canvas.addEventListener('mousedown', (e) => {
|
514 |
+
isDrawing = true;
|
515 |
+
const rect = canvas.getBoundingClientRect();
|
516 |
+
startX = e.clientX - rect.left;
|
517 |
+
startY = e.clientY - rect.top;
|
518 |
+
clearCanvas();
|
519 |
+
updateCoordinates(null, null, null, null);
|
520 |
+
});
|
521 |
+
|
522 |
+
canvas.addEventListener('mousemove', (e) => {
|
523 |
+
if (!isDrawing) return;
|
524 |
+
|
525 |
+
const rect = canvas.getBoundingClientRect();
|
526 |
+
const currentX = e.clientX - rect.left;
|
527 |
+
const currentY = e.clientY - rect.top;
|
528 |
+
|
529 |
+
drawBox(startX, startY, currentX, currentY);
|
530 |
+
updateCoordinates(startX, startY, currentX, currentY);
|
531 |
+
});
|
532 |
+
|
533 |
+
canvas.addEventListener('mouseup', (e) => {
|
534 |
+
if (!isDrawing) return;
|
535 |
+
|
536 |
+
const rect = canvas.getBoundingClientRect();
|
537 |
+
const endX = e.clientX - rect.left;
|
538 |
+
const endY = e.clientY - rect.top;
|
539 |
+
|
540 |
+
drawBox(startX, startY, endX, endY);
|
541 |
+
updateCoordinates(startX, startY, endX, endY);
|
542 |
+
|
543 |
+
isDrawing = false;
|
544 |
+
});
|
545 |
+
|
546 |
+
canvas.addEventListener('mouseleave', () => {
|
547 |
+
isDrawing = false;
|
548 |
+
});
|
549 |
+
|
550 |
+
// Event listener for the clear button
|
551 |
+
document.getElementById('clear-button').addEventListener('click', () => {
|
552 |
+
clearCanvas();
|
553 |
+
lastCoords = null;
|
554 |
+
updateCoordinates(null, null, null, null);
|
555 |
+
});
|
556 |
+
</script>
|
557 |
+
</body>
|
558 |
</html>
|