Home  >  Article  >  Backend Development  >  How to identify license plate number with one line of Python code

How to identify license plate number with one line of Python code

WBOY
WBOYforward
2023-05-10 18:04:061859browse

Recognize license plate

The code to recognize license plate is very simple, only 1 line of code is required, as shown below.

# pip install poocr
import poocr
# 可以填写本地图片的地址:img_path,也可以填写在线图片的地址:img_url
# 如果2个都填,则只用在线图片img_url
# configPath是配置文件的信息,可以不填
Number = poocr.ocr.LicensePlateOCR(
    img_path=r'C:\Users\程序员晚枫\temp\math_img.jpg',
    img_url=r'https://cache.yisu.com/upload/information/20230317/112/9432.jpg',
    configPath=r'D:\workplace\code\github\poocr\tests\poocr-config.toml')
print(Number)

This interface supports the automatic positioning and recognition of motor vehicle license plates in mainland China, and returns regional number, license plate number and license plate color information.

The returned data is as follows.

{
  ...
  "LicensePlateInfos": [
    {
      "Number": "京Q58888",
      ...
      "Color": "蓝"
    }
  ],
  "RequestId": "2be9b49d-d1ce-4344-83e8-771ea929bb97"
}
...

Extended functions

In addition, there are 6 interfaces related to vehicle recognition, which are:

# pip install poocr
import poocr
# 识别驾驶证
ressult = poocr.ocr.DriverLicenseOCR()
# 识别行驶证
ressult = poocr.ocr.VehicleLicenseOCR()
# 识别机动车登记证
ressult = poocr.ocr.VehicleRegCertOCR()
# 识别网约车驾驶证
ressult = poocr.ocr.RideHailingDriverLicenseOCR()
# 识别网约车运输证
ressult = poocr.ocr.RideHailingTransportLicenseOCR()
# 识别车辆VIN码
ressult = poocr.ocr.VinOCR()

Notes

The implementation of this function, It relies on Tencent Cloud's text recognition, so if you are a novice user, please configure a poocr-config.toml file in the same directory.

The file contents are as follows.

[tencent-ai]
TENCENTCLOUD_SECRET_ID = '你的 SecretId'     # 建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考:https://cloud.tencent.com/act/cps/redirect?redirect=36394&cps_key=ca76be5a2293ba3906d6d5407aea15ee
TENCENTCLOUD_SECRET_KEY = '你的 SecretKey'   # 建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考:https://cloud.tencent.com/act/cps/redirect?redirect=36394&cps_key=ca76be5a2293ba3906d6d5407aea15ee

The above is the detailed content of How to identify license plate number with one line of Python code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete