You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebAPI.py 1.4 kB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #coding=utf-8
  2. from flask import Flask, render_template, request
  3. from werkzeug.utils import secure_filename
  4. import cv2
  5. import numpy as np
  6. #导入opencv
  7. from hyperlpr_py3 import pipline
  8. #导入车牌识别库
  9. app = Flask(__name__)
  10. #设置App name
  11. def recognize(filename):
  12. image = cv2.imread(filename)
  13. #通过文件名读入一张图片 放到 image中
  14. return pipline.RecognizePlateJson(image)
  15. #识别一张图片并返回json结果
  16. #识别函数
  17. import base64
  18. def recognizeBase64(base64_code):
  19. file_bytes = np.asarray(bytearray(base64.b64decode(base64_code)),dtype=np.uint8)
  20. image_data_ndarray = cv2.imdecode(file_bytes,1)
  21. return pipline.RecognizePlateJson(image_data_ndarray)
  22. import time
  23. @app.route('/uploader', methods=['GET', 'POST'])#设置请求路由
  24. def upload_file():
  25. if request.method == 'POST':
  26. #如果请求方法是POST
  27. f = request.files['file']
  28. f.save("./images_rec/"+secure_filename(f.filename))
  29. #保存请求上来的文件
  30. t0 = time.time()
  31. res = recognize("./images_rec/"+secure_filename(f.filename))
  32. print("识别时间",time.time() - t0)
  33. return res
  34. #返回识别结果
  35. # return 'file uploaded successfully'
  36. return render_template('upload.html')
  37. if __name__ == '__main__':
  38. #入口函数
  39. app.run("0.0.0.0", port=8000, threaded=False, debug=False)
  40. #运行app 指定IP 指定端口