python百度aip移动目标监控系统_python利用百度云接口实现车牌识别
一個(gè)小需求---實(shí)現(xiàn)車(chē)牌識(shí)別。
目前有兩個(gè)想法
調(diào)云在線的接口或者使用SDK做開(kāi)發(fā)(配置環(huán)境和編譯第三方庫(kù)很麻煩,當(dāng)然使用python可以避免這些問(wèn)題)
自己實(shí)現(xiàn)車(chē)牌識(shí)別算法(復(fù)雜)
!
一開(kāi)始準(zhǔn)備使用百度云文字識(shí)別C++ SDK來(lái)做,發(fā)現(xiàn)需要準(zhǔn)備curl、jsoncpp和OpenCV,并且curl和jsoncpp需要自己編譯,很麻煩,所以換用了python來(lái)做,真的是順暢簡(jiǎn)單。
安裝python環(huán)境(我用python3.7)
python官網(wǎng)下載地址:https://www.python.org/downloads/release/python-374/ 建議直接下載安裝版installer(看對(duì)系統(tǒng)和位數(shù))?打開(kāi)安裝包無(wú)腦安裝即可。安裝好之后,看一下是否安裝成功。
cmd
python --version?
百度云SDK下載安裝及創(chuàng)建應(yīng)用
參考https://cloud.baidu.com/doc/OCR/s/pjwvxzmtc文檔,安裝python SDK
查看pip版本(python環(huán)境自帶,但是要注意版本)
pip?--version
?如果版本不合適,那么自行升級(jí)pip
pip?install?-U?pip
安裝baidu-aip
pip?install?baidu-aip
?現(xiàn)在我們的百度云SDK就安裝好了,下來(lái)創(chuàng)建應(yīng)用
登錄百度云(沒(méi)賬號(hào)注冊(cè)一下)
?創(chuàng)建應(yīng)用
?自己填一下
?現(xiàn)在我們就創(chuàng)建好了車(chē)牌識(shí)別的應(yīng)用,點(diǎn)擊應(yīng)用列表可查看。?這里的APPID、API KEY、Secret Key要在代碼中使用。(注意不要泄漏)
編碼調(diào)接口,實(shí)現(xiàn)需求
python代碼實(shí)現(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)
""" 調(diào)用車(chē)牌識(shí)別 """
res?=?client.licensePlate(image)
return?res
""" call example """
str?=?'C:\\Users\\***\\Desktop\\big.jpg'?""" 照片絕對(duì)地址 """
res?=?get_license_plate(str)
print('車(chē)牌號(hào)碼:'?+?res['words_result']['number'])
print('車(chē)牌顏色:'?+?res['words_result']['color'])
至此,我們就實(shí)現(xiàn)了使用百度云SDK,通過(guò)編寫(xiě)python代碼調(diào)用接口的車(chē)牌識(shí)別需求。
總結(jié)
以上是生活随笔為你收集整理的python百度aip移动目标监控系统_python利用百度云接口实现车牌识别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C/C++语言中联合体union的妙用
- 下一篇: python外汇兑换代码_python爬