Browse Source

I hope this fucking works

yigit
Yiğit Çolakoğlu 6 years ago
parent
commit
a3755d014b
114 changed files with 174323 additions and 271574 deletions
  1. +4
    -4
      master_app/nbactions.xml
  2. +5
    -0
      master_app/pom.xml
  3. +588
    -340
      master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form
  4. +761
    -478
      master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
  5. BIN
      master_app/src/main/java/me/yigitcolakoglu/master_app/thermometer.png
  6. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/Main.class
  7. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$1.class
  8. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$2.class
  9. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$3.class
  10. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$4.class
  11. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$5.class
  12. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$6.class
  13. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$7.class
  14. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$8.class
  15. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$9.class
  16. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm.class
  17. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$1.class
  18. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$2.class
  19. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$3.class
  20. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$4.class
  21. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$5.class
  22. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$6.class
  23. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$7.class
  24. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$8.class
  25. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$9.class
  26. BIN
      master_app/target/classes/me/yigitcolakoglu/master_app/managementForm.class
  27. +3
    -3
      master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
  28. +5
    -0
      server_side/.idea/codeStyles/codeStyleConfig.xml
  29. +4
    -0
      server_side/.idea/encodings.xml
  30. +6
    -0
      server_side/.idea/misc.xml
  31. +9
    -0
      server_side/.idea/modules.xml
  32. +6
    -0
      server_side/.idea/vcs.xml
  33. +25
    -7
      server_side/api/ai_services.py
  34. +1
    -2
      server_side/api/app.py
  35. +2
    -2
      server_side/api/modules/SpotSelector.py
  36. BIN
      server_side/api/modules/c.jpeg
  37. +38
    -38
      server_side/api/modules/car_crash.py
  38. +6
    -6
      server_side/api/modules/complaint.py
  39. +6
    -47
      server_side/api/modules/databases/complaints.json
  40. +12
    -12
      server_side/api/modules/databases/locations.json
  41. +172268
    -270368
      server_side/api/modules/databases/park_data.json
  42. +298
    -149
      server_side/api/modules/databases/users.json
  43. +4
    -7
      server_side/api/modules/smart_park.py
  44. +162
    -0
      server_side/api/modules/smart_park.py.save
  45. +8
    -10
      server_side/api/modules/user_set.py
  46. +1
    -1
      server_side/api/object_detection/core/preprocessor.py
  47. +1
    -1
      server_side/api/object_detection/object_detection_tutorial.ipynb
  48. +1
    -1
      server_side/api/object_detection/protos/anchor_generator_pb2.py
  49. +1
    -1
      server_side/api/object_detection/protos/argmax_matcher_pb2.py
  50. +1
    -1
      server_side/api/object_detection/protos/bipartite_matcher_pb2.py
  51. +1
    -1
      server_side/api/object_detection/protos/box_coder_pb2.py
  52. +1
    -1
      server_side/api/object_detection/protos/box_predictor_pb2.py
  53. +1
    -1
      server_side/api/object_detection/protos/calibration_pb2.py
  54. +1
    -1
      server_side/api/object_detection/protos/eval_pb2.py
  55. +1
    -1
      server_side/api/object_detection/protos/faster_rcnn_box_coder_pb2.py
  56. +1
    -1
      server_side/api/object_detection/protos/faster_rcnn_pb2.py
  57. +1
    -1
      server_side/api/object_detection/protos/flexible_grid_anchor_generator_pb2.py
  58. +1
    -1
      server_side/api/object_detection/protos/graph_rewriter_pb2.py
  59. +1
    -1
      server_side/api/object_detection/protos/grid_anchor_generator_pb2.py
  60. +1
    -1
      server_side/api/object_detection/protos/hyperparams_pb2.py
  61. +1
    -1
      server_side/api/object_detection/protos/image_resizer_pb2.py
  62. +1
    -1
      server_side/api/object_detection/protos/input_reader_pb2.py
  63. +1
    -1
      server_side/api/object_detection/protos/keypoint_box_coder_pb2.py
  64. +1
    -1
      server_side/api/object_detection/protos/losses_pb2.py
  65. +1
    -1
      server_side/api/object_detection/protos/matcher_pb2.py
  66. +1
    -1
      server_side/api/object_detection/protos/mean_stddev_box_coder_pb2.py
  67. +1
    -1
      server_side/api/object_detection/protos/model_pb2.py
  68. +1
    -1
      server_side/api/object_detection/protos/multiscale_anchor_generator_pb2.py
  69. +1
    -1
      server_side/api/object_detection/protos/optimizer_pb2.py
  70. +1
    -1
      server_side/api/object_detection/protos/pipeline_pb2.py
  71. +1
    -1
      server_side/api/object_detection/protos/post_processing_pb2.py
  72. +1
    -1
      server_side/api/object_detection/protos/preprocessor_pb2.py
  73. +1
    -1
      server_side/api/object_detection/protos/region_similarity_calculator_pb2.py
  74. +1
    -1
      server_side/api/object_detection/protos/square_box_coder_pb2.py
  75. +1
    -1
      server_side/api/object_detection/protos/ssd_anchor_generator_pb2.py
  76. +1
    -1
      server_side/api/object_detection/protos/ssd_pb2.py
  77. +1
    -1
      server_side/api/object_detection/protos/string_int_label_map_pb2.py
  78. +1
    -1
      server_side/api/object_detection/protos/train_pb2.py
  79. +30
    -26
      traffic_analyzer/ambulance_detect.py
  80. +5
    -8
      traffic_analyzer/ml_setup.py
  81. +1
    -1
      traffic_analyzer/object_detection/.ipynb_checkpoints/object_detection_tutorial-checkpoint.ipynb
  82. +1
    -1
      traffic_analyzer/object_detection/core/preprocessor.py
  83. +1
    -1
      traffic_analyzer/object_detection/data/mscoco_label_map.pbtxt
  84. +1
    -1
      traffic_analyzer/object_detection/object_detection_tutorial.ipynb
  85. +1
    -1
      traffic_analyzer/object_detection/protos/anchor_generator_pb2.py
  86. +1
    -1
      traffic_analyzer/object_detection/protos/argmax_matcher_pb2.py
  87. +1
    -1
      traffic_analyzer/object_detection/protos/bipartite_matcher_pb2.py
  88. +1
    -1
      traffic_analyzer/object_detection/protos/box_coder_pb2.py
  89. +1
    -1
      traffic_analyzer/object_detection/protos/box_predictor_pb2.py
  90. +1
    -1
      traffic_analyzer/object_detection/protos/calibration_pb2.py
  91. +1
    -1
      traffic_analyzer/object_detection/protos/eval_pb2.py
  92. +1
    -1
      traffic_analyzer/object_detection/protos/faster_rcnn_box_coder_pb2.py
  93. +1
    -1
      traffic_analyzer/object_detection/protos/faster_rcnn_pb2.py
  94. +1
    -1
      traffic_analyzer/object_detection/protos/graph_rewriter_pb2.py
  95. +1
    -1
      traffic_analyzer/object_detection/protos/grid_anchor_generator_pb2.py
  96. +1
    -1
      traffic_analyzer/object_detection/protos/hyperparams_pb2.py
  97. +1
    -1
      traffic_analyzer/object_detection/protos/image_resizer_pb2.py
  98. +1
    -1
      traffic_analyzer/object_detection/protos/input_reader_pb2.py
  99. +1
    -1
      traffic_analyzer/object_detection/protos/keypoint_box_coder_pb2.py
  100. +1
    -1
      traffic_analyzer/object_detection/protos/losses_pb2.py

+ 4
- 4
master_app/nbactions.xml View File

@ -10,9 +10,9 @@
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath ${packageClassName} ips.json</exec.args>
<exec.args>-classpath %classpath me.yigitcolakoglu.master_app.Main ips.json</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
<exec.workingdir>/home/tedankara/Downloads/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
</properties>
</action>
<action>
@ -28,7 +28,7 @@
<exec.args>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ${packageClassName} ips.json</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
<exec.workingdir>/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
<exec.workingdir>/home/tedankara/Downloads/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
</properties>
</action>
<action>
@ -43,7 +43,7 @@
<properties>
<exec.args>-classpath %classpath ${packageClassName} ips.json</exec.args>
<exec.executable>java</exec.executable>
<exec.workingdir>/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
<exec.workingdir>/home/tedankara/Downloads/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app</exec.workingdir>
</properties>
</action>
</actions>

+ 5
- 0
master_app/pom.xml View File

@ -16,6 +16,11 @@
<artifactId>sshj</artifactId>
<version>0.27.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>


+ 588
- 340
master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.form
File diff suppressed because it is too large
View File


+ 761
- 478
master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
File diff suppressed because it is too large
View File


BIN
master_app/src/main/java/me/yigitcolakoglu/master_app/thermometer.png View File

Before After
Width: 128  |  Height: 128  |  Size: 3.1 KiB

BIN
master_app/target/classes/me/yigitcolakoglu/master_app/Main.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$1.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$2.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$3.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$4.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$5.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$6.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$7.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$8.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm$9.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/cameraForm.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$1.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$2.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$3.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$4.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$5.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$6.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$7.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$8.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm$9.class View File


BIN
master_app/target/classes/me/yigitcolakoglu/master_app/managementForm.class View File


+ 3
- 3
master_app/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst View File

@ -1,3 +1,3 @@
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/managementForm.java
/home/yigit/projects/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/managementForm.java
/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/cameraForm.java
/home/efeaydin/Masaüstü/MyCity/master_app/src/main/java/me/yigitcolakoglu/master_app/Main.java

+ 5
- 0
server_side/.idea/codeStyles/codeStyleConfig.xml View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

+ 4
- 0
server_side/.idea/encodings.xml View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>

+ 6
- 0
server_side/.idea/misc.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" project-jdk-name="10" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>

+ 9
- 0
server_side/.idea/modules.xml View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/server_side.iml" filepath="$PROJECT_DIR$/server_side.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/smartcity/server_side.smartcity.iml" filepath="$PROJECT_DIR$/.idea/modules/smartcity/server_side.smartcity.iml" />
</modules>
</component>
</project>

+ 6
- 0
server_side/.idea/vcs.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

+ 25
- 7
server_side/api/ai_services.py View File

@ -9,9 +9,10 @@ from PIL import Image
import base64
import io
import json
import re
import tensorflow as tf
import sys
import sys,getpass
import numpy as np
from flask import Flask, send_from_directory
from flask_restful import Api
@ -30,7 +31,7 @@ PATH_TO_FROZEN_DAMAGE_GRAPH = 'modules/trainedModels/ssd_mobilenet_RoadDamageDe
linux_def = {"detection_boxes":[(106, 188, 480, 452)],"detection_scores":[0.99],"detection_classes":[1]}
detection_graph_coco = None
detection_graph_damage = None
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
detection_graph_coco = tf.Graph()
detection_graph_damage = tf.Graph()
with detection_graph_coco.as_default():
@ -51,11 +52,24 @@ def load_image_into_numpy_array(image):
return np.array(image.getdata()).reshape(
(im_height, im_width, 3)).astype(np.uint8)
def decode_base64(data, altchars=b'+/'):
"""Decode base64, padding being optional.
:param data: Base64 data as an ASCII byte string
:returns: The decoded byte string.
"""
data = re.sub(rb'[^a-zA-Z0-9%s]+' % altchars, b'', bytes(data,"utf-8")) # normalize
missing_padding = len(data) % 4
if missing_padding:
data += b'='* (4 - missing_padding)
return base64.b64decode(data, altchars)
def run_inference_for_single_image(image, graph,type):
global switches
global sess_coco
global sess_damage
if not sys.platform == "win32":
if not getpass.getuser() == "tedankara":
return linux_def
with graph.as_default():
if(switches[type]):
@ -117,7 +131,7 @@ def run_inference_for_single_image(image, graph,type):
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image})
output_dict = {'detection_classes': np.squeeze(classes).astype(np.int32), 'detection_scores': np.squeeze(scores)}
output_dict = {'detection_classes': np.squeeze(classes).astype(np.int32), 'detection_scores': np.squeeze(scores),'detection_boxes': np.squeeze(boxes)}
return output_dict
@ -125,7 +139,8 @@ def run_inference_for_single_image(image, graph,type):
class Process(Resource):
def post(self):
base64_img = request.form['img']
image = Image.open(io.BytesIO(base64.b64decode(base64_img)))
image = Image.open(io.BytesIO(decode_base64(base64_img)))
type = request.form["type"]
image_np = load_image_into_numpy_array(image)
image_np_expanded = np.expand_dims(image_np, axis=0)
@ -133,9 +148,12 @@ class Process(Resource):
output_dict = run_inference_for_single_image(image_np_expanded, detection_graph_coco,type)
elif type == "damage":
output_dict = run_inference_for_single_image(image_np_expanded, detection_graph_damage,type)
if getpass.getuser() == "tedankara":
output_dict["detection_boxes"] = output_dict["detection_boxes"].tolist()
output_dict["detection_scores"] = output_dict["detection_scores"].tolist()
output_dict["detection_classes"] = output_dict["detection_classes"].tolist()
return json.dumps(output_dict,cls=NumpyEncoder)
return output_dict
class NumpyEncoder(json.JSONEncoder):


+ 1
- 2
server_side/api/app.py View File

@ -2,9 +2,8 @@ from flask import Flask, send_from_directory
from flask_restful import Api
from flask_cors import CORS, cross_origin
from modules import user_info, voting_system, rating_system, denunciation, navigation, bus_stops, announcements, complaint, car_crash,smart_park
from modules import user_info, voting_system, rating_system, denunciation, announcements, complaint, car_crash, smart_park,navigation,bus_stops
from modules import utility
from modules import user_set
app = Flask(__name__)
api = Api(app)


+ 2
- 2
server_side/api/modules/SpotSelector.py View File

@ -4,9 +4,9 @@ import json
rects = []
cam = cv2.VideoCapture(2)
cam = cv2.VideoCapture(5)
ret,im = cam.read()
cam.release()
#im = cv2.imread("lot.jpg")
if __name__ == '__main__' :
while(True):


BIN
server_side/api/modules/c.jpeg View File

Before After
Width: 480  |  Height: 640  |  Size: 42 KiB Width: 960  |  Height: 1280  |  Size: 118 KiB

+ 38
- 38
server_side/api/modules/car_crash.py View File

@ -8,7 +8,7 @@ import cv2
import base64
import json
import sys
import sys,getpass
import os
import io
import itertools
@ -28,7 +28,7 @@ import numpy as np
MIN_SCORE_THRESH = 0.6
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
sys.path.insert(0, r'C:\Users\Tednokent01\Downloads\MyCity\traffic_analyzer')
PATH_TO_LABELS = os.path.join('object_detection/data', 'mscoco_label_map.pbtxt')
@ -75,10 +75,10 @@ def find_name(image):
return None
def rotate_img(img, angle):
if angle == 90:
return np.rot90(img)
elif angle == 270:
return np.rot90(np.rot90(np.rot90(img)))
if angle == 90:
return np.rot90(img)
elif angle == 270:
return np.rot90(np.rot90(np.rot90(img)))
def process_img(img_base64):
url = 'https://{}:5001/ai'.format(AI_IP) # Set destination URL here
@ -150,23 +150,23 @@ def process_img(img_base64):
pass
(height_person,width_person) = person.shape[:2]
if name is None:
rotated = rotate_img(person, 270)
face_locs = face_recognition.face_locations(rotated)[0]
name = find_name(rotated)
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top + height_person - right_face,left+bottom_face,top + height_person - left_face,left+top_face)
else:
(top_face, right_face, bottom_face, left_face) = face_locs
person = cv2.rectangle(person, (width_person - bottom_face, left_face), (width_person - top_face, right_face), (0, 255, 0), 3)
face_locs_processed = (top + left_face,left + width_person - top_face,top + right_face,left + width_person - bottom_face)
people[index] = [0, face_locs_processed, name]
else:
face_locs = face_recognition.face_locations(person)[0]
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top+face_locs[0],left+face_locs[1],top+face_locs[2],left+face_locs[3])
name = find_name(person)
people[index] = [1, face_locs_processed, name]
if name is None:
rotated = rotate_img(person, 270)
face_locs = face_recognition.face_locations(rotated)[0]
name = find_name(rotated)
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top + height_person - right_face,left+bottom_face,top + height_person - left_face,left+top_face)
else:
(top_face, right_face, bottom_face, left_face) = face_locs
person = cv2.rectangle(person, (width_person - bottom_face, left_face), (width_person - top_face, right_face), (0, 255, 0), 3)
face_locs_processed = (top + left_face,left + width_person - top_face,top + right_face,left + width_person - bottom_face)
people[index] = [0, face_locs_processed, name]
else:
face_locs = face_recognition.face_locations(person)[0]
(top_face, right_face, bottom_face, left_face) = face_locs
face_locs_processed = (top+face_locs[0],left+face_locs[1],top+face_locs[2],left+face_locs[3])
name = find_name(person)
people[index] = [1, face_locs_processed, name]
@ -188,21 +188,21 @@ class Crash(Resource):
id = request.form['id']
lat, long = request.form['lat'], request.form['long']
image, car_count, injured,out,people = process_img(base64_img)
(top, right, bottom, left) = people[0][1]
top = int(top)
right = int(right)
left = int(left)
bottom = int(bottom)
img = load_image_into_numpy_array(Image.open(io.BytesIO(base64.b64decode(base64_img))))
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),3)
cv2.imshow('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(people)
priority = car_count + injured
if priority > 10:
priority = 10
image, car_count, injured,out,people = process_img(base64_img)
(top, right, bottom, left) = people[0][1]
top = int(top)
right = int(right)
left = int(left)
bottom = int(bottom)
img = load_image_into_numpy_array(Image.open(io.BytesIO(base64.b64decode(base64_img))))
cv2.rectangle(img,(left,top),(right,bottom),(0,255,0),3)
cv2.imshow('test.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
print(people)
priority = car_count + injured
if priority > 10:
priority = 10
crash = {
'img': image,


+ 6
- 6
server_side/api/modules/complaint.py View File

@ -5,7 +5,7 @@ import json
import io
import base64
from PIL import Image
import sys
import sys,getpass
import datetime
import cv2
import ssl
@ -13,7 +13,7 @@ from urllib.parse import urlencode
from urllib.request import Request, urlopen
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
import tensorflow as tf
import numpy as np
import pickle
@ -42,7 +42,7 @@ score_dict = {
with open("modules/databases/complaints.json","r") as f:
complaints = json.load(f)
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
# Path to frozen detection graph. This is the actual model that is used for the object detection.
# List of the strings that is used to add correct label for each box.
@ -60,15 +60,15 @@ def load_image_into_numpy_array(image):
def process_img(img_base64):
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
url = 'https://127.0.0.1:5000/ai' # Set destination URL here
url = 'https://127.0.0.1:5001/ai' # Set destination URL here
post_fields = {'img': img_base64,"type":"damage"} # Set POST fields here
request = Request(url, urlencode(post_fields).encode())
img = load_image_into_numpy_array(Image.open(io.BytesIO(base64.b64decode(img_base64))))
output_dict = json.loads(json.loads(urlopen(request, context=context).read()))
output_dict = json.loads(urlopen(request, context=context).read())
print(output_dict)
vis_util.visualize_boxes_and_labels_on_image_array(
img,


+ 6
- 47
server_side/api/modules/databases/complaints.json
File diff suppressed because it is too large
View File


+ 12
- 12
server_side/api/modules/databases/locations.json View File

@ -1,23 +1,23 @@
{
"0": {
"x1": 2,
"y1": 94,
"x2": 198,
"y2": 206,
"x1": 40,
"y1": 64,
"x2": 258,
"y2": 204,
"priority": 0
},
"1": {
"x1": 190,
"y1": 88,
"x2": 400,
"y2": 196,
"x1": 262,
"y1": 96,
"x2": 386,
"y2": 206,
"priority": 1
},
"2": {
"x1": 390,
"y1": 66,
"x2": 640,
"y2": 200,
"x1": 426,
"y1": 100,
"x2": 564,
"y2": 204,
"priority": 2
}
}

+ 172268
- 270368
server_side/api/modules/databases/park_data.json
File diff suppressed because it is too large
View File


+ 298
- 149
server_side/api/modules/databases/users.json
File diff suppressed because it is too large
View File


+ 4
- 7
server_side/api/modules/smart_park.py View File

@ -93,7 +93,7 @@ def generateData(locs, img, avgs,show):
if spot in show:
plt.imshow(vals[spot], interpolation='nearest')
plt.show()
#plt.show()
return distances
@ -102,15 +102,13 @@ def im2str(im):
imdata = pickle.dumps(im)
return base64.b64encode(imdata).decode('ascii')
cam = cv2.VideoCapture(2)
plt.axis("off")
with open("modules/databases/locations.json","r") as f:
locs = json.loads(f.read())
with open("modules/databases/park_data.json","r") as f:
data = json.loads(f.read())
cam=cv2.VideoCapture(5)
if 0:
ret,im = cam.read()
data = generateAvg(locs,im,data)
@ -120,9 +118,7 @@ if 0:
class Empty(Resource):
def get(self):
ret,image = cam.read()
#image = cv2.imread("module s/lot.jpg")
image = cv2.imread("modules/lot.jpg")
backup = image.copy()
spot_data = generateData(locs,image,data,["0","1","2"])
print(spot_data)
@ -140,6 +136,7 @@ class Empty(Resource):
print(spot_data)
if best_spot == -1:
print("Sorry, no spot found :(")
return
else:
print("Empty spot found at {}".format(int(best_spot) + 1))
foo = locs[best_spot]


+ 162
- 0
server_side/api/modules/smart_park.py.save View File

@ -0,0 +1,162 @@
import cv2
import numpy as np
import json
from pysolar.solar import *
from datetime import datetime
from flask import Flask, request
from flask_restful import Resource, Api, abort
import base64
import pickle
from PIL import Image
from matplotlib import pyplot as plt
from io import BytesIO
app = Flask(__name__)
api = Api(app)
def generateAvg(locs, img, avgs):
time = datetime.strptime( "2019-04-27 17:52:00 -0300","%Y-%m-%d %H:%M:%S %z")
altitude = int(get_altitude(39.9127938,32.8073577,time))
loc_images = {}
for i in locs:
temp = locs[i]
crop_img = img[temp["y1"]:temp["y2"], temp["x1"]:temp["x2"]]
loc_images[i]=[crop_img]
vals = {}
if str(altitude) in avgs:
vals = avgs[str(altitude)]
else:
for spot in loc_images:
vals[spot] = loc_images[spot]
for spot in loc_images:
for col in range(len(vals[spot][0])):
for pix in range(len(vals[spot][0][col])):
vals[spot][0][col][pix] = [
np.uint8((int(vals[spot][0][col][pix][0]) + int(loc_images[spot][0][col][pix][0]))/2),
np.uint8((int(vals[spot][0][col][pix][1]) + int(loc_images[spot][0][col][pix][1]))/2),
np.uint8((int(vals[spot][0][col][pix][2]) + int(loc_images[spot][0][col][pix][2]))/2)]
for i in vals:
vals[i] = vals[i][0].tolist()
avgs[altitude] = vals
return avgs
def generateData(locs, img, avgs,show):
time = datetime.strptime( "2019-04-27 17:52:00 -0300","%Y-%m-%d %H:%M:%S %z")
altitude = int(get_altitude(39.9127938,32.8073577,time))
loc_images = {}
distances = {}
for i in locs:
temp = locs[i]
crop_img = img[temp["y1"]:temp["y2"], temp["x1"]:temp["x2"]]
loc_images[i]=[crop_img]
vals = {}
if str(altitude) in avgs:
for spot in avgs[str(altitude)]:
vals[spot] = np.array(avgs[str(altitude)][spot])
else:
for spot in loc_images:
vals[spot] = loc_images[spot]
for spot in loc_images:
foo = np.zeros((len(vals[spot]),len(vals[spot][0])),dtype=int)
distances[spot] = 0
for col in range(len(vals[spot])):
for pix in range(len(vals[spot][col])):
vals[spot][col][pix] = [
np.uint8(abs(int(vals[spot][col][pix][0]) - int(loc_images[spot][0][col][pix][0]))),
np.uint8(abs(int(vals[spot][col][pix][1]) - int(loc_images[spot][0][col][pix][1]))),
np.uint8(abs(int(vals[spot][col][pix][2]) - int(loc_images[spot][0][col][pix][2])))]
distances[spot] += np.sum(vals[spot][col][pix])
foo[col][pix] = np.max(vals[spot][col][pix])
distances[spot] = int(distances[spot]/vals[spot].size)
vals[spot] = foo
if spot in show:
plt.imshow(vals[spot], interpolation='nearest')
#plt.show()
return distances
def im2str(im):
imdata = pickle.dumps(im)
return base64.b64encode(imdata).decode('ascii')
plt.axis("off")
with open("modules/databases/locations.json","r") as f:
locs = json.loads(f.read())
with open("modules/databases/park_data.json","r") as f:
data = json.loads(f.read())
cam = cv2.VideoCapture(5)
if 1:
ret,im = cam.read()
data = generateAvg(locs,im,data)
with open("modules/databases/park_data.json","w") as f:
f.write(json.dumps(data,indent=2))
class Empty(Resource):
def get(self):
image = cv2.imread("modules/lot.jpg")
backup = image.copy()
spot_data = generateData(locs,image,data,["0","1","2"])
print(spot_data)
best_spot = -1
for loc in spot_data:
spot_data[loc] = spot_data[loc] < 30
color = (0,255*spot_data[loc],255*(not spot_data[loc]))
cv2.rectangle(image,(locs[loc]["x1"],locs[loc]["y1"]),(locs[loc]["x2"],locs[loc]["y2"]),color,5)
if spot_data[loc]:
if best_spot == -1:
best_spot = loc
continue
if locs[loc]["priority"] < locs[best_spot]["priority"]:
best_spot = loc
print(spot_data)
if best_spot == -1:
print("Sorry, no spot found :(")
return
else:
print("Empty spot found at {}".format(int(best_spot) + 1))
foo = locs[best_spot]
crop_img = backup[foo["y1"]:foo["y2"], foo["x1"]:foo["x2"]].copy(order='C')
crop_img = Image.fromarray(crop_img,"RGB")
buffered = BytesIO()
crop_img.save(buffered, format="JPEG")
img = base64.b64encode(buffered.getvalue()).decode("ascii")
return {"lat":foo["lat"], "lng":foo["lng"], "img":img}

+ 8
- 10
server_side/api/modules/user_set.py View File

@ -1,26 +1,24 @@
import os
import sys
import sys,getpass
import json
import base64
import face_recognition
from modules import utils
import utils
with open('modules/databases/users.json') as f:
with open('databases/users.json') as f:
users = json.load(f)
for file in os.listdir("images"):
for file in os.listdir("../images"):
if file.endswith(".png") or file.endswith(".jpg"):
uid = file.split('.')[0]
if len(uid) == 32 and utils.find_by_id(users.values(), uid):
full_path = os.path.join("images", file)
full_path = os.path.join("../images", file)
image = face_recognition.load_image_file(full_path)
with open(full_path, 'rb') as f:
base64_image = base64.b64encode(f.read())
if sys.platform == "win32":
face_locations = face_recognition.face_locations(image, model="cnn")[0]
else:
if getpass.getuser() == "tedankara":
face_locations = face_recognition.face_locations(image)[0]
face_encoding = face_recognition.face_encodings(image)[0]
@ -30,7 +28,7 @@ for file in os.listdir("images"):
users[k]['face_locations'] = face_locations
users[k]['face_encoding'] = list(face_encoding)
with open('modules/databases/users.json', 'w') as f:
with open('databases/users.json', 'w') as f:
users = json.dump(users, f, indent=2)
os.remove(full_path)
os.remove(full_path)

+ 1
- 1
server_side/api/object_detection/core/preprocessor.py View File

@ -65,7 +65,7 @@ back to rank 4.
import functools
import inspect
import sys
import sys,getpass
import tensorflow as tf
from tensorflow.python.ops import control_flow_ops


+ 1
- 1
server_side/api/object_detection/object_detection_tutorial.ipynb View File

@ -39,7 +39,7 @@
"import numpy as np\n",
"import os\n",
"import six.moves.urllib as urllib\n",
"import sys\n",
"import sys,getpass\n",
"import tarfile\n",
"import tensorflow as tf\n",
"import zipfile\n",


+ 1
- 1
server_side/api/object_detection/protos/anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/argmax_matcher_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/argmax_matcher.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/bipartite_matcher_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/bipartite_matcher.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/box_predictor_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/box_predictor.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/calibration_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/calibration.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/eval_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/eval.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/faster_rcnn_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/faster_rcnn_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/faster_rcnn_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/faster_rcnn.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/flexible_grid_anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/flexible_grid_anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/graph_rewriter_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/graph_rewriter.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/grid_anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/grid_anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/hyperparams_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/hyperparams.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/image_resizer_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/image_resizer.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor


+ 1
- 1
server_side/api/object_detection/protos/input_reader_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/input_reader.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor


+ 1
- 1
server_side/api/object_detection/protos/keypoint_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/keypoint_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/losses_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/losses.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/matcher_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/matcher.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/mean_stddev_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/mean_stddev_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/model_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/model.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/multiscale_anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/multiscale_anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/optimizer_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/optimizer.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/pipeline_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/pipeline.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/post_processing_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/post_processing.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/preprocessor_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/preprocessor.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/region_similarity_calculator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/region_similarity_calculator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/square_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/square_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/ssd_anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/ssd_anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/ssd_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/ssd.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/string_int_label_map_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/string_int_label_map.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
server_side/api/object_detection/protos/train_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/train.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 30
- 26
traffic_analyzer/ambulance_detect.py View File

@ -2,17 +2,19 @@
import pickle
import threading
import sys
import sys,getpass
import cv2
import os
import numpy as np
import psutil
import subprocess
from telnetlib import Telnet
from utils import label_map_util
from utils import visualization_utils as vis_util
if sys.platform == "win32":
if getpass.getuser() == "tedankara":
import tensorflow as tf
from distutils.version import StrictVersion
@ -30,6 +32,7 @@ from PIL import Image
from io import BytesIO
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from imutils.video import VideoStream
import ssl
switch = 1
@ -41,9 +44,9 @@ sys.path.append("..")
import time
from object_detection.utils import ops as utils_ops
TELNET = False
TELNET = True
AI_IP = '10.10.26.161'
AI_IP = '127.0.0.1'
LIGHT_IP = '192.168.2.174'
context = ssl._create_unverified_context()
if TELNET:
@ -69,16 +72,18 @@ def load_image_into_numpy_array(image):
data = {"gpu_temp":"10C","gpu_load":"15%","cpu_temp":"47C","cpu_load":"15%","mem_temp":"NaN","mem_load":"17%","fan_speed":"10000RPM"}
"""
def get_temps():
global data
if not sys.platform == "win32":
temps = psutil.sensors_temperatures()
data["cpu_temp"] = str(int(temps["dell_smm"][0][1]))+"°C"
data["cpu_load"] = str(psutil.cpu_percent())+"%"
data["mem_load"] = str(dict(psutil.virtual_memory()._asdict())["percent"])+"%"
data["fan_speed"] = str(psutil.sensors_fans()["dell_smm"][0][1])+"RPM"
"""
temps = psutil.sensors_temperatures()
result = subprocess.run(['nvidia-smi', '--query-gpu=utilization.memory', '--format=csv'] , stdout=subprocess.PIPE)
data["gpu_load"] = result.stdout.decode("utf-8").split("\n")[1]
result = subprocess.run(['nvidia-smi', '--query-gpu=temperature.gpu', '--format=csv'] , stdout=subprocess.PIPE)
data["gpu_temp"] = result.stdout.decode("utf-8").split("\n")[1]+"°C"
data["cpu_temp"] = str(int(temps["coretemp"][0][1]))+"°C"
data["cpu_load"] = str(psutil.cpu_percent())+"%"
data["mem_load"] = str(dict(psutil.virtual_memory()._asdict())["percent"])+"%"
data["fan_speed"] = str(psutil.sensors_fans()["dell_smm"][0][1])+"RPM"
def run_inference_for_single_image(image):
@ -88,7 +93,7 @@ def run_inference_for_single_image(image):
post_fields = {'img': img_base64,"type":"coco"} # Set POST fields here
request = Request(url, urlencode(post_fields).encode())
data = urlopen(request, context=context).read().decode("ascii")
output_dict = json.loads(json.loads(data))
output_dict = json.loads(data)
return output_dict
kill = True
@ -122,20 +127,19 @@ socket_switch = True
thread = threading.Thread(target=listener)
thread.start()
cam = cv2.VideoCapture(1)
cam = VideoStream(src=0).start()
switch = 0
# get_temps()
get_temps()
# (left, right, top, bottom)
ambulance_coordinates = (65, 190, 0, 140)
ambulance_coordinates = (150, 400, 250, 400)
reps = -1
reps_vid = 0
while 1:
ret,image = cam.read()
image = cv2.imread('/home/efeaydin/Masaüstü/union-county-car-accident-attorneys.jpg')
image = cam.read()
reps_vid += 1
reps += 1
@ -145,6 +149,7 @@ while 1:
output_dict = run_inference_for_single_image(image_np)
height, width, channels = image_np.shape
cv2.imshow('frmmi', image[ambulance_coordinates[2]:ambulance_coordinates[3], ambulance_coordinates[0]:ambulance_coordinates[1]])
out_dict = {'detection_boxes': [], 'detection_classes': [], 'detection_scores': []}
for index,i in enumerate(output_dict['detection_classes']):
@ -192,11 +197,10 @@ while 1:
line_thickness=8,
min_score_thresh=0.3
)
cv2.imwrite('/home/efeaydin/Masaüstü/foto.jpg', image_np)
cv2.imshow('frame', image_np)
ex_c = [27, ord("q"), ord("Q")]
if cv2.waitKey(1) & 0xFF in ex_c:
break
#cv2.imshow('frame', image_np)
#ex_c = [27, ord("q"), ord("Q")]
#if cv2.waitKey(1) & 0xFF in ex_c:
# break
t2 = time.time()
print("time taken for {}".format(t2-t1))
@ -224,13 +228,13 @@ while 1:
if cut[i] < 0:
cut_send[i] = lens[i] + cut[i]
cut_send[i+1] = abs(cut[i])-abs(cut[i+1])
client_socket.sendall(json.dumps({"image_full":img,"image_sizes":{"x":65,"y":0,"width":125,"height":140},"load":data}).encode('gbk')+b"\n")
client_socket.sendall(json.dumps({"image_full":img,"image_sizes":{"x":90,"y":0,"width":140,"height":140},"load":data}).encode('gbk')+b"\n")
img_counter += 1
except:
socket_switch = True
if img_counter % 10 == 0:
# get_temps()
get_temps()
pass
except Exception as e:
@ -248,6 +252,6 @@ if not socket_switch:
cv2.destroyAllWindows()
cam.release()
cam.stop()
kill = False
thread.join()

+ 5
- 8
traffic_analyzer/ml_setup.py View File

@ -1,21 +1,18 @@
import requests
import os
import tarfile
import sys
import sys,getpass
urls = [
"https://s3-ap-northeast-1.amazonaws.com/mycityreport/trainedModels.tar.gz",
"http://download.tensorflow.org/models/object_detection/rfcn_resnet101_coco_2018_01_28.tar.gz",
"http://download.tensorflow.org/models/object_detection/faster_rcnn_resnet101_kitti_2018_01_28.tar.gz"
]
"http://download.tensorflow.org/models/object_detection/rfcn_resnet101_coco_2018_01_28.tar.gz",]
paths = ["../server_side/api/modules", ".", '../server_side/api/modules']
paths = ["../server_side/api/modules", "."]
for i in range(len(urls)):
if i == 0:
continue
url = urls[i]
print("[INFO]: Downloadinng file: {} to temp.tar.gz!".format(url.split("/")[-1]))
print("[INFO]: Downloading file: {} to temp.tar.gz!".format(url.split("/")[-1]))
with open("temp.tar.gz", 'wb') as f:
response = requests.get(url, stream=True)


+ 1
- 1
traffic_analyzer/object_detection/.ipynb_checkpoints/object_detection_tutorial-checkpoint.ipynb View File

@ -39,7 +39,7 @@
"import numpy as np\n",
"import os\n",
"import six.moves.urllib as urllib\n",
"import sys\n",
"import sys,getpass\n",
"import tarfile\n",
"import tensorflow as tf\n",
"import zipfile\n",


+ 1
- 1
traffic_analyzer/object_detection/core/preprocessor.py View File

@ -65,7 +65,7 @@ back to rank 4.
import functools
import inspect
import sys
import sys,getpass
import tensorflow as tf
from tensorflow.python.ops import control_flow_ops


+ 1
- 1
traffic_analyzer/object_detection/data/mscoco_label_map.pbtxt View File

@ -36,7 +36,7 @@ item {
item {
name: "/m/07r04"
id: 8
display_name: "ambulance"
display_name: "truck"
}
item {
name: "/m/019jd"


+ 1
- 1
traffic_analyzer/object_detection/object_detection_tutorial.ipynb View File

@ -39,7 +39,7 @@
"import numpy as np\n",
"import os\n",
"import six.moves.urllib as urllib\n",
"import sys\n",
"import sys,getpass\n",
"import tarfile\n",
"import tensorflow as tf\n",
"import zipfile\n",


+ 1
- 1
traffic_analyzer/object_detection/protos/anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/argmax_matcher_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/argmax_matcher.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/bipartite_matcher_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/bipartite_matcher.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/box_predictor_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/box_predictor.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/calibration_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/calibration.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/eval_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/eval.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/faster_rcnn_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/faster_rcnn_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/faster_rcnn_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/faster_rcnn.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/graph_rewriter_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/graph_rewriter.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/grid_anchor_generator_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/grid_anchor_generator.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/hyperparams_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/hyperparams.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/image_resizer_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/image_resizer.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor


+ 1
- 1
traffic_analyzer/object_detection/protos/input_reader_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/input_reader.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor


+ 1
- 1
traffic_analyzer/object_detection/protos/keypoint_box_coder_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/keypoint_box_coder.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


+ 1
- 1
traffic_analyzer/object_detection/protos/losses_pb2.py View File

@ -1,7 +1,7 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: object_detection/protos/losses.proto
import sys
import sys,getpass
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save