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.

upload.py 1.5 kB

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