最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python批量識(shí)別圖片指定區(qū)域文字內(nèi)容

 更新時(shí)間:2021年06月22日 11:50:18   作者:林圈圈的  
這篇文章主要為大家詳細(xì)介紹了python識(shí)別圖片指定區(qū)域文字內(nèi)容,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

Python批量識(shí)別圖片指定區(qū)域文字內(nèi)容,供大家參考,具體內(nèi)容如下

簡(jiǎn)介

對(duì)于一張圖片,需求識(shí)別指定區(qū)域的內(nèi)容

1.截取原始圖上的指定圖片當(dāng)做模板
2.根據(jù)模板相似度去再原始圖片上識(shí)別準(zhǔn)確坐標(biāo)
3.根據(jù)坐標(biāo)剪切出指定位置圖片,也就是所需的內(nèi)容區(qū)域
4.對(duì)指定位置圖片進(jìn)行ocr識(shí)別

環(huán)境

Ubuntu18.04
Python2.7

所需Python模塊

1.aircv

用于識(shí)別模板再原始圖的位置坐標(biāo)

pip install aircv

2.Pillow

用于剪裁圖片

pip install Pillow

3.Tesseract

文字識(shí)別
在此也可以用平臺(tái)端的API進(jìn)行更精準(zhǔn)的識(shí)別
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代碼

識(shí)別對(duì)應(yīng)位置

#!/usr/bin/python2.7 
# -*- coding: utf-8 -*- 
import aircv


def matchImg(imgsrc, imgobj, confidence=0.2):
 """
  圖片對(duì)比識(shí)別imgobj在imgsrc上的相對(duì)位置(批量識(shí)別統(tǒng)一圖片中需要的部分)
 :param imgsrc: 原始圖片路徑(str)
 :param imgobj: 待查找圖片路徑(模板)(str)
 :param confidence: 識(shí)別度(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)

圖片識(shí)別

#!/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)

對(duì)于三方API識(shí)別自行研究

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

阳曲县| 平泉县| 白沙| 维西| 峨山| 广州市| 孟连| 那曲县| 斗六市| 平阳县| 桃园市| 凯里市| 泸溪县| 大厂| 凌云县| 桑日县| 南召县| 东安县| 合水县| 富裕县| 余庆县| 阿尔山市| 彭水| 灵璧县| 合川市| 扬州市| 泌阳县| 天峨县| 南昌市| 清涧县| 洪洞县| 凯里市| 融水| 集贤县| 虹口区| 西贡区| 焦作市| 石屏县| 汝阳县| 开平市| 乌兰察布市|