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

65 lines
1.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. from modules import utils
  2. from flask import Flask, request, Response
  3. from flask_restful import Resource, Api
  4. from PIL import Image
  5. import base64
  6. import json
  7. import sys
  8. import os
  9. import io
  10. if sys.platform == "win32":
  11. import tensorflow as tf
  12. import numpy as np
  13. import pickle
  14. sys.path.insert(0, r'C:\Users\Tednokent01\Downloads\MyCity\traffic_analyzer')
  15. from utils import label_map_util
  16. from utils import visualization_utils as vis_util
  17. app = Flask(__name__)
  18. api = Api(app)
  19. db_path = os.path.join(app.root_path, 'databases', 'crashes.json')
  20. with open(db_path, 'r') as f:
  21. crashes = json.load(f)
  22. users_path = os.path.join(app.root_path, 'databases', 'users.json')
  23. with open(users_path, 'r') as f:
  24. users = json.load(f)
  25. if sys.platform == "win32":
  26. PATH_TO_LABELS = '../../traffic_analyzer/object_detection/data/mscoco_label_map.pbtxt'
  27. PATH_TO_CKPT = 'modules/faster_rcnn_resnet101_kitti_2018_01_28/frozen_inference_graph.pb'
  28. NUM_CLASSES = 8
  29. detection_graph = tf.Graph()
  30. with detection_graph.as_default():
  31. od_graph_def = tf.GraphDef()
  32. with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
  33. serialized_graph = fid.read()
  34. od_graph_def.ParseFromString(serialized_graph)
  35. tf.import_graph_def(od_graph_def, name='')
  36. label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
  37. categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
  38. category_index = label_map_util.create_category_index(categories)
  39. def process_img(img):
  40. pass
  41. class Crash(Resource):
  42. def post(self):
  43. message = request.form['message']
  44. base64_img = request.form['img']
  45. id = request.form['id']
  46. process_img(Image.open(io.BytesIO(base64.b64decode(base64_img))))
  47. return id