Skip to content

Commit

Permalink
moar python2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-cranfill committed Sep 28, 2017
1 parent e8b7f4e commit 852149a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
23 changes: 17 additions & 6 deletions cena/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,28 @@ def recognize_faces(self, frame, list_o_faces):
pred_prob = max(pred_probs)
pred_names.append({pred_name: pred_prob})

if DEV and ANNOTATE_FRAME:
if ANNOTATE_FRAME:
pose_landmarks = self.face_pose_predictor(frame, rect)
cv2.putText(frame, '{}: {}'.format(pred_name, pred_prob), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1,
(102, 204, 102), thickness=2)
for point in pose_landmarks.parts():
x, y = point.x, point.y
cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)

end = datetime.now()
return frame, pred_names, (end - start).microseconds / 1000
else:
end = datetime.now()
return pred_names, (end - start).microseconds / 1000
end = datetime.now()
return frame, pred_names, (end - start).microseconds / 1000

# if DEV and ANNOTATE_FRAME:
# pose_landmarks = self.face_pose_predictor(frame, rect)
# cv2.putText(frame, '{}: {}'.format(pred_name, pred_prob), (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1,
# (102, 204, 102), thickness=2)
# for point in pose_landmarks.parts():
# x, y = point.x, point.y
# cv2.circle(frame, (x, y), 5, (0, 255, 0), -1)
#
# end = datetime.now()
# return frame, pred_names, (end - start).microseconds / 1000
# else:
# end = datetime.now()
# return pred_names, (end - start).microseconds / 1000

24 changes: 17 additions & 7 deletions cena/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from ast import literal_eval

ENVIRONMENT = 'dev'
# ENVIRONMENT = 'nah dude'
Expand All @@ -7,8 +8,14 @@
YOLO_MODE = True
# YOLO_MODE = False

ANNOTATE_FRAME = True
# ANNOTATE_FRAME = False
# ANNOTATE_FRAME = True
ANNOTATE_FRAME = False

CLIENT_ENV_VAR = os.getenv('FACE_CLIENT', True)
if not isinstance(CLIENT_ENV_VAR, bool):
IS_CLIENT = literal_eval(CLIENT_ENV_VAR)
else:
IS_CLIENT = CLIENT_ENV_VAR

API_SERVER_NAME = 'face-api'

Expand Down Expand Up @@ -39,9 +46,12 @@
RYAN_FILE_NAME = 'dun_dun_dun.mp3'
RYAN_SONG_PATH = os.path.join(SONGS_DIR, RYAN_FILE_NAME)

from cena.utils import get_api_server_ip_address
# SERVER_URL = 'http://localhost:5000/recognize'
# SERVER_IP = 'localhost'
SERVER_IP = get_api_server_ip_address()
if IS_CLIENT:
from cena.utils import get_api_server_ip_address
# SERVER_URL = 'http://localhost:5000/recognize'
SERVER_IP = get_api_server_ip_address()
# SERVER_URL = 'http://107.20.57.175:5000/recognize'
else:
SERVER_IP = 'localhost'

SERVER_URL = 'http://{}:5000/recognize'.format(SERVER_IP)
# SERVER_URL = 'http://107.20.57.175:5000/recognize'
4 changes: 2 additions & 2 deletions face_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from cena.utils import encode_image, decode_image, play_mp3



def listen_for_quit():
k = cv2.waitKey(1)
if k == ord('q'):
Expand Down Expand Up @@ -59,7 +58,8 @@ def process_frame(video_capture, face_recognizer=None):
# frame, people_list, time = face_recognizer.recognize_faces(frame, list_o_faces)
frame, people_list, time = get_server_response(frame, list_o_faces)
elif DEV:
people_list, time = face_recognizer.recognize_faces(frame, list_o_faces)
people_list, time = get_server_response(frame, list_o_faces)
# people_list, time = face_recognizer.recognize_faces(frame, list_o_faces)
else:
people_list, time = get_server_response(frame, list_o_faces)
# play_mp3(RYAN_SONG_PATH)
Expand Down
4 changes: 4 additions & 0 deletions feature_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def recognize():
list_o_faces = request.json['list_o_faces']

frame, people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)
# if ANNOTATE_FRAME:
# frame, people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)
# else:
# people_list, time = RECOGNIZER.recognize_faces(frame, list_o_faces)

response = {
'people_list': people_list,
Expand Down

0 comments on commit 852149a

Please sign in to comment.