Teeradon commited on
Commit
66fdf16
·
verified ·
1 Parent(s): df325a4

Upload 3 files

Browse files
Files changed (1) hide show
  1. result.html +32 -1
result.html CHANGED
@@ -352,7 +352,38 @@
352
  function renderLightbox() {
353
  const d = resultData;
354
  const isOrig = lightboxMode === 'orig';
355
- document.getElementById('lightbox-img').src = 'data:image/jpeg;base64,' + (isOrig ? d.orig_b64 : d.result_b64);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  document.getElementById('lightbox-title').textContent = isOrig
357
  ? (currentLang==='th'?'ภาพต้นฉบับ':'Original')
358
  : (currentLang==='th'?'ผล detection':'Detection');
 
352
  function renderLightbox() {
353
  const d = resultData;
354
  const isOrig = lightboxMode === 'orig';
355
+ if (isOrig) {
356
+ // ภาพต้นฉบับ — ใช้ base64 ตรงๆ
357
+ document.getElementById('lightbox-img').src = 'data:image/jpeg;base64,' + d.orig_b64;
358
+ } else {
359
+ // ภาพ detection — snapshot จาก canvas + ภาพต้นฉบับรวมกัน
360
+ const img = document.getElementById('result-img');
361
+ const canvas = document.getElementById('det-canvas');
362
+ // วาดภาพ + box รวมกันบน offscreen canvas
363
+ const off = document.createElement('canvas');
364
+ off.width = img.naturalWidth || img.width;
365
+ off.height = img.naturalHeight || img.height;
366
+ const ctx = off.getContext('2d');
367
+ ctx.drawImage(img, 0, 0, off.width, off.height);
368
+ // วาด box ทับด้วย scale ที่ถูกต้อง
369
+ const scaleX = off.width / (canvas.width || 1);
370
+ const scaleY = off.height / (canvas.height || 1);
371
+ const filtered = allBoxes.filter(b => b.conf >= currentThreshold);
372
+ filtered.forEach(b => {
373
+ const x = b.x1 * off.width, y = b.y1 * off.height;
374
+ const w = (b.x2 - b.x1) * off.width, h = (b.y2 - b.y1) * off.height;
375
+ ctx.strokeStyle = '#e84d6f'; ctx.lineWidth = Math.max(2, off.width / 300);
376
+ ctx.strokeRect(x, y, w, h);
377
+ const label = (b.conf * 100).toFixed(0) + '%';
378
+ ctx.font = 'bold ' + Math.max(12, off.width / 80) + 'px monospace';
379
+ const tw = ctx.measureText(label).width;
380
+ ctx.fillStyle = '#e84d6f';
381
+ ctx.fillRect(x, y - Math.max(16, off.width / 60), tw + 8, Math.max(16, off.width / 60));
382
+ ctx.fillStyle = '#fff';
383
+ ctx.fillText(label, x + 4, y - 4);
384
+ });
385
+ document.getElementById('lightbox-img').src = off.toDataURL('image/jpeg', 0.92);
386
+ }
387
  document.getElementById('lightbox-title').textContent = isOrig
388
  ? (currentLang==='th'?'ภาพต้นฉบับ':'Original')
389
  : (currentLang==='th'?'ผล detection':'Detection');