一個小需求---實現(xiàn)車牌識別冠场。
目前有兩個想法
調云在線的接口或者使用SDK做開發(fā)(配置環(huán)境和編譯第三方庫很麻煩,當然使用python可以避免這些問題)
自己實現(xiàn)車牌識別算法(復雜)
一開始準備使用百度云文字識別C++ SDK來做,發(fā)現(xiàn)需要準備curl爵政、jsoncpp和OpenCV仅讽,并且curl和jsoncpp需要自己編譯,很麻煩钾挟,所以換用了python來做洁灵,真的是順暢簡單。
安裝python環(huán)境(我用python3.7)
python官網(wǎng)下載地址:https://www.python.org/downloads/release/python-374/ 建議直接下載安裝版installer(看對系統(tǒng)和位數(shù))?打開安裝包無腦安裝即可掺出。安裝好之后徽千,看一下是否安裝成功。
汤锨!
cmd
python --version?
百度云SDK下載安裝及創(chuàng)建應用
參考https://cloud.baidu.com/doc/OCR/s/pjwvxzmtc文檔双抽,安裝python SDK
查看pip版本(python環(huán)境自帶,但是要注意版本)
pip?--version
?如果版本不合適闲礼,那么自行升級pip
pip?install?-U?pip
安裝baidu-aip
pip?install?baidu-aip
?現(xiàn)在我們的百度云SDK就安裝好了牍汹,下來創(chuàng)建應用
登錄百度云(沒賬號注冊一下)
?創(chuàng)建應用
?自己填一下
?現(xiàn)在我們就創(chuàng)建好了車牌識別的應用,點擊應用列表可查看位仁。?這里的APPID柑贞、API KEY、Secret Key要在代碼中使用聂抢。(注意不要泄漏)
編碼調接口钧嘶,實現(xiàn)需求
python代碼實現(xiàn)
'''
Statement
1. using the file
2. prepare a image path and call func "get_license_plate(filePath)"
3. you can get a json object
4. get the info from the pbject
example :
{
? "log_id": 3583925545,
? "words_result": {
? ? ? "color": "blue",
? ? ? "number": "蘇HS7766"
? }
}
'''
from?aip?import?AipOcr
import?json
"""get img"""
def?get_file_content(filePath):
? ?with?open(filePath,?'rb')?as?fp:
? ? ? ?return?fp.read()
""" get licsense plate """
def?get_license_plate(filePath):
? ?""" APPID AK SK """
? ?APP_ID?=?'********'
? ?API_KEY?=?'**************'
? ?SECRET_KEY?=?'******************'
? ?""" create client """
? ?client?=?AipOcr(APP_ID,?API_KEY,?SECRET_KEY)
? ?image?=?get_file_content(filePath)
? ?""" 調用車牌識別 """
? ?res?=?client.licensePlate(image)
? ?return?res
""" call example """
str?=?'C:\\Users\\***\\Desktop\\big.jpg'?""" 照片絕對地址 """
res?=?get_license_plate(str)
print('車牌號碼:'?+?res['words_result']['number'])
print('車牌顏色:'?+?res['words_result']['color'])
至此,我們就實現(xiàn)了使用百度云SDK琳疏,通過編寫python代碼調用接口的車牌識別需求有决。