mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 14:31:35 +08:00
refactor(ocr): 移除独立的灰度处理模块并改进预处理流程
将灰度处理功能直接集成到OCR预处理中,不再需要单独的image模块 添加normalise和threshold处理以提升OCR识别效果
This commit is contained in:
parent
362ac6d0b7
commit
7bc49c32e9
@ -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()
|
||||
}
|
||||
@ -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. 读取图像文件
|
||||
|
||||
Loading…
Reference in New Issue
Block a user