nonamexd commited on
Commit
c101d28
·
verified ·
1 Parent(s): 76c92ce

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +5 -18
server.js CHANGED
@@ -226,31 +226,18 @@ async function fetchImageBuffer(imageUrl) {
226
  return Buffer.from(await res.arrayBuffer());
227
  }
228
 
229
- // Pre-process image for Tesseract to decrease recognition time
230
- // Resizes large images, grayscales for faster OCR
231
  async function preprocessImageForOCR(buffer) {
232
  try {
233
  const img = await loadImage(buffer);
234
- let width = img.width;
235
- let height = img.height;
236
-
237
- // 450px: screenshot'lardaki metni korurken hızlı kalır
238
- const maxDim = 450;
239
- if (width > maxDim || height > maxDim) {
240
- if (width > height) {
241
- height = Math.round((height * maxDim) / width);
242
- width = maxDim;
243
- } else {
244
- width = Math.round((width * maxDim) / height);
245
- height = maxDim;
246
- }
247
- }
248
 
249
  const canvas = createCanvas(width, height);
250
  const ctx = canvas.getContext('2d');
251
  ctx.drawImage(img, 0, 0, width, height);
252
 
253
- // Sadece grayscale (binarization dark-mode screenshot'larda metni yok ediyor)
254
  const imgData = ctx.getImageData(0, 0, width, height);
255
  const data = imgData.data;
256
  for (let i = 0; i < data.length; i += 4) {
@@ -261,7 +248,7 @@ async function preprocessImageForOCR(buffer) {
261
  }
262
  ctx.putImageData(imgData, 0, 0);
263
 
264
- return canvas.toBuffer('image/jpeg', { quality: 0.65 });
265
  } catch (err) {
266
  console.warn('[Preprocessing] Failed, using raw buffer instead:', err.message);
267
  return buffer;
 
226
  return Buffer.from(await res.arrayBuffer());
227
  }
228
 
229
+ // Pre-process: sadece grayscale, boyut küçültme YOK (metin okunabilirliği için)
 
230
  async function preprocessImageForOCR(buffer) {
231
  try {
232
  const img = await loadImage(buffer);
233
+ const width = img.width;
234
+ const height = img.height;
 
 
 
 
 
 
 
 
 
 
 
 
235
 
236
  const canvas = createCanvas(width, height);
237
  const ctx = canvas.getContext('2d');
238
  ctx.drawImage(img, 0, 0, width, height);
239
 
240
+ // Sadece grayscale dönüşümü
241
  const imgData = ctx.getImageData(0, 0, width, height);
242
  const data = imgData.data;
243
  for (let i = 0; i < data.length; i += 4) {
 
248
  }
249
  ctx.putImageData(imgData, 0, 0);
250
 
251
+ return canvas.toBuffer('image/jpeg', { quality: 0.75 });
252
  } catch (err) {
253
  console.warn('[Preprocessing] Failed, using raw buffer instead:', err.message);
254
  return buffer;