OCR使用开源

之前用过百度的ocr,GitHub上蛮复杂感觉,官网的需要money,且接口不能一直循环调用。

这里分享一个好用的方法。

直接上代码:


import cv2
import pytesseract
import os
pytesseract.pytesseract.tesseract_cmd = '/usr/local/bin/tesseract'
for i in os.listdir('/Users/fuchenli/Desktop/evl/'):
    print(i)
    outfile = 'test_txt/{}.txt'.format(i[:-4])
    image = cv2.imread('/Users/fuchenli/Desktop/evl/{}'.format(i))
    text = pytesseract.image_to_string(image, lang='chi_sim')
    #print(text)
    text = text.replace(' ', '').replace('\n', '')
    fo = open(outfile, 'a')
    k = 0

    fo.writelines(text)


    # fo.writelines('\n'*2)
print("文本导出成功!")
print()

猜你喜欢

转载自blog.csdn.net/qq_40962125/article/details/130826571
OCR