Skip to content

Commit 5e9ebf9

Browse files
authored
Merge pull request #13 from Capstone-Projects-2022-Spring/ASLIntegration
model integrated into web app
2 parents bf44f3c + 3f4a7fe commit 5e9ebf9

3,245 files changed

Lines changed: 272 additions & 746479 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/vcs.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RealTimeObjectDetection

Lines changed: 0 additions & 1 deletion
This file was deleted.
3.9 KB
Binary file not shown.
-31 Bytes
Binary file not shown.

detection.py

Lines changed: 70 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
#!/usr/bin/env python
2-
# coding: utf-8
3-
4-
# In[ ]:
5-
6-
71
import tensorflow as tf
82
from object_detection.utils import config_util
9-
from object_detection.protos import pipeline_pb2
10-
from google.protobuf import text_format
113
import os
124
from object_detection.utils import label_map_util
135
from object_detection.utils import visualization_utils as viz_utils
146
from object_detection.builders import model_builder
157
import cv2
168
import numpy as np
17-
from gtts import gTTS
189
from playsound import playsound
19-
from matplotlib import pyplot as plt
2010

21-
WORKSPACE_PATH = 'Tensorflow/workspace'
22-
SCRIPTS_PATH = 'Tensorflow/scripts'
23-
APIMODEL_PATH = 'Tensorflow/models'
11+
WORKSPACE_PATH = 'RealTimeObjectDetection/Tensorflow/workspace'
12+
SCRIPTS_PATH = 'RealTimeObjectDetection/Tensorflow/scripts'
13+
APIMODEL_PATH = 'RealTimeObjectDetection/Tensorflow/models'
2414
ANNOTATION_PATH = WORKSPACE_PATH+'/annotations'
2515
IMAGE_PATH = WORKSPACE_PATH+'/images'
2616
MODEL_PATH = WORKSPACE_PATH+'/models'
@@ -33,16 +23,20 @@
3323
config = config_util.get_configs_from_pipeline_file(CONFIG_PATH)
3424
configs = config_util.get_configs_from_pipeline_file(CONFIG_PATH)
3525
detection_model = model_builder.build(model_config=configs['model'], is_training=False)
36-
37-
phrase_buffer = []
26+
print("model built")
3827

3928
cap = cv2.VideoCapture(0)
4029
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
4130
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
42-
31+
print("camera created")
4332

4433
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
4534
ckpt.restore(os.path.join(CHECKPOINT_PATH, 'ckpt-6')).expect_partial()
35+
category_index = label_map_util.create_category_index_from_labelmap(ANNOTATION_PATH+'/label_map.pbtxt')
36+
print("checkpoints reached")
37+
38+
def getCamera():
39+
return cap
4640

4741
@tf.function
4842
def detect_fn(image):
@@ -51,71 +45,63 @@ def detect_fn(image):
5145
detections = detection_model.postprocess(prediction_dict, shapes)
5246
return detections
5347

54-
category_index = label_map_util.create_category_index_from_labelmap(ANNOTATION_PATH+'/label_map.pbtxt')
55-
56-
while True:
57-
ret, frame = cap.read()
58-
image_np = np.array(frame)
59-
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
60-
detections = detect_fn(input_tensor)
61-
num_detections = int(detections.pop('num_detections'))
62-
detections = {key: value[0, :num_detections].numpy()
63-
for key, value in detections.items()}
64-
detections['num_detections'] = num_detections
65-
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
66-
label_id_offset = 1
67-
image_np_with_detections = image_np.copy()
68-
res = [(i, j) for i, j in zip(detections['detection_classes'], detections['detection_scores'])]
69-
for i in res:
70-
if i[1] >= .50:
71-
gesture_id = int(i[0])
72-
if gesture_id == 0:
73-
playsound("hello_en.mp3")
74-
if gesture_id == 1:
75-
playsound("help_en.mp3")
76-
if gesture_id == 2:
77-
playsound("yes_en.mp3")
78-
if gesture_id == 3:
79-
playsound("no_en.mp3")
80-
if gesture_id == 4:
81-
playsound("i_en.mp3")
82-
if gesture_id == 5:
83-
playsound("i_love_you_en.mp3")
84-
if gesture_id == 6:
85-
playsound("stand_en.mp3")
86-
if gesture_id == 7:
87-
playsound("telephone_en.mp3")
88-
if gesture_id == 8:
89-
playsound("mom_en.mp3")
90-
if gesture_id == 9:
91-
playsound("thank_you_en.mp3")
92-
93-
viz_utils.visualize_boxes_and_labels_on_image_array(
94-
image_np_with_detections,
95-
detections['detection_boxes'],
96-
detections['detection_classes']+label_id_offset,
97-
detections['detection_scores'],
98-
category_index,
99-
use_normalized_coordinates=True,
100-
max_boxes_to_draw=5,
101-
min_score_thresh=.5,
102-
agnostic_mode=False)
103-
104-
cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))
105-
106-
if cv2.waitKey(1) & 0xFF == ord('q'):
107-
cap.release()
108-
break
109-
110-
111-
# In[ ]:
112-
113-
114-
115-
116-
117-
# In[ ]:
118-
119-
120-
121-
48+
def activateModel():
49+
while True:
50+
ret, frame = cap.read()
51+
frame = cv2.flip(frame, 1)
52+
53+
image_np = np.array(frame)
54+
input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
55+
detections = detect_fn(input_tensor)
56+
num_detections = int(detections.pop('num_detections'))
57+
detections = {key: value[0, :num_detections].numpy()
58+
for key, value in detections.items()}
59+
detections['num_detections'] = num_detections
60+
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
61+
label_id_offset = 1
62+
image_np_with_detections = image_np.copy()
63+
64+
res = [(i, j) for i, j in zip(detections['detection_classes'], detections['detection_scores'])]
65+
for i in res:
66+
if i[1] >= .50:
67+
gesture_id = int(i[0])
68+
if gesture_id == 0:
69+
playsound("RealTimeObjectDetection/hello_en.mp3")
70+
if gesture_id == 1:
71+
playsound("RealTimeObjectDetection/help_en.mp3")
72+
if gesture_id == 2:
73+
playsound("RealTimeObjectDetection/yes_en.mp3")
74+
if gesture_id == 3:
75+
playsound("RealTimeObjectDetection/no_en.mp3")
76+
if gesture_id == 4:
77+
playsound("RealTimeObjectDetection/i_en.mp3")
78+
if gesture_id == 5:
79+
playsound("RealTimeObjectDetection/i_love_you_en.mp3")
80+
if gesture_id == 6:
81+
playsound("RealTimeObjectDetection/stand_en.mp3")
82+
if gesture_id == 7:
83+
playsound("RealTimeObjectDetection/telephone_en.mp3")
84+
if gesture_id == 8:
85+
playsound("RealTimeObjectDetection/mom_en.mp3")
86+
if gesture_id == 9:
87+
playsound("RealTimeObjectDetection/thank_you_en.mp3")
88+
89+
viz_utils.visualize_boxes_and_labels_on_image_array(
90+
image_np_with_detections,
91+
detections['detection_boxes'],
92+
detections['detection_classes']+label_id_offset,
93+
detections['detection_scores'],
94+
category_index,
95+
use_normalized_coordinates=True,
96+
max_boxes_to_draw=5,
97+
min_score_thresh=.5,
98+
agnostic_mode=False)
99+
100+
# cv2.imshow('object detection', cv2.resize(image_np_with_detections, (800, 600)))
101+
ret, buffer = cv2.imencode('.jpg', image_np_with_detections)
102+
frame = buffer.tobytes()
103+
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
104+
105+
if cv2.waitKey(1) & 0xFF == ord('q'):
106+
cap.release()
107+
break

requirements.txt

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
absl-py==1.0.0
2+
apache-beam==2.37.0
3+
argon2-cffi==21.3.0
4+
argon2-cffi-bindings==21.2.0
5+
asttokens==2.0.5
6+
astunparse==1.6.3
7+
attrs==21.4.0
8+
avro-python3==1.10.2
9+
backcall==0.2.0
10+
beautifulsoup4==4.10.0
11+
bleach==4.1.0
12+
cachetools==5.0.0
13+
certifi==2021.10.8
14+
cffi==1.15.0
15+
charset-normalizer==2.0.12
16+
click==7.1.2
17+
cloudpickle==2.0.0
18+
colorama==0.4.4
19+
contextlib2==21.6.0
20+
crcmod==1.7
21+
cryptography==36.0.0
22+
cycler==0.11.0
23+
Cython==0.29.28
24+
debugpy==1.6.0
25+
decorator==5.1.1
26+
defusedxml==0.7.1
27+
dill==0.3.1.1
28+
dm-tree==0.1.6
29+
dnspython==2.2.1
30+
docopt==0.6.2
31+
docutils==0.18.1
32+
email-validator==1.1.3
33+
entrypoints==0.4
34+
executing==0.8.3
35+
fastavro==1.4.10
36+
Flask==1.1.2
37+
Flask-SQLAlchemy==2.5.1
38+
Flask-WTF==0.14.3
39+
flatbuffers==2.0
40+
fonttools==4.31.2
41+
gast==0.5.3
42+
gin-config==0.5.0
43+
google-api-core==2.7.1
44+
google-api-python-client==2.42.0
45+
google-auth==2.6.2
46+
google-auth-httplib2==0.1.0
47+
google-auth-oauthlib==0.4.6
48+
google-pasta==0.2.0
49+
googleapis-common-protos==1.56.0
50+
greenlet==1.1.2
51+
grpcio==1.44.0
52+
gTTS==2.2.4
53+
h5py==3.6.0
54+
hdfs==2.7.0
55+
httplib2==0.19.1
56+
idna==3.3
57+
importlib-metadata==4.11.3
58+
ipykernel==6.10.0
59+
ipython==8.2.0
60+
ipython-genutils==0.2.0
61+
ipywidgets==7.7.0
62+
itsdangerous==1.1.0
63+
jedi==0.18.1
64+
Jinja2==2.11.2
65+
joblib==1.1.0
66+
jsonschema==4.4.0
67+
jupyter==1.0.0
68+
jupyter-client==7.1.2
69+
jupyter-console==6.4.3
70+
jupyter-core==4.9.2
71+
jupyterlab-pygments==0.1.2
72+
jupyterlab-widgets==1.1.0
73+
kaggle==1.5.12
74+
keras==2.8.0
75+
Keras-Preprocessing==1.1.2
76+
keyring==23.5.0
77+
kiwisolver==1.4.1
78+
libclang==13.0.0
79+
lvis==0.5.3
80+
lxml==4.8.0
81+
Markdown==3.3.6
82+
MarkupSafe==2.0.1
83+
matplotlib==3.5.1
84+
matplotlib-inline==0.1.3
85+
mistune==0.8.4
86+
nbclient==0.5.13
87+
nbconvert==6.4.5
88+
nbformat==5.2.0
89+
nest-asyncio==1.5.4
90+
nltk==3.5
91+
notebook==6.4.10
92+
numpy==1.22.3
93+
oauth2client==4.1.3
94+
oauthlib==3.2.0
95+
object-detection==0.1
96+
opencv-python==4.5.5
97+
opencv-python-headless==4.5.5.64
98+
opt-einsum==3.3.0
99+
orjson==3.6.7
100+
packaging==21.3
101+
pandas==1.4.1
102+
pandocfilters==1.5.0
103+
parso==0.8.3
104+
pickleshare==0.7.5
105+
Pillow==9.0.1
106+
pip==21.2.4
107+
pkginfo==1.8.2
108+
playsound==1.3.0
109+
portalocker==2.4.0
110+
prometheus-client==0.13.1
111+
promise==2.3
112+
prompt-toolkit==3.0.28
113+
proto-plus==1.20.3
114+
protobuf==3.19.4
115+
psutil==5.9.0
116+
pure-eval==0.2.2
117+
py-cpuinfo==8.0.0
118+
pyarrow==6.0.1
119+
pyasn1==0.4.8
120+
pyasn1-modules==0.2.8
121+
pycocotools==2.0
122+
pycparser==2.21
123+
pydot==1.4.2
124+
Pygments==2.11.2
125+
pymongo==3.12.3
126+
PyMySQL==1.0.2
127+
pyparsing==2.4.7
128+
pyrsistent==0.18.1
129+
python-dateutil==2.8.2
130+
python-slugify==6.1.1
131+
pytz==2022.1
132+
pywin32==303
133+
pywin32-ctypes==0.2.0
134+
pywinpty==2.0.5
135+
PyYAML==5.4.1
136+
pyzmq==22.3.0
137+
qtconsole==5.3.0
138+
QtPy==2.0.1
139+
readme-renderer==34.0
140+
regex==2022.3.15
141+
requests==2.27.1
142+
requests-oauthlib==1.3.1
143+
requests-toolbelt==0.9.1
144+
rfc3986==2.0.0
145+
rsa==4.8
146+
sacrebleu==2.0.0
147+
scikit-learn==1.0.2
148+
scipy==1.8.0
149+
Send2Trash==1.8.0
150+
sentencepiece==0.1.96
151+
seqeval==1.2.2
152+
setuptools==61.2.0
153+
six==1.16.0
154+
soupsieve==2.3.1
155+
SQLAlchemy==1.4.32
156+
stack-data==0.2.0
157+
tabulate==0.8.9
158+
tensorboard==2.8.0
159+
tensorboard-data-server==0.6.1
160+
tensorboard-plugin-wit==1.8.1
161+
tensorflow==2.8.0
162+
tensorflow-addons==0.16.1
163+
tensorflow-datasets==4.5.2
164+
tensorflow-hub==0.12.0
165+
tensorflow-io==0.24.0
166+
tensorflow-io-gcs-filesystem==0.24.0
167+
tensorflow-metadata==1.7.0
168+
tensorflow-model-optimization==0.7.2
169+
tensorflow-object-detection-api==0.1.1
170+
tensorflow-text==2.8.1
171+
termcolor==1.1.0
172+
terminado==0.13.3
173+
testpath==0.6.0
174+
text-unidecode==1.3
175+
tf-estimator-nightly==2.8.0.dev2021122109
176+
tf-models-official==2.8.0
177+
tf-slim==1.1.0
178+
threadpoolctl==3.1.0
179+
tornado==6.1
180+
tqdm==4.63.1
181+
traitlets==5.1.1
182+
twine==3.8.0
183+
typeguard==2.13.3
184+
typing_extensions==4.1.1
185+
uritemplate==4.1.1
186+
urllib3==1.26.9
187+
wcwidth==0.2.5
188+
webencodings==0.5.1
189+
Werkzeug==2.0.3
190+
wheel==0.37.1
191+
widgetsnbextension==3.6.0
192+
wincertstore==0.2
193+
wrapt==1.14.0
194+
WTForms==2.3.3
195+
zipp==3.7.0

0 commit comments

Comments
 (0)