python中怎么批量識別圖片指定區(qū)域的文字,針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信平臺小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了鄯善免費(fèi)建站歡迎大家使用!1.aircv
用于識別模板再原始圖的位置坐標(biāo)
pip install aircv
2.Pillow
用于剪裁圖片
pip install Pillow
3.Tesseract
文字識別
在此也可以用平臺端的API進(jìn)行更精準(zhǔn)的識別
ubuntu下Tesseract環(huán)境安裝
sudo apt-get install libpng12-dev sudo apt-get install libjpeg62-dev sudo apt-get install libtiff4-dev sudo apt-get install gcc sudo apt-get install g++ sudo apt-get install automake
1.tesseract-ocr安裝
sudo apt-get install tesseract-ocr
2.pytesseract安裝
pip install pytesseract
Python代碼
識別對應(yīng)位置
#!/usr/bin/python2.7 # -*- coding: utf-8 -*- import aircv def matchImg(imgsrc, imgobj, confidence=0.2): """ 圖片對比識別imgobj在imgsrc上的相對位置(批量識別統(tǒng)一圖片中需要的部分) :param imgsrc: 原始圖片路徑(str) :param imgobj: 待查找圖片路徑(模板)(str) :param confidence: 識別度(0<confidence<1.0) :return: None or dict({'confidence': 相似度(float), 'rectangle': 原始圖片上的矩形坐標(biāo)(tuple), 'result': 中心坐標(biāo)(tuple)}) """ imsrc = aircv.imread(imgsrc) imobj = aircv.imread(imgobj) match_result = aircv.find_template(imsrc, imobj, confidence) # {'confidence': 0.5435812473297119, 'rectangle': ((394, 384), (394, 416), (450, 384), (450, 416)), 'result': (422.0, 400.0)} if match_result is not None: match_result['shape'] = (imsrc.shape[1], imsrc.shape[0]) # 0為高,1為寬 return match_result
圖片剪裁
#!/usr/bin/python2.7 # -*- coding: utf-8 -*- from PIL import Image, ImageEnhance def cutImg(imgsrc, out_img_name, coordinate): """ 根據(jù)坐標(biāo)位置剪切圖片 :param imgsrc: 原始圖片路徑(str) :param out_img_name: 剪切輸出圖片路徑(str) :param coordinate: 原始圖片上的坐標(biāo)(tuple) egg:(x, y, w, h) ---> x,y為矩形左上角坐標(biāo), w,h為右下角坐標(biāo) :return: """ image = Image.open(imgsrc) region = image.crop(coordinate) region = ImageEnhance.Contrast(region).enhance(1.5) region.save(out_img_name)
圖片識別
#!/usr/bin/python2.7 # -*- coding: utf-8 -*- import pytesseract from PIL import Image image = Image.open('bb.png') code = pytesseract.image_to_string(image) print(code)
關(guān)于python中怎么批量識別圖片指定區(qū)域的文字問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道了解更多相關(guān)知識。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
網(wǎng)頁標(biāo)題:python中怎么批量識別圖片指定區(qū)域的文字-創(chuàng)新互聯(lián)
本文路徑:http://www.muchs.cn/article28/depcjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、響應(yīng)式網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、服務(wù)器托管、網(wǎng)站導(dǎo)航、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容