Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +4 -8
index.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6 |
<title>Candy Label Scanner</title>
|
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
|
10 |
<style>
|
11 |
#output {
|
12 |
font-size: 20px;
|
@@ -39,7 +39,6 @@
|
|
39 |
const canvas = document.getElementById('canvas');
|
40 |
const output = document.getElementById('output');
|
41 |
const captureButton = document.getElementById('capture');
|
42 |
-
|
43 |
navigator.mediaDevices.getUserMedia({
|
44 |
video: {
|
45 |
facingMode: { exact: "environment" }
|
@@ -51,21 +50,20 @@
|
|
51 |
.catch(err => {
|
52 |
console.error("Error accessing the camera: ", err);
|
53 |
});
|
54 |
-
|
55 |
captureButton.addEventListener('click', () => {
|
56 |
// Draw the video frame to the canvas
|
57 |
canvas.width = video.videoWidth;
|
58 |
canvas.height = video.videoHeight;
|
59 |
const context = canvas.getContext('2d');
|
60 |
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
61 |
-
|
62 |
// Convert canvas to image data
|
63 |
const dataURL = canvas.toDataURL('image/png');
|
64 |
-
|
65 |
// Process the image with Tesseract
|
66 |
Tesseract.recognize(
|
67 |
dataURL,
|
68 |
'kor',
|
|
|
|
|
69 |
{
|
70 |
logger: m => console.log(m)
|
71 |
}
|
@@ -74,7 +72,6 @@
|
|
74 |
analyzeNutrition(text);
|
75 |
});
|
76 |
});
|
77 |
-
|
78 |
function analyzeNutrition(text) {
|
79 |
// Extract nutritional values (assuming sugar content is labeled as '당류' in Korean)
|
80 |
const regex = /당류\s*:\s*(\d+(\.\d+)?)\s*g\s*/; // This regex might need adjustments based on label format
|
@@ -101,5 +98,4 @@
|
|
101 |
}
|
102 |
</script>
|
103 |
</body>
|
104 |
-
</html>
|
105 |
-
|
|
|
6 |
<title>Candy Label Scanner</title>
|
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;
|
|
|
39 |
const canvas = document.getElementById('canvas');
|
40 |
const output = document.getElementById('output');
|
41 |
const captureButton = document.getElementById('capture');
|
|
|
42 |
navigator.mediaDevices.getUserMedia({
|
43 |
video: {
|
44 |
facingMode: { exact: "environment" }
|
|
|
50 |
.catch(err => {
|
51 |
console.error("Error accessing the camera: ", err);
|
52 |
});
|
|
|
53 |
captureButton.addEventListener('click', () => {
|
54 |
// Draw the video frame to the canvas
|
55 |
canvas.width = video.videoWidth;
|
56 |
canvas.height = video.videoHeight;
|
57 |
const context = canvas.getContext('2d');
|
58 |
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
|
59 |
// Convert canvas to image data
|
60 |
const dataURL = canvas.toDataURL('image/png');
|
|
|
61 |
// Process the image with Tesseract
|
62 |
Tesseract.recognize(
|
63 |
dataURL,
|
64 |
'kor',
|
65 |
+
"image-to-text",
|
66 |
+
model="team-lucid/trocr-small-korean",
|
67 |
{
|
68 |
logger: m => console.log(m)
|
69 |
}
|
|
|
72 |
analyzeNutrition(text);
|
73 |
});
|
74 |
});
|
|
|
75 |
function analyzeNutrition(text) {
|
76 |
// Extract nutritional values (assuming sugar content is labeled as '당류' in Korean)
|
77 |
const regex = /당류\s*:\s*(\d+(\.\d+)?)\s*g\s*/; // This regex might need adjustments based on label format
|
|
|
98 |
}
|
99 |
</script>
|
100 |
</body>
|
101 |
+
</html>
|
|