Spaces:
Running
Running
Update index.html
Browse files- index.html +15 -3
index.html
CHANGED
|
@@ -903,7 +903,12 @@
|
|
| 903 |
wrapper.appendChild(canvas);
|
| 904 |
|
| 905 |
// 3. 設定 Context
|
| 906 |
-
canvasCtx = canvas.getContext('2d');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 907 |
canvasCtx.lineWidth = 10; // [修改] 增加線條寬度以利 OCR 辨識
|
| 908 |
canvasCtx.lineCap = 'round';
|
| 909 |
canvasCtx.lineJoin = 'round';
|
|
@@ -1001,7 +1006,11 @@
|
|
| 1001 |
function clearCanvas() {
|
| 1002 |
const canvas = document.getElementById('handwriting-canvas');
|
| 1003 |
if(!canvas || !canvasCtx) return;
|
| 1004 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
currentStrokes = [];
|
| 1006 |
answerInput.value = '';
|
| 1007 |
candidateBar.innerHTML = '';
|
|
@@ -1019,7 +1028,10 @@
|
|
| 1019 |
function redrawCanvas() {
|
| 1020 |
const canvas = document.getElementById('handwriting-canvas');
|
| 1021 |
if(!canvas || !canvasCtx) return;
|
| 1022 |
-
|
|
|
|
|
|
|
|
|
|
| 1023 |
|
| 1024 |
canvasCtx.beginPath();
|
| 1025 |
currentStrokes.forEach(stroke => {
|
|
|
|
| 903 |
wrapper.appendChild(canvas);
|
| 904 |
|
| 905 |
// 3. 設定 Context
|
| 906 |
+
canvasCtx = canvas.getContext('2d', { willReadFrequently: true }); // [優化] 加入讀取優化提示
|
| 907 |
+
|
| 908 |
+
// [修改] 為了 TrOCR 模型,強制將畫布背景填滿白色像素 (透明背景會導致辨識失敗)
|
| 909 |
+
canvasCtx.fillStyle = '#ffffff';
|
| 910 |
+
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
| 911 |
+
|
| 912 |
canvasCtx.lineWidth = 10; // [修改] 增加線條寬度以利 OCR 辨識
|
| 913 |
canvasCtx.lineCap = 'round';
|
| 914 |
canvasCtx.lineJoin = 'round';
|
|
|
|
| 1006 |
function clearCanvas() {
|
| 1007 |
const canvas = document.getElementById('handwriting-canvas');
|
| 1008 |
if(!canvas || !canvasCtx) return;
|
| 1009 |
+
|
| 1010 |
+
// [修改] 使用 fillRect 填滿白色,取代 clearRect (避免透明背景)
|
| 1011 |
+
canvasCtx.fillStyle = '#ffffff';
|
| 1012 |
+
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
| 1013 |
+
|
| 1014 |
currentStrokes = [];
|
| 1015 |
answerInput.value = '';
|
| 1016 |
candidateBar.innerHTML = '';
|
|
|
|
| 1028 |
function redrawCanvas() {
|
| 1029 |
const canvas = document.getElementById('handwriting-canvas');
|
| 1030 |
if(!canvas || !canvasCtx) return;
|
| 1031 |
+
|
| 1032 |
+
// [修改] 重繪前先填滿白色背景
|
| 1033 |
+
canvasCtx.fillStyle = '#ffffff';
|
| 1034 |
+
canvasCtx.fillRect(0, 0, canvas.width, canvas.height);
|
| 1035 |
|
| 1036 |
canvasCtx.beginPath();
|
| 1037 |
currentStrokes.forEach(stroke => {
|