松原档案管理软件,选对系统让工作轻松一半
说实话,很多单位搞档案管理,那叫一个头疼。纸质文件堆成山,找个去年的合同得翻半天,领导急着要的时候,恨不得把办公室给拆了。这事儿吧,真不是人不够勤快,是方法太原始了。你有没有发现,一旦上了合适的档案管...
2026年08月23日 06:05:28
在终端执行以下命令,完成零门槛环境部署:
``` pip install paddlepaddle==2.5.2 paddleocr==2.7.0 pillow ```依赖说明:paddlepaddle为深度学习框架,paddleocr为图像识别核心库,pillow负责图像格式处理。
在代码所在目录新建文件夹archive_images,将需要识别的档案图像(格式仅限JPG/PNG)放入该文件夹,文件名避免特殊符号。
新建文件archive_ocr.py,复制以下完整可运行代码:
``` import os import csv from PIL import Image from paddleocr import PaddleOCR 核心配置,请勿修改路径 IMAGE_FOLDER = './archive_images' RESULT_CSV = './archive_ocr_result.csv' 关键配置:过滤置信度低于0.8的无效识别结果 CONFIDENCE_THRESHOLD = 0.8 关键配置:限制图像边长,提速且减少乱码 IMAGE_MAX_WIDTH = 1024 初始化OCR(零门槛用CPU模式,中文识别) ocr = PaddleOCR( use_gpu=False, lang='ch', show_log=False, det_limit_side_len=768 ) def process_archive_images(): 写入结果CSV,编码设为utf-8避免乱码 with open(RESULT_CSV, 'w', newline='', encoding='utf-8') as csv_file: writer = csv.writer(csv_file) writer.writerow(['图像路径', '识别文字内容', '最高置信度']) 遍历图像文件夹 for img_name in os.listdir(IMAGE_FOLDER): img_path = os.path.join(IMAGE_FOLDER, img_name) 过滤非图像文件 if not img_name.lower().endswith(('.jpg', '.png')): continue 调整图像大小,提速且不影响识别 try: img = Image.open(img_path) width, height = img.size if width > IMAGE_MAX_WIDTH: new_height = int(height IMAGE_MAX_WIDTH / width) img = img.resize((IMAGE_MAX_WIDTH, new_height)) 保存临时图像,避免修改原文件 temp_path = './temp_' + img_name img.save(temp_path) current_path = temp_path else: current_path = img_path except Exception as e: writer.writerow([img_path, f'图像加载失败:{str(e)}', 0]) continue 执行图像识别 ocr_result = ocr.ocr(current_path, cls=False) 清理临时文件 if 'temp_path' in locals() and os.path.exists(temp_path): os.remove(temp_path) 处理识别结果 text_list = [] max_conf = 0.0 if ocr_result: for line in ocr_result: for word_info in line: text = word_info[1][0].strip() conf = round(word_info[1][1], 2) if conf >= CONFIDENCE_THRESHOLD: text_list.append(text) if conf > max_conf: max_conf = conf 写入CSV if text_list: full_text = '\n'.join(text_list) writer.writerow([img_path, full_text, max_conf]) else: writer.writerow([img_path, '无有效识别内容', 0]) print(f"识别完成,结果已保存至:{RESULT_CSV}") if __name__ == "__main__": process_archive_images() ```
在终端进入代码所在目录,执行以下命令:
``` python archive_ocr.py ```等待1-5分钟(取决于档案图像数量),完成后会生成archive_ocr_result.csv文件,可直接导入档案管理系统使用。
若图像超过20张,可调整IMAGE_MAX_WIDTH为800,进一步压缩图像大小;或批量拆分图像为每次10张处理,避免内存占用过高。
1. 确认档案图像清晰,无褶皱、阴影、遮挡;2. 若为繁体档案,将OCR初始化时的lang='ch'改为lang='chinese_cht';3. 检查图像是否存在严重扭曲,需先做图像校正再识别。
检查图像是否为纯白背景,或文字过于细小(字号小于12号),可放大图像后重新扫描,再执行识别。
档案数字化,政府档案保密要求高怎么办?别慌,这有“通关秘籍”