refactor(ocr): 移除独立的灰度处理模块并改进预处理流程

将灰度处理功能直接集成到OCR预处理中,不再需要单独的image模块
添加normalise和threshold处理以提升OCR识别效果
This commit is contained in:
icarus 2025-08-24 20:46:12 +08:00
parent 362ac6d0b7
commit 7bc49c32e9
2 changed files with 5 additions and 14 deletions

View File

@ -1,11 +0,0 @@
import sharp from 'sharp'
/**
*
* @param image Buffer
* @returns Promise<Buffer> Buffer
* @throws {Error}
*/
export const greyScale = (image: Buffer): Promise<Buffer> => {
return sharp(image).greyscale().toBuffer()
}

View File

@ -1,16 +1,18 @@
import { ImageFileMetadata } from '@types'
import { readFile } from 'fs/promises'
import { greyScale } from './image'
import sharp from 'sharp'
const preprocessImage = (buffer: Buffer) => {
return greyScale(buffer)
// threshold 70 is hard-encoded
const result = sharp(buffer).greyscale().normalise().threshold(70).toBuffer()
return result
}
/**
* OCR图像
* @param file -
* @returns Buffer
* @throws {Error}
*
* :
* 1.