Skip to content

Commit f1ba112

Browse files
committed
fix bbox to show for image detections
1 parent 24673bc commit f1ba112

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/routes/detections/[id]/+page.svelte

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,31 @@
175175
<div class="space-y-4">
176176
<div class="relative overflow-hidden rounded-xl border-2 border-purple-200 bg-purple-50">
177177
<img
178+
bind:this={imgElement}
179+
on:load={handleImageLoad}
178180
src="/{data.image.imageUrl}"
179181
alt="Detection {data.detection.id}"
180182
class="h-auto w-full object-contain"
181183
/>
182184
<!-- Bounding Box Overlay -->
183-
<svg
184-
class="pointer-events-none absolute left-0 top-0 h-full w-full"
185-
viewBox="0 0 100 100"
186-
preserveAspectRatio="none"
187-
>
188-
<rect
189-
x={data.detection.bbox[0]}
190-
y={data.detection.bbox[1]}
191-
width={data.detection.bbox[2] - data.detection.bbox[0]}
192-
height={data.detection.bbox[3] - data.detection.bbox[1]}
193-
fill="none"
194-
stroke="rgb(74, 222, 128)"
195-
stroke-width="4"
196-
vector-effect="non-scaling-stroke"
197-
/>
198-
</svg>
185+
{#if imageWidth > 0 && imageHeight > 0}
186+
<svg
187+
class="pointer-events-none absolute left-0 top-0 h-full w-full"
188+
viewBox="0 0 {imageWidth} {imageHeight}"
189+
preserveAspectRatio="none"
190+
>
191+
<rect
192+
x={data.detection.bbox[0]}
193+
y={data.detection.bbox[1]}
194+
width={data.detection.bbox[2] - data.detection.bbox[0]}
195+
height={data.detection.bbox[3] - data.detection.bbox[1]}
196+
fill="none"
197+
stroke="rgb(74, 222, 128)"
198+
stroke-width="4"
199+
vector-effect="non-scaling-stroke"
200+
/>
201+
</svg>
202+
{/if}
199203
</div>
200204
<div class="rounded-lg border border-purple-200 bg-purple-50 p-4">
201205
<h3 class="mb-2 font-semibold text-purple-900">Image Information</h3>

0 commit comments

Comments
 (0)