車牌圖片識別使用hyperlpr

功能簡介:監(jiān)聽8000端口,接受直接上傳圖片來識別車牌號,也支持根據(jù)圖片url來識別車牌號。

#coding=UTF-8

import flask, os, sys,time

from flask import request

from gevent import pywsgi

import requests

import numpy as np

from hyperlpr import *

import cv2

app = flask.Flask(__name__, static_folder='static')

@app.route('/upload', methods=['post'])

def upload():

? ? fname = request.files['file']? #獲取上傳的文件

? ? print(fname)

? ? print(request.files)

? ? if fname:

? ? ? ? t = time.strftime('%Y%m%d%H%M%S')

? ? ? ? new_fname = r'static/' + t + fname.filename

? ? ? ? fname.save(new_fname)? #保存文件到指定路徑

? ? ? ? image = cv2.imread(new_fname)

? ? ? ? res = HyperLPR_plate_recognition(image)

? ? ? ? print(len(res[0]))

? ? ? ? str = " ".join('%s' %id for id in res[0])

? ? ? ? strList = str.split(' ')

? ? ? ? return strList[0].encode('raw_unicode_escape')

? ? else:

? ? ? ? return '{"msg": "請上傳文件!"}'

@app.route('/check', methods=['get'])

def check():

? ? try:

? ? ? ? fileUrl = request.args.get('fileUrl')? #獲取上傳的文件url

? ? ? ? print(fileUrl)

? ? ? ? if fileUrl:

? ? ? ? ? ? file = requests.get(fileUrl)

? ? ? ? ? ? image = cv2.imdecode(np.fromstring(file.content, np.uint8), 1) #file.content 是讀取的遠(yuǎn)程文件的字節(jié)流

? ? ? ? ? ? res = HyperLPR_plate_recognition(image)

? ? ? ? ? ? if len(res) > 0:

? ? ? ? ? ? ? ? print(len(res[0]))

? ? ? ? ? ? ? ? str = " ".join('%s' %id for id in res[0])

? ? ? ? ? ? ? ? strList = str.split(' ')

? ? ? ? ? ? ? ? return strList[0].encode('raw_unicode_escape')

? ? ? ? ? ? else:

? ? ? ? ? ? ? ? return ''?

? ? ? ? else:

? ? ? ? ? ? return '{"msg": "請上傳文件url"}',400

? ? except Exception, e:

? ? ? ? msg = 'str(Exception):\t', str(Exception)

? ? ? ? return msg,500

server = pywsgi.WSGIServer(('0.0.0.0', 8000), app)

server.serve_forever()

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容