亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python利用pytesseract 實(shí)現(xiàn)本地識(shí)別圖片文字

瀏覽:6日期:2022-07-02 10:45:07

#!/usr/bin/env python3# -*- coding: utf-8 -*-import globfrom os import pathimport osimport pytesseractfrom PIL import Imagefrom queue import Queueimport threadingimport datetimeimport cv2def convertimg(picfile,outdir): ’調(diào)整圖片大小,對(duì)于過大的圖片進(jìn)行壓縮 picfile: 圖片路徑 outdir: 圖片輸出路徑 ’ img = Image.open(picfile)  width, height = img.size  while (width * height 4000000): # 該數(shù)值壓縮后的圖片大約 兩百多k width = width / 2 height = height / 2  new_img = img.resize((width,height), Image.BILINEAR) new_img.save(path.join(outdir, os.path.basename(picfile)))def baiduOCR(ts_queue): while not ts_queue.empty(): picfile = ts_queue.get() filename = path.basename(picfile) outfile = ’D:StudypythonProjectscrapyIpProxyport_zidian.txt’ img = cv2.imread(picfile, cv2.IMREAD_COLOR) print('正在識(shí)別圖片:t' + filename) message = pytesseract.image_to_string(img,lang = ’eng’) message = message.replace(’’, ’’) message = message.replace(’’, ’’) # message = client.basicAccurate(img)  # 通用文字高精度識(shí)別,每天 800 次免費(fèi) #print('識(shí)別成功!') try: filename1 = filename.split(’.’)[0] filename1 = ’’.join(filename1) with open(outfile, ’a+’) as fo: fo.writelines(’’ + filename1 + ’’ + ’:’ + message + ’,’) fo.writelines(’n’) # fo.writelines('+' * 60 + ’n’) # fo.writelines('識(shí)別圖片:t' + filename + 'n' * 2) # fo.writelines('文本內(nèi)容:n') # 輸出文本內(nèi)容 # for text in message.get(’words_result’): # fo.writelines(text.get(’words’) + ’n’) # fo.writelines(’n’ * 2) os.remove(filename) print('識(shí)別成功!') except: print(’識(shí)別失敗’) print('文本導(dǎo)出成功!') print()def duqu_tupian(dir): ts_queue = Queue(10000) outdir = dir # if path.exists(outfile): # os.remove(outfile) if not path.exists(outdir): os.mkdir(outdir)  print('壓縮過大的圖片...') # 首先對(duì)過大的圖片進(jìn)行壓縮,以提高識(shí)別速度,將壓縮的圖片保存與臨時(shí)文件夾中 try: for picfile in glob.glob(r'D:StudypythonProjectscrapyIpProxytmp*'): convertimg(picfile, outdir) print('圖片識(shí)別...') for picfile in glob.glob('tmp1/*'): ts_queue.put(picfile) #baiduOCR(picfile, outfile) #os.remove(picfile) print(’圖片文本提取結(jié)束!文本輸出結(jié)果位于文件中。’) #os.removedirs(outdir) return ts_queue except: print(’失敗’)if __name__ == '__main__': start = datetime.datetime.now().replace(microsecond=0) t = ’tmp1’ s = duqu_tupian(t) threads = [] try: for i in range(100): t = threading.Thread(target=baiduOCR, name=’th-’ + str(i), kwargs=[’ts_queue’: s]) threads.append(t) for t in threads: t.start() for t in threads: t.join() end = datetime.datetime.now().replace(microsecond=0) print(’刪除耗時(shí):’ + str(end - start)) except: print(’識(shí)別失敗’)

實(shí)測(cè)速度慢,但用了多線程明顯提高了速度,但準(zhǔn)確度稍低,同樣高清圖片,90百分識(shí)別率。還時(shí)不時(shí)出現(xiàn)亂碼文字,亂空格,這里展現(xiàn)不了,自己實(shí)踐吧,重點(diǎn)免費(fèi)的,隨便識(shí)別,通向100張圖片,用時(shí)快6分鐘了,速度慢了一倍,但是是免費(fèi)的,挺不錯(cuò)的了。

以上就是python利用pytesseract 實(shí)現(xiàn)本地識(shí)別圖片文字的詳細(xì)內(nèi)容,更多關(guān)于python 識(shí)別圖片文字的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲第一页中文字幕 | 亚洲一级高清在线中文字幕 | 美女在线看永久免费网址 | 闫盼盼福利 | 国产精品福利资源在线 | 国产视频www | 日本免费一区二区三区a区 日本内谢69xxxx免费播放 | 欧美在线视频精品 | 一级片日韩 | 色拍拍在线精品视频 | 国内自拍第1页 | 成人伊人亚洲人综合网站222 | 美女国产一区 | 日韩在线观看高清 | 国产成人在线播放视频 | 日本亚洲欧美国产日韩ay高清 | 色老头福利视频在线观看 | 免费在线国产视频 | 91精品国产露脸在线 | 秀人网福利视频在线观看 | aaa毛片视频免费观看 | 色爱综合区五月小说 | 国产精品99久久免费黑人 | 成人午夜啪啪免费网站 | 国产一区二区在线视频 | 午夜久久 | 亚洲美女在线播放 | 无码专区aaaaaa免费视频 | 激情婷婷成人亚洲综合 | 九九热视频在线播放 | 日韩欧美国产偷亚洲清高 | 青草草视频在线观看 | 免费在线观看视频网站 | 国产精品果冻 | 欧美成人午夜免费完成 | 亚洲天堂婷婷 | 亚洲另类欧美日韩 | 国产剧情福利 | 色婷婷综合在线视频最新 | 中文字幕在线看片成人 | 四虎现在的网址入口2022 |