Spaces:
Sleeping
Sleeping
yukiapple323
commited on
Commit
โข
b6697ae
1
Parent(s):
f355a39
Update index.html
Browse files- index.html +6 -23
index.html
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
8 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd"></script>
|
9 |
<script src="https://cdn.jsdelivr.net/npm/tesseract.js"></script>
|
10 |
-
<script src="https://cdn.jsdelivr.net/npm/@tesseract.js/lang-kor"></script>
|
11 |
<style>
|
12 |
#output {
|
13 |
font-size: 20px;
|
@@ -26,11 +25,6 @@
|
|
26 |
width: 100%;
|
27 |
height: auto;
|
28 |
}
|
29 |
-
canvas {
|
30 |
-
display: block;
|
31 |
-
margin-top: 20px;
|
32 |
-
border: 1px solid black;
|
33 |
-
}
|
34 |
</style>
|
35 |
</head>
|
36 |
<body>
|
@@ -65,9 +59,7 @@
|
|
65 |
console.error("Error accessing the camera: ", err);
|
66 |
});
|
67 |
|
68 |
-
captureButton.addEventListener('click',
|
69 |
-
|
70 |
-
function captureAndAnalyze() {
|
71 |
// ์บ๋ฒ์ค์ ๋น๋์ค ํ๋ ์ ๊ทธ๋ฆฌ๊ธฐ
|
72 |
canvas.width = video.videoWidth;
|
73 |
canvas.height = video.videoHeight;
|
@@ -75,28 +67,21 @@
|
|
75 |
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
76 |
// ์บ๋ฒ์ค์์ ์ด๋ฏธ์ง ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
77 |
const dataURL = canvas.toDataURL('image/png');
|
78 |
-
|
79 |
-
|
80 |
-
capturedImage.src = dataURL;
|
81 |
-
// ์ด๋ฏธ์ง๋ฅผ body์ ์ถ๊ฐ
|
82 |
-
document.body.appendChild(capturedImage);
|
83 |
-
// Tesseract๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง ํ
์คํธ ์ธ์
|
84 |
Tesseract.recognize(
|
85 |
dataURL,
|
86 |
-
'
|
87 |
-
{
|
88 |
-
logger: m => console.log(m)
|
89 |
-
}
|
90 |
).then(({ data: { text } }) => {
|
91 |
console.log("Recognized text: ", text);
|
92 |
analyzeNutrition(text);
|
93 |
}).catch(err => {
|
94 |
console.error("Tesseract error: ", err);
|
95 |
});
|
96 |
-
}
|
97 |
|
98 |
function analyzeNutrition(text) {
|
99 |
-
console.log("Original text:", text);
|
100 |
// ์ ๊ท์์ ์ฌ์ฉํ์ฌ ์คํ ํจ๋ ์ถ์ถ
|
101 |
const sugarMatch = text.match(/๋น[^\d]*(\d+(\.\d+)?)\s*(g|grams|๊ทธ๋จ)/i);
|
102 |
if (sugarMatch) {
|
@@ -113,10 +98,8 @@
|
|
113 |
message += 'Dangerous';
|
114 |
output.className = 'red';
|
115 |
}
|
116 |
-
// ๋ฉ์์ง์ ์คํ์ผ์ ์ค์ ํ ํ์ output์ ํ ๋น
|
117 |
output.textContent = message;
|
118 |
} else {
|
119 |
-
// ์คํ ํจ๋์ ์ฐพ์ง ๋ชปํ ๊ฒฝ์ฐ์ ์ฒ๋ฆฌ
|
120 |
output.textContent = 'Sugar content not found';
|
121 |
output.className = '';
|
122 |
}
|
|
|
7 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
|
8 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd"></script>
|
9 |
<script src="https://cdn.jsdelivr.net/npm/tesseract.js"></script>
|
|
|
10 |
<style>
|
11 |
#output {
|
12 |
font-size: 20px;
|
|
|
25 |
width: 100%;
|
26 |
height: auto;
|
27 |
}
|
|
|
|
|
|
|
|
|
|
|
28 |
</style>
|
29 |
</head>
|
30 |
<body>
|
|
|
59 |
console.error("Error accessing the camera: ", err);
|
60 |
});
|
61 |
|
62 |
+
captureButton.addEventListener('click', () => {
|
|
|
|
|
63 |
// ์บ๋ฒ์ค์ ๋น๋์ค ํ๋ ์ ๊ทธ๋ฆฌ๊ธฐ
|
64 |
canvas.width = video.videoWidth;
|
65 |
canvas.height = video.videoHeight;
|
|
|
67 |
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
68 |
// ์บ๋ฒ์ค์์ ์ด๋ฏธ์ง ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
69 |
const dataURL = canvas.toDataURL('image/png');
|
70 |
+
|
71 |
+
// Tesseract๋ก ํ
์คํธ ์ธ์ ์๋
|
|
|
|
|
|
|
|
|
72 |
Tesseract.recognize(
|
73 |
dataURL,
|
74 |
+
'eng', // ์์ด ์ธ์ด๋ง ์ฌ์ฉ
|
75 |
+
{ logger: m => console.log(m) }
|
|
|
|
|
76 |
).then(({ data: { text } }) => {
|
77 |
console.log("Recognized text: ", text);
|
78 |
analyzeNutrition(text);
|
79 |
}).catch(err => {
|
80 |
console.error("Tesseract error: ", err);
|
81 |
});
|
82 |
+
});
|
83 |
|
84 |
function analyzeNutrition(text) {
|
|
|
85 |
// ์ ๊ท์์ ์ฌ์ฉํ์ฌ ์คํ ํจ๋ ์ถ์ถ
|
86 |
const sugarMatch = text.match(/๋น[^\d]*(\d+(\.\d+)?)\s*(g|grams|๊ทธ๋จ)/i);
|
87 |
if (sugarMatch) {
|
|
|
98 |
message += 'Dangerous';
|
99 |
output.className = 'red';
|
100 |
}
|
|
|
101 |
output.textContent = message;
|
102 |
} else {
|
|
|
103 |
output.textContent = 'Sugar content not found';
|
104 |
output.className = '';
|
105 |
}
|