yukiapple323 commited on
Commit
534f4b3
1 Parent(s): 4d2fe33

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +42 -6
index.html CHANGED
@@ -54,18 +54,28 @@
54
  .catch(err => {
55
  console.error("Error accessing the camera: ", err);
56
  });
 
57
  captureButton.addEventListener('click', () => {
58
  // Draw the video frame to the canvas
59
  canvas.width = video.videoWidth;
60
  canvas.height = video.videoHeight;
61
  const context = canvas.getContext('2d');
62
  context.drawImage(video, 0, 0, canvas.width, canvas.height);
63
- // Convert canvas to image data
 
 
 
 
 
 
 
 
64
  const dataURL = canvas.toDataURL('image/png');
65
- // Process the image with Tesseract
 
66
  Tesseract.recognize(
67
  dataURL,
68
- 'kor+eng', // Use both Korean and English
69
  {
70
  logger: m => console.log(m)
71
  }
@@ -76,13 +86,39 @@
76
  console.error("Tesseract error: ", err);
77
  });
78
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  function analyzeNutrition(text) {
80
  // Extract sugar content from the recognized text
81
- // const sugarMatch = text.match(/(\d+(\.\d+)?)(\s*(g|grams|그램))/i);
82
- // const sugarMatch = text.match(/당[^\d]*(\d+(\.\d+)?)\s*(g|grams|그램)/i);
83
  const sugarMatch = text.match(/(당[^\d]*)(\d+(\.\d+)?)(\s*(g|grams|그램))/i);
84
  if (sugarMatch) {
85
- const sugarContent = parseFloat(sugarMatch[1]);
86
  let message = `Sugar content: ${sugarContent}g - `;
87
  if (sugarContent <= 20) {
88
  message += 'Good';
 
54
  .catch(err => {
55
  console.error("Error accessing the camera: ", err);
56
  });
57
+
58
  captureButton.addEventListener('click', () => {
59
  // Draw the video frame to the canvas
60
  canvas.width = video.videoWidth;
61
  canvas.height = video.videoHeight;
62
  const context = canvas.getContext('2d');
63
  context.drawImage(video, 0, 0, canvas.width, canvas.height);
64
+
65
+ // Preprocess the image
66
+ const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
67
+ preprocess(imageData);
68
+
69
+ // Draw the preprocessed image on the canvas
70
+ context.putImageData(imageData, 0, 0);
71
+
72
+ // Convert the canvas to data URL
73
  const dataURL = canvas.toDataURL('image/png');
74
+
75
+ // Recognize text using Tesseract
76
  Tesseract.recognize(
77
  dataURL,
78
+ 'kor+eng', // Recognize both Korean and English
79
  {
80
  logger: m => console.log(m)
81
  }
 
86
  console.error("Tesseract error: ", err);
87
  });
88
  });
89
+
90
+ function preprocess(imageData) {
91
+ // Binarization
92
+ binarization(imageData);
93
+ // Noise reduction
94
+ noiseReduction(imageData);
95
+ // Border enhancement
96
+ borderEnhancement(imageData);
97
+ // Resize
98
+ resize(imageData);
99
+ }
100
+
101
+ function binarization(imageData) {
102
+ // Binarization code
103
+ }
104
+
105
+ function noiseReduction(imageData) {
106
+ // Noise reduction code
107
+ }
108
+
109
+ function borderEnhancement(imageData) {
110
+ // Border enhancement code
111
+ }
112
+
113
+ function resize(imageData) {
114
+ // Resize code
115
+ }
116
+
117
  function analyzeNutrition(text) {
118
  // Extract sugar content from the recognized text
 
 
119
  const sugarMatch = text.match(/(당[^\d]*)(\d+(\.\d+)?)(\s*(g|grams|그램))/i);
120
  if (sugarMatch) {
121
+ const sugarContent = parseFloat(sugarMatch[2]);
122
  let message = `Sugar content: ${sugarContent}g - `;
123
  if (sugarContent <= 20) {
124
  message += 'Good';