一个调用云API进行车牌识别的的例子

这个网址提供了一个云车牌识别的测试接口,我测试一下.下边是代码.

import base64
import requests

image_path = "1.jpg"
secret_key = 'YOUR_KEY' #注册后软件会给一个Key

with open(image_path, 'rb') as image_file:
    image_base64 = base64.b64encode(image_file.read())
    
url = ('https://api.openalpr.com/v2/recognize_bytes'
	+ '?recognize_vehicle=1&country=eu&secret_key={}'.format(secret key))
r= requests.post(url, data=img_base64)
try:
    print({
        'plate': r.json()['results'][0]['plate'],
        'Brand': r.json()['results'][0]['vehicle']['make'][0]['name'],
        'Color': r.json()['results'][0]['vehicle']['color'][0]['name']
	})
except:
    print('Plate cannot be identified')

输出:

{'Plate': '5G6330,, 'Brand': 'mercedes-benz', 'Color': 'silver-gray'}

这个网址效果还行,就是太贵了.

最后的话:

这篇文章发布在CSDN/蓝色的杯子, 没事多留言,让我们一起爱智求真吧.我的邮箱wisdomfriend@126.com.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是制作一个调用百度API的OCR识别页面的步骤: 1. 首先,你需要在百度AI平台上注册一个账号,并且创建一个应用,获取应用的API Key和Secret Key。 2. 在你的HTML页面中,创建一个表单,用于上传图片。 ```html <form method="POST" enctype="multipart/form-data"> <input type="file" name="image"> <input type="submit" value="识别"> </form> ``` 3. 在你的后端代码中,使用Python语言编写一个调用百度API的函数。下面是一个使用Python的requests库向百度API发送POST请求的示例代码: ```python import requests def recognize_text(image_path, api_key, secret_key): url = "https://aip.baidubce.com/oauth/2.0/token" grant_type = "client_credentials" # 获取Access Token response = requests.get( f"{url}?grant_type={grant_type}&client_id={api_key}&client_secret={secret_key}" ) access_token = response.json()["access_token"] # 发送OCR识别请求 url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" headers = {"Content-Type": "application/x-www-form-urlencoded"} params = {"access_token": access_token} image = open(image_path, "rb").read() response = requests.post(url=url, headers=headers, params=params, data=image) # 解析响应 result = response.json() if "error_code" in result: return None else: return result["words_result"] ``` 4. 在你的后端代码中,获取上传的图片,并调用OCR识别函数。 ```python from flask import Flask, request, render_template app = Flask(__name__) @app.route("/", methods=["GET", "POST"]) def home(): if request.method == "POST": # 保存上传的图片 image = request.files["image"] image.save("image.png") # 调用OCR识别函数 api_key = "your_api_key" secret_key = "your_secret_key" result = recognize_text("image.png", api_key, secret_key) # 渲染模板,显示识别结果 return render_template("result.html", result=result) else: return render_template("index.html") if __name__ == "__main__": app.run(debug=True) ``` 5. 在你的HTML模板中,渲染识别结果。 ```html {% if result %} <h2>识别结果:</h2> <ul> {% for text in result %} <li>{{ text }}</li> {% endfor %} </ul> {% endif %} ``` 以上就是制作一个调用百度API的OCR识别页面的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值