PaddleOCR 图片转文字(python)

1. 使用OCR工具

OCR(光学字符识别)技术可以将图片中的文字提取出来。以下是几种常见的OCR工具:

Google Keep:将图片上传到Google Keep,然后使用“提取文字”功能。

Microsoft OneNote:将图片插入到OneNote中,右键点击图片并选择“复制图片中的文本”。

Adobe Acrobat:使用Adobe Acrobat的OCR功能将图片转换为可编辑的PDF或文本文件。

2. 在线OCR服务

有许多在线OCR服务可以将图片转换为文字,例如:

Online OCR(https://www.onlineocr.net/)

Smallpdf(https://smallpdf.com/ocr)

i2OCR(https://www.i2ocr.com/)

3. 手机应用

许多手机应用也提供图片转文字的功能,例如:

Google Lens:使用Google Lens拍摄或上传图片,然后提取文字。

Microsoft Office Lens:拍摄图片并提取文字,支持导出到Word、PDF等格式。

CamScanner:扫描图片并提取文字。

代码实现:

安装包

 pip install paddlepaddle
pip install paddleocr  

代码如下:

from paddleocr import PaddleOCR

ocr = PaddleOCR(use_angle_cls=False, lang='ch', use_gpu=False)

image_path = 'test.png'  # 替换为你的图片路径
result = ocr.ocr(image_path, cls=True)

print("OCR 结果原始数据:", result)  # 🔴 调试输出

if not result or not result[0]:
    print("未检测到文本")
else:
    result = result[0]  # 取出真正的 OCR 结果
    with open('ocr_result.txt', 'w', encoding='utf-8') as f:
        for idx, line in enumerate(result):
            print(f"当前处理数据:{line}")  # 🔴 调试输出

            if len(line) < 2 or not isinstance(line[1], tuple):
                print(f"⚠️ 第 {idx + 1} 行格式异常,跳过: {line}")
                continue

            text, confidence = line[1]  # 取出文字和置信度
            if not isinstance(text, str):
                print(f"⚠️ 文字内容异常,跳过: {text}")
                continue

            f.write(text + '\n')  # 确保正确写入
            print(f"✅ 成功写入: {text}")  # 🔴 调试输出

    print("🎉 识别结果已保存到 ocr_result.txt")

示例图片:

请添加图片描述

在这里插入图片描述

识别效果:

ocr_result.txt

在这里插入图片描述
这个效果还是不错的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小海聊智造

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值