日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python识别图片指定位置文字_python批量识别图片指定区域文字内容

發(fā)布時間:2023/12/19 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python识别图片指定位置文字_python批量识别图片指定区域文字内容 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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

簡介

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

1.截取原始圖上的指定圖片當做模板

2.根據(jù)模板相似度去再原始圖片上識別準確坐標

3.根據(jù)坐標剪切出指定位置圖片,也就是所需的內(nèi)容區(qū)域

4.對指定位置圖片進行ocr識別

環(huán)境

Ubuntu18.04

Python2.7

所需Python模塊

1.aircv

用于識別模板再原始圖的位置坐標

pip install aircv

2.Pillow

用于剪裁圖片

pip install Pillow

3.Tesseract

文字識別

在此也可以用平臺端的API進行更精準的識別

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代碼

識別對應位置

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

:return: None or dict({'confidence': 相似度(float), 'rectangle': 原始圖片上的矩形坐標(tuple), 'result': 中心坐標(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ù)坐標位置剪切圖片

:param imgsrc: 原始圖片路徑(str)

:param out_img_name: 剪切輸出圖片路徑(str)

:param coordinate: 原始圖片上的坐標(tuple) egg:(x, y, w, h) ---> x,y為矩形左上角坐標, w,h為右下角坐標

: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)

對于三方API識別自行研究

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。

本文標題: python批量識別圖片指定區(qū)域文字內(nèi)容

本文地址: http://www.cppcns.com/jiaoben/python/258124.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的python识别图片指定位置文字_python批量识别图片指定区域文字内容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。