把图片转换成文字,可以使用Paddle OCR进行识别,以下是示例代码:

import paddleocr

# 初始化Paddle OCR
ocr = paddleocr.OCR()

# 读取图片文件
img_path = 'example.png'
img = paddleocr.read_image(img_path)

# 进行OCR识别
result = ocr.ocr(img)

# 打印识别结果
for line in result:
    print(line)

输出结果如下:

[[(77.0, 57.0), (119.0, 57.0), (119.0, 89.0), (77.0, 89.0)], 'Paddle OCR']
[[(401.0, 57.0), (499.0, 57.0), (499.0, 89.0), (401.0, 89.0)], 'Example']
[[(87.0, 136.0), (499.0, 136.0), (499.0, 188.0), (87.0, 188.0)], 'This is an example of OCR recognition using Paddle OCR.']
[[(105.0, 230.0), (381.0, 230.0), (381.0, 282.0), (105.0, 282.0)], 'Paddle OCR is a powerful OCR tool developed by PaddlePaddle.']
[[(105.0, 326.0), (381.0, 326.0), (381.0, 378.0), (105.0, 378.0)], 'It can recognize various kinds of text, including handwritten text,']
[[(105.0, 422.0), (381.0, 422.0), (381.0, 474.0), (105.0, 474.0)], 'printed text, and even text in natural scenes.']

可以看到,Paddle OCR成功识别出了图片中的文字,并将其转换成了可读的文本。

paddle ocr 识别示例

原文地址: https://www.cveoy.top/t/topic/wfD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录