百度AI之图像识别SDK:车牌识别

最近想研究学习OCR识别的知识,当然就想起来先拿百度AI来试个手体验一下啦~???
不过好像百度的SDK升级了,记得去年八月份的时候用这个的时候要先修改原SDK中的部分代码(主要是图片编码处理的),这次直接就可以用了,话不多说直接贴上代码:

#-*-coding:utf-8-*-
from aip import AipOcr
import cv2 as cv
import numpy as np
#from PIL import Image

""" 你的 APPID AK SK """
APP_ID = '160**570'
API_KEY = 'wuN**pO25TGHFaUF8l2MI42I'
SECRET_KEY = 'H3G2K9N**TDnjG1zpwFgGo7iK3xvcNl'

client = AipOcr(APP_ID, API_KEY, SECRET_KEY)


""" 读取图片 """
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

image = get_file_content('example.jpg')

""" 调用车牌识别 """
client.licensePlate(image);

""" 如果有可选参数 """
options = {}
options["multi_detect"] = "true"

""" 带参数调用车牌识别 """
fb = client.licensePlate(image, options)
print("return log:",fb)

result = fb['words_result']
#print(result)
#print(type(result))

#color = result[0]['color']
#number = result[0]['number']
location = result[0]['vertexes_location']
#print(color)
#print(number)
#print(type(number))
#print(location)

img = cv.imread("./example.jpg")

#cv.putText(img, number1, (np.int(location[0]['x']), np.int(location[0]['y'])-20), cv.FONT_HERSHEY_TRIPLEX, 0.8, (0, 255,0), 2)
cv.rectangle(img, (np.int(location[0]['x']), np.int(location[0]['y'])), (np.int(location[2]['x']), np.int(location[2]['y'])), (0, 255, 0),2,cv.LINE_8,0) 
cv.imshow("result",img)
cv.waitKey(0)
cv.destroyAllWindows()

代码基本照抄的SDK参考文档里的,仅仅加入了opencv来可视化结果的代码。由于options[“multi_detect”] = “true”,所以是可以检测包含多个车牌的图片的,这里我只是使用了只有一个车牌的图片。
返回的log如下:

return log: {'log_id': 5299849045275730993, 
'words_result': [{'color': 'blue', 
				  'number': '苏JAY888', 
				  'probability': [1.0, 1.0, 0.9999914169311523,
				   				  0.9999885559082031,
				   				  0.9993658065795898, 0.9993288516998291, 
				   		          0.9992438554763794], 
				  'vertexes_location': [
				  {'y': 184, 'x': 88}, 
				  {'y': 181, 'x': 303}, 
				  {'y': 235, 'x': 304}, 
				  {'y': 239, 'x': 90}
				  ]}]}

其中color就是车牌颜色,number就是车牌号,prob就是六个字符的置信度,v_l就是车牌四个定点的位置(左上,右上,右下,左下)。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值