Life is short, use Baidu Cloud SDK, write python code that calls the interface plate recognition

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45523154/article/details/102750352

Two ideas

  1. Tune cloud online interface or use the SDK to do development (environment and configure third-party libraries to compile a lot of trouble, of course, these problems can be avoided using python)

  2. Own license plate recognition algorithms (complex)

    Baidu cloud began to prepare a text recognition using C ++ SDK to do, find it necessary to prepare curl, jsoncpp and OpenCV, and curl and jsoncpp need to compile a lot of trouble, so switching to a python to do, really smooth and simple.

  3. Install python environment (I use python3.7)

Open the installation package can be installed without the brain. After installing, see if the installation was successful.

cmd

python --version

  1. Baidu Cloud SDK to create applications to download and install

Reference https://cloud.baidu.com/doc/OCR/s/pjwvxzmtc documentation, installation python SDK

View pip version (python own environment, but be aware version)

pip --version

If the version is not appropriate, then the upgrade itself pip

pip install -U pip

AnSo baidu-aip

pip install baidu-aip


Interested in Python or are studying a small partner, you can join us to learn Python buckle qun: 784758214, look at how seniors are learning! From basic web development python script to, reptiles, django, data mining and other projects to combat zero-based data are finishing. Given to every little python partner! Every day, Daniel explain the timing Python technology, to share some of the ways to learn and need to pay attention to small details, click on Join us python learner gathering

Now we are on the Baidu Cloud SDK installed, create applications down

Login Baidu Cloud (account registration did not look)

Creating an application

Fill out their own

现在我们就创建好了车牌识别的应用,点击应用列表可查看。

这里的APPID、API KEY、Secret Key要在代码中使用。(注意不要泄漏)

  1. 编码调接口,实现需求

python代码实现

'''
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'])
在学习过程中有什么不懂得可以加我的
python学习交流扣扣qun,784758214
群里有不错的学习视频教程、开发工具与电子书籍。
与你分享python企业当下人才需求及怎么从零基础学习好python,和学习什么内容

至此,我们就实现了使用百度云SDK,通过编写python代码调用接口的车牌识别需求。

Guess you like

Origin blog.csdn.net/weixin_45523154/article/details/102750352