Spaces:
Sleeping
Sleeping
Commit ·
fc4d964
1
Parent(s): 313a596
Fix mirrored canvas text on environment camera
Browse files- templates/recognition.html +22 -10
templates/recognition.html
CHANGED
|
@@ -327,21 +327,33 @@
|
|
| 327 |
label = `Scanning... [${score}]`;
|
| 328 |
}
|
| 329 |
|
| 330 |
-
// Rendering
|
| 331 |
context.strokeStyle = color;
|
| 332 |
context.lineWidth = 3;
|
| 333 |
context.strokeRect(box.x, box.y, box.width, box.height);
|
| 334 |
|
| 335 |
context.save();
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
context.restore();
|
| 346 |
});
|
| 347 |
} catch (err) { console.error(err); }
|
|
|
|
| 327 |
label = `Scanning... [${score}]`;
|
| 328 |
}
|
| 329 |
|
| 330 |
+
// Conditional Text Rendering based on Camera Mode
|
| 331 |
context.strokeStyle = color;
|
| 332 |
context.lineWidth = 3;
|
| 333 |
context.strokeRect(box.x, box.y, box.width, box.height);
|
| 334 |
|
| 335 |
context.save();
|
| 336 |
+
if (currentFacingMode === 'user') {
|
| 337 |
+
// Compensate for CSS mirror
|
| 338 |
+
context.scale(-1, 1);
|
| 339 |
+
const textRectX = -(box.x + box.width);
|
| 340 |
+
context.fillStyle = color;
|
| 341 |
+
context.font = "bold 16px Outfit";
|
| 342 |
+
context.globalAlpha = 0.8;
|
| 343 |
+
context.fillRect(textRectX, box.y - 30, box.width, 30);
|
| 344 |
+
context.globalAlpha = 1.0;
|
| 345 |
+
context.fillStyle = "white";
|
| 346 |
+
context.fillText(label, textRectX + 5, box.y - 10);
|
| 347 |
+
} else {
|
| 348 |
+
// Normal rendering for back camera
|
| 349 |
+
context.fillStyle = color;
|
| 350 |
+
context.font = "bold 16px Outfit";
|
| 351 |
+
context.globalAlpha = 0.8;
|
| 352 |
+
context.fillRect(box.x, box.y - 30, box.width, 30);
|
| 353 |
+
context.globalAlpha = 1.0;
|
| 354 |
+
context.fillStyle = "white";
|
| 355 |
+
context.fillText(label, box.x + 5, box.y - 10);
|
| 356 |
+
}
|
| 357 |
context.restore();
|
| 358 |
});
|
| 359 |
} catch (err) { console.error(err); }
|