国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

Python實現(xiàn)OCR識別之pytesseract案例詳解

瀏覽:22日期:2022-06-14 17:34:51
Python實現(xiàn)OCR識別:pytesseract

Python常用pytesseract進行圖片上的文字識別,即OCR識別,完整的代碼比較簡單,只要下面一行即可,但是實際使用時環(huán)境配置上容易出錯。

from PIL import Imageimport pytesseract text = pytesseract.image_to_string(Image.open(’/Users/alice/Documents/Develop/PythonCode/textinphoto.PNG’))print(text)

因此使用前,需要先安裝pillow和pytesseract依賴包。

然而運行時仍然報錯,raise TesseractNotFoundError()pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in your path

原因是因為未安裝tesseract,然后使用pip3 install tesseract之后仍然提示錯誤,如圖:

alicedembp:~ alice$ pip3 install tesseractRequirement already satisfied: tesseract in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.1.3)alicedembp:~ alice$ tesseract-bash: tesseract: command not found

無法使用,往上找了很多教程,說是要使用brew安裝,于是得以解決,步驟為:

先安裝brew

alicedembp:~ alice$ ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)' 再使用brew安裝leptonica

alicedembp:~ alice$ brew install leptonica 使用brew安裝tesseract

alicedembp:~ alice$ brew install tesseract 安裝成功,通過命令行tesseract -v的方式查看是否成功,出現(xiàn)版本號則為安裝成功

alicedembp:~ alice$ tesseractUsage: tesseract --help | --help-extra | --version tesseract --list-langs tesseract imagename outputbase [options...] [configfile...] OCR options: -l LANG[+LANG]Specify language(s) used for OCR.NOTE: These options must occur before any configfile. Single options: --helpShow this help message. --help-extra Show extra help for advanced users. --version Show version information. --list-langs List available languages for tesseract engine. alicedembp:~ alice$ tesseract -vtesseract 4.0.0 leptonica-1.78.0 libgif 5.1.4 : libjpeg 9c : libpng 1.6.36 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.2 : libopenjp2 2.3.1 Found AVX2 Found AVX Found SSE

接下來就可以直接使用了,使用如下代碼:

alicedembp:~ alice$ tesseract /Users/alice/Documents/Develop/PythonCode/textinphoto.png /Users/alice/Documents/Develop/PythonCode/output.txt

打開textinphoto.PNG的圖片,將文字輸出到output.txt,圖片如下

Python實現(xiàn)OCR識別之pytesseract案例詳解

運行成功,產(chǎn)生output.txt文檔,里面的文本為圖片中識別出的文字。

Python實現(xiàn)OCR識別之pytesseract案例詳解

到此這篇關(guān)于Python實現(xiàn)OCR識別之pytesseract案例詳解的文章就介紹到這了,更多相關(guān)python OCR識別之pytesseract內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python pytesseract OCR識別
主站蜘蛛池模板: 白朗县| 蒙阴县| 留坝县| 秭归县| 宾川县| 娄烦县| 邻水| 韶山市| 随州市| 抚远县| 望江县| 河间市| 湖南省| 汾阳市| 通江县| 阿克苏市| 镇宁| 厦门市| 宁明县| 平舆县| 正安县| 布尔津县| 武义县| 灌南县| 克山县| 海伦市| 萝北县| 山东省| 马龙县| 玉林市| 辽宁省| 新疆| 正阳县| 洛南县| 新宁县| 京山县| 得荣县| 桑日县| 天祝| 甘孜| 安岳县|