日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python識別身份證號碼

系統(tǒng) 2561 0
閱讀更多

用到了兩個重要的庫,以下以MacOS系統(tǒng)為例

?

1.?ImageMagick,用于對圖片進(jìn)行預(yù)處理

安裝

            brew install ImageMagick
          

?

再下載針對文本圖片清理的腳本? ?textcleaner

增加可執(zhí)行權(quán)限

            chmod +x textcleaner
          

?

測試一下效果,原始圖片


Python識別身份證號碼_第1張圖片
?

執(zhí)行命令

            ./textcleaner -g -e normalize -f 50 -o 12 -s 2 id-test3.png user_id_cleaned.png
          

得到新圖片

Python識別身份證號碼_第2張圖片
?效果非常明顯。

?

2.?pytesseract,用于識別文字

pytesseract依賴于Google?tesseract-ocr

            brew install tesseract
          

?

再安裝?pytesseract

            pip3 install pytesseract
          

?

識別代碼

            print(pytesseract.image_to_string(Image.open('user_id_cleaned.png')))
          

?

3. 完整代碼

?

            # -*- coding: utf-8 -*-
from PIL import Image
import pytesseract
import subprocess
import shlex

source_file = 'id-test3.png'
cmd = f'./textcleaner -g -e normalize -f 50 -o 12 -s 2 {source_file} user_id_cleaned.png'
print('cleaning image for text')
subprocess.run(shlex.split(cmd))

print('recognizing text from image')
print(pytesseract.image_to_string(Image.open('user_id_cleaned.png')))

          

?

?

?

?

?

?

  • Python識別身份證號碼_第3張圖片
  • 大小: 275.4 KB
  • Python識別身份證號碼_第4張圖片
  • 大小: 3 KB
  • 查看圖片附件

更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 晋江市| 重庆市| 盐山县| 克什克腾旗| 泰安市| 砚山县| 宁河县| 共和县| 思茅市| 宜丰县| 内黄县| 兴海县| 吉安市| 利津县| 遵化市| 宝山区| 乐业县| 密云县| 河源市| 肃北| 屯昌县| 榆林市| 克山县| 万州区| 河源市| 敦煌市| 巴里| 抚宁县| 当涂县| 含山县| 通辽市| 绥化市| 辽中县| 准格尔旗| 辽宁省| 高尔夫| 琼海市| 枞阳县| 勐海县| 宝山区| 东源县|