yukiapple323 commited on
Commit
b6697ae
โ€ข
1 Parent(s): f355a39

Update index.html

Browse files
Files changed (1) hide show
  1. 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', captureAndAnalyze);
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
- const capturedImage = new Image();
80
- capturedImage.src = dataURL;
81
- // ์ด๋ฏธ์ง€๋ฅผ body์— ์ถ”๊ฐ€
82
- document.body.appendChild(capturedImage);
83
- // Tesseract๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€ ํ…์ŠคํŠธ ์ธ์‹
84
  Tesseract.recognize(
85
  dataURL,
86
- 'kor', // ํ•œ๊ธ€ ์–ธ์–ด ์„ค์ •
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
  }