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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from streamlit_webrtc import webrtc_streamer, RTCConfiguration
|
| 2 |
+
import av
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import mediapipe as mp
|
| 5 |
+
import cv2
|
| 6 |
+
import time
|
| 7 |
+
import math
|
| 8 |
+
import numpy as np
|
| 9 |
+
# import pandas as pd
|
| 10 |
+
# import tensorflow as tf
|
| 11 |
+
import variables
|
| 12 |
+
|
| 13 |
+
from download import download_file
|
| 14 |
+
from turn import get_ice_servers
|
| 15 |
+
|
| 16 |
+
# # face bounder indices
|
| 17 |
+
# FACE_OVAL=[ 10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288, 397, 365, 379, 378, 400, 377, 152, 148, 176, 149, 150, 136, 172, 58, 132, 93, 234, 127, 162, 21, 54, 103,67, 109]
|
| 18 |
+
# variables
|
| 19 |
+
frame_counter = 0
|
| 20 |
+
CEF_COUNTER = 0
|
| 21 |
+
TOTAL_BLINKS = 0
|
| 22 |
+
# constants
|
| 23 |
+
CLOSED_EYES_FRAME = 3
|
| 24 |
+
FONTS = cv2.FONT_HERSHEY_COMPLEX
|
| 25 |
+
|
| 26 |
+
# face bounder indices
|
| 27 |
+
FACE_OVAL = [10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288, 397, 365, 379, 378,
|
| 28 |
+
400, 377, 152, 148, 176, 149, 150, 136, 172, 58, 132, 93, 234, 127, 162, 21, 54, 103, 67, 109]
|
| 29 |
+
|
| 30 |
+
# lips indices for Landmarks
|
| 31 |
+
LIPS = [61, 146, 91, 181, 84, 17, 314, 405, 321, 375, 291, 308, 324, 318, 402, 317, 14, 87, 178,
|
| 32 |
+
88, 95, 185, 40, 39, 37, 0, 267, 269, 270, 409, 415, 310, 311, 312, 13, 82, 81, 42, 183, 78]
|
| 33 |
+
LOWER_LIPS = [61, 146, 91, 181, 84, 17, 314, 405, 321,
|
| 34 |
+
375, 291, 308, 324, 318, 402, 317, 14, 87, 178, 88, 95]
|
| 35 |
+
UPPER_LIPS = [185, 40, 39, 37, 0, 267, 269, 270,
|
| 36 |
+
409, 415, 310, 311, 312, 13, 82, 81, 42, 183, 78]
|
| 37 |
+
|
| 38 |
+
# Left eyes indices
|
| 39 |
+
LEFT_EYE = [362, 382, 381, 380, 374, 373, 390,
|
| 40 |
+
249, 263, 466, 388, 387, 386, 385, 384, 398]
|
| 41 |
+
LEFT_EYEBROW = [336, 296, 334, 293, 300, 276, 283, 282, 295, 285]
|
| 42 |
+
|
| 43 |
+
# right eyes indices
|
| 44 |
+
RIGHT_EYE = [33, 7, 163, 144, 145, 153, 154,
|
| 45 |
+
155, 133, 173, 157, 158, 159, 160, 161, 246]
|
| 46 |
+
RIGHT_EYEBROW = [70, 63, 105, 66, 107, 55, 65, 52, 53, 46]
|
| 47 |
+
|
| 48 |
+
UPPER_EYE_LEFT = [246, 161, 160, 159, 158, 157, 173, 133]
|
| 49 |
+
UPPER_EYE_RIGHT = [7, 33, 161, 160, 159, 158, 157, 173]
|
| 50 |
+
|
| 51 |
+
counter = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
| 52 |
+
|
| 53 |
+
full_counter = 0
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def landmarksDetection(img, results, draw=False):
|
| 57 |
+
img_height, img_width = img.shape[:2]
|
| 58 |
+
# list[(x,y), (x,y)....]
|
| 59 |
+
mesh_coord = [(int(point.x * img_width), int(point.y * img_height))
|
| 60 |
+
for point in results.face_landmarks.landmark]
|
| 61 |
+
if draw:
|
| 62 |
+
[cv2.circle(img, p, 2, (0, 0, 255), -1) for p in mesh_coord]
|
| 63 |
+
|
| 64 |
+
# returning the list of tuples for each landmarks
|
| 65 |
+
return mesh_coord
|
| 66 |
+
|
| 67 |
+
# Euclaidean distance
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def euclaideanDistance(point, point1):
|
| 71 |
+
x, y = point
|
| 72 |
+
x1, y1 = point1
|
| 73 |
+
distance = math.sqrt((x1 - x)**2 + (y1 - y)**2)
|
| 74 |
+
return distance
|
| 75 |
+
|
| 76 |
+
# Blinking Ratio
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def blinkRatio(img, landmarks, right_indices, left_indices):
|
| 80 |
+
|
| 81 |
+
rh_right = landmarks[right_indices[0]]
|
| 82 |
+
rh_left = landmarks[right_indices[8]]
|
| 83 |
+
# vertical line
|
| 84 |
+
rv_top = landmarks[right_indices[12]]
|
| 85 |
+
rv_bottom = landmarks[right_indices[4]]
|
| 86 |
+
|
| 87 |
+
lh_right = landmarks[left_indices[0]]
|
| 88 |
+
lh_left = landmarks[left_indices[8]]
|
| 89 |
+
|
| 90 |
+
# vertical line
|
| 91 |
+
lv_top = landmarks[left_indices[12]]
|
| 92 |
+
lv_bottom = landmarks[left_indices[4]]
|
| 93 |
+
|
| 94 |
+
rhDistance = euclaideanDistance(rh_right, rh_left)
|
| 95 |
+
rvDistance = euclaideanDistance(rv_top, rv_bottom)
|
| 96 |
+
|
| 97 |
+
lvDistance = euclaideanDistance(lv_top, lv_bottom)
|
| 98 |
+
lhDistance = euclaideanDistance(lh_right, lh_left)
|
| 99 |
+
|
| 100 |
+
reRatio = rhDistance/rvDistance
|
| 101 |
+
leRatio = lhDistance/lvDistance
|
| 102 |
+
|
| 103 |
+
ratio = (reRatio+leRatio)/2
|
| 104 |
+
return ratio
|
| 105 |
+
|
| 106 |
+
# Eyes Extrctor function,
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def eyesExtractor(img, right_eye_coords, left_eye_coords):
|
| 110 |
+
# converting color image to scale image
|
| 111 |
+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 112 |
+
|
| 113 |
+
# getting the dimension of image
|
| 114 |
+
dim = gray.shape
|
| 115 |
+
|
| 116 |
+
# creating mask from gray scale dim
|
| 117 |
+
mask = np.zeros(dim, dtype=np.uint8)
|
| 118 |
+
|
| 119 |
+
# drawing Eyes Shape on mask with white color
|
| 120 |
+
cv2.fillPoly(mask, [np.array(right_eye_coords, dtype=np.int32)], 255)
|
| 121 |
+
cv2.fillPoly(mask, [np.array(left_eye_coords, dtype=np.int32)], 255)
|
| 122 |
+
|
| 123 |
+
# showing the mask
|
| 124 |
+
# cv.imshow('mask', mask)
|
| 125 |
+
|
| 126 |
+
# draw eyes image on mask, where white shape is
|
| 127 |
+
eyes = cv2.bitwise_and(gray, gray, mask=mask)
|
| 128 |
+
# change black color to gray other than eys
|
| 129 |
+
# cv.imshow('eyes draw', eyes)
|
| 130 |
+
eyes[mask == 0] = 155
|
| 131 |
+
|
| 132 |
+
# getting minium and maximum x and y for right and left eyes
|
| 133 |
+
# For Right Eye
|
| 134 |
+
r_max_x = (max(right_eye_coords, key=lambda item: item[0]))[0]
|
| 135 |
+
r_min_x = (min(right_eye_coords, key=lambda item: item[0]))[0]
|
| 136 |
+
r_max_y = (max(right_eye_coords, key=lambda item: item[1]))[1]
|
| 137 |
+
r_min_y = (min(right_eye_coords, key=lambda item: item[1]))[1]
|
| 138 |
+
|
| 139 |
+
# For LEFT Eye
|
| 140 |
+
l_max_x = (max(left_eye_coords, key=lambda item: item[0]))[0]
|
| 141 |
+
l_min_x = (min(left_eye_coords, key=lambda item: item[0]))[0]
|
| 142 |
+
l_max_y = (max(left_eye_coords, key=lambda item: item[1]))[1]
|
| 143 |
+
l_min_y = (min(left_eye_coords, key=lambda item: item[1]))[1]
|
| 144 |
+
|
| 145 |
+
# croping the eyes from mask
|
| 146 |
+
cropped_right = eyes[r_min_y: r_max_y, r_min_x: r_max_x]
|
| 147 |
+
cropped_left = eyes[l_min_y: l_max_y, l_min_x: l_max_x]
|
| 148 |
+
|
| 149 |
+
# returning the cropped eyes
|
| 150 |
+
return cropped_right, cropped_left
|
| 151 |
+
|
| 152 |
+
# Eyes Postion Estimator
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def positionEstimator(cropped_eye):
|
| 156 |
+
# getting height and width of eye
|
| 157 |
+
h, w = cropped_eye.shape
|
| 158 |
+
|
| 159 |
+
# remove the noise from images
|
| 160 |
+
gaussain_blur = cv2.GaussianBlur(cropped_eye, (9, 9), 0)
|
| 161 |
+
median_blur = cv2.medianBlur(gaussain_blur, 3)
|
| 162 |
+
|
| 163 |
+
# applying thrsholding to convert binary_image
|
| 164 |
+
ret, threshed_eye = cv2.threshold(median_blur, 130, 255, cv2.THRESH_BINARY)
|
| 165 |
+
|
| 166 |
+
# create fixd part for eye with
|
| 167 |
+
piece = int(w/3)
|
| 168 |
+
|
| 169 |
+
# slicing the eyes into three parts
|
| 170 |
+
right_piece = threshed_eye[0:h, 0:piece]
|
| 171 |
+
center_piece = threshed_eye[0:h, piece: piece+piece]
|
| 172 |
+
left_piece = threshed_eye[0:h, piece + piece:w]
|
| 173 |
+
|
| 174 |
+
# calling pixel counter function
|
| 175 |
+
eye_position = pixelCounter(right_piece, center_piece, left_piece)
|
| 176 |
+
|
| 177 |
+
return eye_position
|
| 178 |
+
|
| 179 |
+
# creating pixel counter function
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def pixelCounter(first_piece, second_piece, third_piece):
|
| 183 |
+
# counting black pixel in each part
|
| 184 |
+
right_part = np.sum(first_piece == 0)
|
| 185 |
+
center_part = np.sum(second_piece == 0)
|
| 186 |
+
left_part = np.sum(third_piece == 0)
|
| 187 |
+
# creating list of these values
|
| 188 |
+
eye_parts = [right_part, center_part, left_part]
|
| 189 |
+
|
| 190 |
+
# getting the index of max values in the list
|
| 191 |
+
max_index = eye_parts.index(max(eye_parts))
|
| 192 |
+
pos_eye = ''
|
| 193 |
+
if max_index == 0:
|
| 194 |
+
pos_eye = "RIGHT"
|
| 195 |
+
elif max_index == 1:
|
| 196 |
+
pos_eye = 'CENTER'
|
| 197 |
+
elif max_index == 2:
|
| 198 |
+
pos_eye = 'LEFT'
|
| 199 |
+
else:
|
| 200 |
+
pos_eye = "Closed"
|
| 201 |
+
return pos_eye
|
| 202 |
+
|
| 203 |
+
# Function to check if eyes are looking up
|
| 204 |
+
|
| 205 |
+
# Load your TFLite model
|
| 206 |
+
# interpreter = tf.lite.Interpreter(model_path='model_second.tflite')
|
| 207 |
+
# interpreter.allocate_tensors()
|
| 208 |
+
|
| 209 |
+
# # Get input and output details
|
| 210 |
+
# input_details = interpreter.get_input_details()
|
| 211 |
+
# output_details = interpreter.get_output_details()
|
| 212 |
+
|
| 213 |
+
# # Assuming your input tensor name is 'flatten_input'
|
| 214 |
+
# input_tensor_index = input_details[0]['index']
|
| 215 |
+
# output_tensor_index = output_details[0]['index']
|
| 216 |
+
|
| 217 |
+
# # You can use the following function for inference
|
| 218 |
+
# def predict_label(input_data):
|
| 219 |
+
# # Set the input tensor
|
| 220 |
+
# interpreter.set_tensor(input_tensor_index, input_data)
|
| 221 |
+
|
| 222 |
+
# # Run inference
|
| 223 |
+
# interpreter.invoke()
|
| 224 |
+
|
| 225 |
+
# # Get the output tensor
|
| 226 |
+
# output_data = interpreter.get_tensor(output_tensor_index)
|
| 227 |
+
|
| 228 |
+
# # Convert the output to class labels
|
| 229 |
+
# predicted_label = np.argmax(output_data, axis=1)
|
| 230 |
+
|
| 231 |
+
# # Decode the predicted label
|
| 232 |
+
# # predicted_class = label_encoder.classes_[predicted_label][0]
|
| 233 |
+
|
| 234 |
+
# return predicted_label
|
| 235 |
+
|
| 236 |
+
# class Queue:
|
| 237 |
+
# def __init__(self, max_size=80):
|
| 238 |
+
# self.max_size = max_size
|
| 239 |
+
# self.queue = []
|
| 240 |
+
|
| 241 |
+
# def enqueue(self, value):
|
| 242 |
+
# if len(self.queue) < self.max_size:
|
| 243 |
+
# self.queue.append(value)
|
| 244 |
+
# else:
|
| 245 |
+
# self.queue.pop(0)
|
| 246 |
+
# self.queue.append(value)
|
| 247 |
+
|
| 248 |
+
# def dequeue(self):
|
| 249 |
+
# if self.queue:
|
| 250 |
+
# self.queue.pop(0)
|
| 251 |
+
# else:
|
| 252 |
+
# print("Queue is empty. Dequeue operation failed.")
|
| 253 |
+
|
| 254 |
+
# def get_all_values(self):
|
| 255 |
+
# return self.queue
|
| 256 |
+
|
| 257 |
+
# frames_list = Queue(max_size=80)
|
| 258 |
+
|
| 259 |
+
def is_eyes_looking_up(landmarks, upper_eye_indices):
|
| 260 |
+
upper_eye_points = [landmarks[idx] for idx in upper_eye_indices]
|
| 261 |
+
average_y = sum(point[1]
|
| 262 |
+
for point in upper_eye_points) / len(upper_eye_points)
|
| 263 |
+
return average_y < landmarks[LEFT_EYE[0]][1] and average_y < landmarks[RIGHT_EYE[0]][1]
|
| 264 |
+
|
| 265 |
+
def gen_report():
|
| 266 |
+
global nerv_bool
|
| 267 |
+
global pos_val
|
| 268 |
+
global report_generated
|
| 269 |
+
global report_data
|
| 270 |
+
global nerv_val
|
| 271 |
+
report_generated = True
|
| 272 |
+
# print("Arsooo")
|
| 273 |
+
# print("Session: ", st.session_state.pos_val)
|
| 274 |
+
if(nerv_bool):
|
| 275 |
+
pos_val += f"Person was Nervous and Blinked {nerv_val} times in 1 Minute"
|
| 276 |
+
report_data = pos_val
|
| 277 |
+
|
| 278 |
+
report_generated = False
|
| 279 |
+
nerv_bool = False
|
| 280 |
+
nerv_val = 0
|
| 281 |
+
pos_val = ""
|
| 282 |
+
|
| 283 |
+
our_time = 0
|
| 284 |
+
|
| 285 |
+
start_time = time.time()
|
| 286 |
+
|
| 287 |
+
nervous = False
|
| 288 |
+
|
| 289 |
+
mp_drawing = mp.solutions.drawing_utils # Drawing helpers
|
| 290 |
+
mp_holistic = mp.solutions.holistic # Mediapipe Solutions
|
| 291 |
+
|
| 292 |
+
holistic = mp_holistic.Holistic(
|
| 293 |
+
min_detection_confidence=0.5, min_tracking_confidence=0.5)
|
| 294 |
+
|
| 295 |
+
class VideoProcessor:
|
| 296 |
+
def __init__(self):
|
| 297 |
+
self.reporter = False
|
| 298 |
+
|
| 299 |
+
def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
|
| 300 |
+
global full_counter
|
| 301 |
+
global TOTAL_BLINKS
|
| 302 |
+
global CEF_COUNTER
|
| 303 |
+
global CLOSED_EYES_FRAME
|
| 304 |
+
global our_time
|
| 305 |
+
global start_time
|
| 306 |
+
global nervous
|
| 307 |
+
global nerv_bool
|
| 308 |
+
global pos_val
|
| 309 |
+
global report_generated
|
| 310 |
+
global report_data
|
| 311 |
+
global nerv_val
|
| 312 |
+
# global frames_list
|
| 313 |
+
|
| 314 |
+
frame = frame.to_ndarray(format="bgr24")
|
| 315 |
+
|
| 316 |
+
full_counter += 1
|
| 317 |
+
|
| 318 |
+
# Recolor Feed
|
| 319 |
+
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 320 |
+
image.flags.writeable = False
|
| 321 |
+
|
| 322 |
+
# Make Detections
|
| 323 |
+
results = holistic.process(image)
|
| 324 |
+
|
| 325 |
+
# Recolor image back to BGR for rendering
|
| 326 |
+
image.flags.writeable = True
|
| 327 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 328 |
+
|
| 329 |
+
img_h, img_w, img_c = image.shape
|
| 330 |
+
face_3d = []
|
| 331 |
+
face_2d = []
|
| 332 |
+
|
| 333 |
+
# 1. Draw face landmarks
|
| 334 |
+
mp_drawing.draw_landmarks(image, results.face_landmarks, mp_holistic.FACEMESH_CONTOURS,
|
| 335 |
+
mp_drawing.DrawingSpec(
|
| 336 |
+
color=(80, 110, 10), thickness=1, circle_radius=1),
|
| 337 |
+
mp_drawing.DrawingSpec(
|
| 338 |
+
color=(80, 256, 121), thickness=1, circle_radius=1)
|
| 339 |
+
)
|
| 340 |
+
|
| 341 |
+
# 2. Right hand
|
| 342 |
+
mp_drawing.draw_landmarks(image, results.right_hand_landmarks, mp_holistic.HAND_CONNECTIONS,
|
| 343 |
+
mp_drawing.DrawingSpec(
|
| 344 |
+
color=(80, 22, 10), thickness=2, circle_radius=4),
|
| 345 |
+
mp_drawing.DrawingSpec(
|
| 346 |
+
color=(80, 44, 121), thickness=2, circle_radius=2)
|
| 347 |
+
)
|
| 348 |
+
|
| 349 |
+
# 3. Left Hand
|
| 350 |
+
mp_drawing.draw_landmarks(image, results.left_hand_landmarks, mp_holistic.HAND_CONNECTIONS,
|
| 351 |
+
mp_drawing.DrawingSpec(
|
| 352 |
+
color=(121, 22, 76), thickness=2, circle_radius=4),
|
| 353 |
+
mp_drawing.DrawingSpec(
|
| 354 |
+
color=(121, 44, 250), thickness=2, circle_radius=2)
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
# 4. Pose Detections
|
| 358 |
+
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_holistic.POSE_CONNECTIONS,
|
| 359 |
+
mp_drawing.DrawingSpec(
|
| 360 |
+
color=(245, 117, 66), thickness=2, circle_radius=4),
|
| 361 |
+
mp_drawing.DrawingSpec(
|
| 362 |
+
color=(245, 66, 230), thickness=2, circle_radius=2)
|
| 363 |
+
)
|
| 364 |
+
|
| 365 |
+
if (results.right_hand_landmarks and results.left_hand_landmarks and results.face_landmarks and results.pose_landmarks):
|
| 366 |
+
right_hand_landmarks = results.right_hand_landmarks.landmark
|
| 367 |
+
left_hand_landmarks = results.left_hand_landmarks.landmark
|
| 368 |
+
pose_landmarks = results.pose_landmarks.landmark
|
| 369 |
+
face_landmarks = results.face_landmarks.landmark
|
| 370 |
+
|
| 371 |
+
mesh_coords = landmarksDetection(frame, results, False)
|
| 372 |
+
|
| 373 |
+
bottom_lip = face_landmarks[18]
|
| 374 |
+
nose_center = face_landmarks[5]
|
| 375 |
+
|
| 376 |
+
right_wrist = pose_landmarks[16]
|
| 377 |
+
|
| 378 |
+
lips_left = face_landmarks[287]
|
| 379 |
+
lips_right = face_landmarks[57]
|
| 380 |
+
|
| 381 |
+
right_ear_top = face_landmarks[21]
|
| 382 |
+
right_ear_bottom = face_landmarks[215]
|
| 383 |
+
|
| 384 |
+
left_ear_top = face_landmarks[389]
|
| 385 |
+
left_ear_bottom = face_landmarks[361]
|
| 386 |
+
|
| 387 |
+
forehead = face_landmarks[151]
|
| 388 |
+
|
| 389 |
+
bottom_lip_y = int(bottom_lip.y * frame.shape[0])
|
| 390 |
+
upper_nose_y = int(nose_center.y * frame.shape[0])
|
| 391 |
+
|
| 392 |
+
lips_left_x = int(lips_left.x * frame.shape[1])
|
| 393 |
+
lips_right_x = int(lips_right.x * frame.shape[1])
|
| 394 |
+
lips_left_y = int(lips_left.y * frame.shape[0])
|
| 395 |
+
lips_right_y = int(lips_right.y * frame.shape[0])
|
| 396 |
+
|
| 397 |
+
right_ear_top_y = int(right_ear_top.y * frame.shape[0])
|
| 398 |
+
right_ear_top_x = int(right_ear_top.x * frame.shape[1])
|
| 399 |
+
right_ear_bottom_x = int(right_ear_bottom.x * frame.shape[1])
|
| 400 |
+
right_ear_bottom_y = int(right_ear_bottom.y * frame.shape[0])
|
| 401 |
+
|
| 402 |
+
left_ear_top_y = int(left_ear_top.y * frame.shape[0])
|
| 403 |
+
left_ear_top_x = int(left_ear_top.x * frame.shape[1])
|
| 404 |
+
left_ear_bottom_y = int(left_ear_bottom.y * frame.shape[0])
|
| 405 |
+
left_ear_bottom_x = int(left_ear_bottom.x * frame.shape[1])
|
| 406 |
+
|
| 407 |
+
right_hand_tip_x = int(
|
| 408 |
+
right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].x * frame.shape[1])
|
| 409 |
+
left_hand_tip_x = int(
|
| 410 |
+
left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].x * frame.shape[1])
|
| 411 |
+
right_hand_tip_y = int(
|
| 412 |
+
right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].y * frame.shape[0])
|
| 413 |
+
left_hand_tip_y = int(
|
| 414 |
+
left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].y * frame.shape[0])
|
| 415 |
+
right_hand_dip_y = int(
|
| 416 |
+
right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_DIP].y * frame.shape[0])
|
| 417 |
+
left_hand_dip_y = int(
|
| 418 |
+
left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_DIP].y * frame.shape[0])
|
| 419 |
+
right_hand_thumb = int(
|
| 420 |
+
right_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP].y * frame.shape[0])
|
| 421 |
+
left_hand_thumb = int(
|
| 422 |
+
left_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP].y * frame.shape[0])
|
| 423 |
+
right_shoulder = pose_landmarks[12]
|
| 424 |
+
left_shoulder = pose_landmarks[11]
|
| 425 |
+
mouth_left = pose_landmarks[9]
|
| 426 |
+
mouth_right = pose_landmarks[10]
|
| 427 |
+
|
| 428 |
+
right_hand_middle_finger_y = int(
|
| 429 |
+
right_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].y * frame.shape[0])
|
| 430 |
+
right_hand_middle_finger_x = int(
|
| 431 |
+
right_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].x * frame.shape[1])
|
| 432 |
+
right_hand_ring_finger_y = int(
|
| 433 |
+
right_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].y * frame.shape[0])
|
| 434 |
+
right_hand_ring_finger_x = int(
|
| 435 |
+
right_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].x * frame.shape[1])
|
| 436 |
+
right_hand_pinky_finger_y = int(
|
| 437 |
+
right_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].y * frame.shape[0])
|
| 438 |
+
right_hand_pinky_finger_x = int(
|
| 439 |
+
right_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].x * frame.shape[1])
|
| 440 |
+
|
| 441 |
+
left_hand_middle_finger_y = int(
|
| 442 |
+
left_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].y * frame.shape[0])
|
| 443 |
+
left_hand_middle_finger_x = int(
|
| 444 |
+
left_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].x * frame.shape[1])
|
| 445 |
+
left_hand_ring_finger_y = int(
|
| 446 |
+
left_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].y * frame.shape[0])
|
| 447 |
+
left_hand_ring_finger_x = int(
|
| 448 |
+
left_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].x * frame.shape[1])
|
| 449 |
+
left_hand_pinky_finger_y = int(
|
| 450 |
+
left_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].y * frame.shape[0])
|
| 451 |
+
left_hand_pinky_finger_x = int(
|
| 452 |
+
left_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].x * frame.shape[1])
|
| 453 |
+
|
| 454 |
+
forehead_y = int(forehead.y * frame.shape[0])
|
| 455 |
+
|
| 456 |
+
right_hand_middle_finger_dip_y = int(
|
| 457 |
+
right_hand_landmarks[11].y * frame.shape[0])
|
| 458 |
+
right_hand_ring_finger_dip_y = int(
|
| 459 |
+
right_hand_landmarks[15].y * frame.shape[0])
|
| 460 |
+
right_hand_pinky_dip_y = int(
|
| 461 |
+
right_hand_landmarks[19].y * frame.shape[0])
|
| 462 |
+
|
| 463 |
+
left_hand_middle_finger_dip_y = int(
|
| 464 |
+
right_hand_landmarks[11].y * frame.shape[0])
|
| 465 |
+
left_hand_ring_finger_dip_y = int(
|
| 466 |
+
right_hand_landmarks[15].y * frame.shape[0])
|
| 467 |
+
left_hand_pinky_dip_y = int(
|
| 468 |
+
left_hand_landmarks[19].y * frame.shape[0])
|
| 469 |
+
|
| 470 |
+
right_index_middle_finger_distance = right_hand_middle_finger_x - right_hand_tip_x
|
| 471 |
+
right_middle_ring_finger_distance = right_hand_ring_finger_x - \
|
| 472 |
+
right_hand_middle_finger_x
|
| 473 |
+
|
| 474 |
+
left_index_middle_finger_distance = left_hand_middle_finger_x - left_hand_tip_x
|
| 475 |
+
right_middle_ring_finger_distance = right_hand_ring_finger_x - \
|
| 476 |
+
right_hand_middle_finger_x
|
| 477 |
+
|
| 478 |
+
# eye_pupil_right_x = int(face_landmarks[468].x * frame.shape[1])
|
| 479 |
+
# eye_pupil_left_x = int(face_landmarks[473].x * frame.shape[1])
|
| 480 |
+
|
| 481 |
+
ring_finger_distance = right_hand_ring_finger_y - left_hand_ring_finger_y
|
| 482 |
+
|
| 483 |
+
mouth_left_y = int(mouth_left.y * frame.shape[0])
|
| 484 |
+
mouth_right_y = int(mouth_right.y * frame.shape[0])
|
| 485 |
+
right_shoulder_y = int(right_shoulder.y * frame.shape[0])
|
| 486 |
+
left_shoulder_y = int(left_shoulder.y * frame.shape[0])
|
| 487 |
+
|
| 488 |
+
val_hand_tips = left_hand_tip_x - right_hand_tip_x
|
| 489 |
+
val_hand_thumbs = left_hand_thumb - right_hand_thumb
|
| 490 |
+
|
| 491 |
+
lips_left = face_landmarks[287]
|
| 492 |
+
lips_right = face_landmarks[57]
|
| 493 |
+
|
| 494 |
+
lips_left_x = int(lips_left.x * frame.shape[1])
|
| 495 |
+
lips_right_x = int(lips_right.x * frame.shape[1])
|
| 496 |
+
|
| 497 |
+
face_landmarks = results.face_landmarks.landmark
|
| 498 |
+
|
| 499 |
+
thumb_tip = right_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP]
|
| 500 |
+
index_finger_tip = right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP]
|
| 501 |
+
right_cheek = face_landmarks[116]
|
| 502 |
+
right_ear = face_landmarks[147]
|
| 503 |
+
chin = face_landmarks[152]
|
| 504 |
+
left_cheek = face_landmarks[323]
|
| 505 |
+
|
| 506 |
+
thumb_tip_y = int(thumb_tip.y * frame.shape[0])
|
| 507 |
+
thumb_tip_x = int(thumb_tip.x * frame.shape[1])
|
| 508 |
+
index_finger_tip_y = int(index_finger_tip.y * frame.shape[0])
|
| 509 |
+
index_finger_tip_x = int(index_finger_tip.x * frame.shape[1])
|
| 510 |
+
cheek_y = int(right_cheek.y * frame.shape[0])
|
| 511 |
+
right_ear_x = int(right_ear.x * frame.shape[1])
|
| 512 |
+
chin_y = int(chin.y * frame.shape[0])
|
| 513 |
+
left_cheek_x = int(left_cheek.x * frame.shape[1])
|
| 514 |
+
|
| 515 |
+
lips_left_y_distance = lips_left_y - lips_right_y
|
| 516 |
+
lips_right_y_distance = lips_right_y - lips_left_y
|
| 517 |
+
|
| 518 |
+
index_finger_distance_x = left_hand_tip_x - right_hand_tip_x
|
| 519 |
+
if ((right_hand_tip_y < right_hand_middle_finger_y) and (right_hand_tip_y < right_hand_ring_finger_y) and (right_hand_tip_y < right_hand_pinky_finger_y) and (right_hand_tip_y < thumb_tip_y)):
|
| 520 |
+
if ((right_hand_tip_y > upper_nose_y) and (right_hand_tip_y < bottom_lip_y) and (right_hand_tip_x > lips_left_x) and (right_hand_tip_x < lips_right_x)):
|
| 521 |
+
cv2.putText(image, "Disagree with Spoken Word", (50, 50),
|
| 522 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 523 |
+
counter[0] += 1
|
| 524 |
+
elif ((right_hand_tip_y > right_hand_dip_y) and (right_hand_middle_finger_y > right_hand_middle_finger_dip_y) and (right_hand_ring_finger_y > right_hand_ring_finger_dip_y) and (right_hand_pinky_finger_y > right_hand_pinky_dip_y) and (left_hand_tip_y > left_hand_dip_y) and (left_hand_middle_finger_y > left_hand_middle_finger_dip_y) and (left_hand_ring_finger_y > left_hand_ring_finger_dip_y) and (left_hand_pinky_finger_y > left_hand_pinky_dip_y) and (right_hand_tip_x > (right_ear_top_x-40)) and (right_hand_tip_x < right_ear_top_x) and (left_hand_tip_x < (left_ear_top_x+40)) and (left_hand_tip_x > left_ear_top_x) and (lips_left_y > lips_right_y or lips_right_y > lips_left_y) and ((lips_left_y_distance > 1 and lips_left_y_distance < 40) or (lips_right_y_distance > 1 and lips_right_y_distance < 40))):
|
| 525 |
+
cv2.putText(image, "Annoyed", (50, 50),
|
| 526 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 527 |
+
counter[2] += 1
|
| 528 |
+
elif ((right_hand_tip_y < right_shoulder_y and left_hand_tip_y < left_shoulder_y) and (right_hand_tip_y > mouth_right_y) and (left_hand_tip_y > mouth_left_y) and (right_hand_dip_y > right_hand_tip_y and left_hand_dip_y > left_hand_tip_y) and (left_hand_tip_x < lips_left_x) and (right_hand_tip_x > lips_right_x) and (val_hand_tips < 20 and val_hand_thumbs < 20)):
|
| 529 |
+
cv2.putText(image, "Wants her knowledge to be recognized now",
|
| 530 |
+
(50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 531 |
+
counter[8] += 1
|
| 532 |
+
elif (((right_hand_tip_y < right_hand_dip_y) and (right_hand_middle_finger_y < right_hand_middle_finger_dip_y) and (right_hand_ring_finger_y < right_hand_ring_finger_dip_y) and (right_hand_tip_y < right_hand_dip_y)) and ((left_hand_tip_y < left_hand_dip_y) and (left_hand_middle_finger_y < left_hand_middle_finger_dip_y) and (left_hand_ring_finger_y < left_hand_ring_finger_dip_y) and (left_hand_pinky_finger_y < left_hand_pinky_dip_y)) and (is_eyes_looking_up(mesh_coords, UPPER_EYE_LEFT + UPPER_EYE_RIGHT)) and (right_hand_tip_y < chin_y and right_hand_tip_y > forehead_y) and (left_hand_tip_y < chin_y and left_hand_tip_y > forehead_y) and (right_hand_tip_x > right_ear_top_x and left_hand_tip_x < left_ear_top_x) and (index_finger_distance_x > 20)):
|
| 533 |
+
cv2.putText(image, "Reobserve, Feeling Uncomfortable", (50, 50),
|
| 534 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 535 |
+
counter[1] += 1
|
| 536 |
+
else:
|
| 537 |
+
cv2.putText(image, "Neutral", (50, 50),
|
| 538 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 539 |
+
counter[7] += 1
|
| 540 |
+
|
| 541 |
+
elif results.face_landmarks and results.right_hand_landmarks and results.pose_landmarks:
|
| 542 |
+
face_landmarks = results.face_landmarks.landmark
|
| 543 |
+
right_hand_landmarks = results.right_hand_landmarks.landmark
|
| 544 |
+
pose_landmarks = results.pose_landmarks.landmark
|
| 545 |
+
|
| 546 |
+
for idx, lm in enumerate(face_landmarks):
|
| 547 |
+
if idx == 33 or idx == 263 or idx == 1 or idx == 61 or idx == 291 or idx == 199:
|
| 548 |
+
if idx == 1:
|
| 549 |
+
nose_2d = (lm.x * img_w, lm.y * img_h)
|
| 550 |
+
nose_3d = (lm.x * img_w, lm.y * img_h, lm.z * 3000)
|
| 551 |
+
|
| 552 |
+
x, y = int(lm.x * img_w), int(lm.y * img_h)
|
| 553 |
+
|
| 554 |
+
# Get the 2D Coordinates
|
| 555 |
+
face_2d.append([x, y])
|
| 556 |
+
|
| 557 |
+
# Get the 3D Coordinates
|
| 558 |
+
face_3d.append([x, y, lm.z])
|
| 559 |
+
|
| 560 |
+
# Convert it to the NumPy array
|
| 561 |
+
face_2d = np.array(face_2d, dtype=np.float64)
|
| 562 |
+
|
| 563 |
+
# Convert it to the NumPy array
|
| 564 |
+
face_3d = np.array(face_3d, dtype=np.float64)
|
| 565 |
+
|
| 566 |
+
# The camera matrix
|
| 567 |
+
focal_length = 1 * img_w
|
| 568 |
+
|
| 569 |
+
cam_matrix = np.array([[focal_length, 0, img_h / 2],
|
| 570 |
+
[0, focal_length, img_w / 2],
|
| 571 |
+
[0, 0, 1]])
|
| 572 |
+
|
| 573 |
+
# The distortion parameters
|
| 574 |
+
dist_matrix = np.zeros((4, 1), dtype=np.float64)
|
| 575 |
+
|
| 576 |
+
# Solve PnP
|
| 577 |
+
success, rot_vec, trans_vec = cv2.solvePnP(
|
| 578 |
+
face_3d, face_2d, cam_matrix, dist_matrix)
|
| 579 |
+
|
| 580 |
+
# Get rotational matrix
|
| 581 |
+
rmat, jac = cv2.Rodrigues(rot_vec)
|
| 582 |
+
|
| 583 |
+
# Get angles
|
| 584 |
+
angles, mtxR, mtxQ, Qx, Qy, Qz = cv2.RQDecomp3x3(rmat)
|
| 585 |
+
|
| 586 |
+
# Get the y rotation degree
|
| 587 |
+
x = angles[0] * 360
|
| 588 |
+
y = angles[1] * 360
|
| 589 |
+
z = angles[2] * 360
|
| 590 |
+
|
| 591 |
+
head_text = ""
|
| 592 |
+
|
| 593 |
+
# See where the user's head tilting
|
| 594 |
+
if y < -10:
|
| 595 |
+
head_text = "Looking Left"
|
| 596 |
+
elif y > 10:
|
| 597 |
+
head_text = "Looking Right"
|
| 598 |
+
elif x < -10:
|
| 599 |
+
head_text = "Looking Down"
|
| 600 |
+
elif x > 10:
|
| 601 |
+
head_text = "Looking Up"
|
| 602 |
+
else:
|
| 603 |
+
head_text = "Forward"
|
| 604 |
+
|
| 605 |
+
# Display the nose direction
|
| 606 |
+
nose_3d_projection, jacobian = cv2.projectPoints(
|
| 607 |
+
nose_3d, rot_vec, trans_vec, cam_matrix, dist_matrix)
|
| 608 |
+
|
| 609 |
+
p1 = (int(nose_2d[0]), int(nose_2d[1]))
|
| 610 |
+
p2 = (int(nose_2d[0] + y * 10), int(nose_2d[1] - x * 10))
|
| 611 |
+
|
| 612 |
+
# cv2.line(image, p1, p2, (255, 0, 0), 3)
|
| 613 |
+
|
| 614 |
+
# Add the text on the image
|
| 615 |
+
# cv2.putText(image, head_text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 2)
|
| 616 |
+
# cv2.putText(image, "x: " + str(np.round(x,2)), (500, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 617 |
+
# cv2.putText(image, "y: " + str(np.round(y,2)), (500, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 618 |
+
# cv2.putText(image, "z: " + str(np.round(z,2)), (500, 150), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 619 |
+
|
| 620 |
+
mesh_coords = landmarksDetection(frame, results, False)
|
| 621 |
+
|
| 622 |
+
thumb_tip = right_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP]
|
| 623 |
+
index_finger_tip = right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP]
|
| 624 |
+
right_cheek = face_landmarks[116]
|
| 625 |
+
right_ear = face_landmarks[147]
|
| 626 |
+
chin = face_landmarks[152]
|
| 627 |
+
left_cheek = face_landmarks[323]
|
| 628 |
+
|
| 629 |
+
thumb_tip_y = int(thumb_tip.y * frame.shape[0])
|
| 630 |
+
thumb_tip_x = int(thumb_tip.x * frame.shape[1])
|
| 631 |
+
index_finger_tip_y = int(index_finger_tip.y * frame.shape[0])
|
| 632 |
+
index_finger_tip_x = int(index_finger_tip.x * frame.shape[1])
|
| 633 |
+
cheek_y = int(right_cheek.y * frame.shape[0])
|
| 634 |
+
right_ear_x = int(right_ear.x * frame.shape[1])
|
| 635 |
+
chin_y = int(chin.y * frame.shape[0])
|
| 636 |
+
left_cheek_x = int(left_cheek.x * frame.shape[1])
|
| 637 |
+
|
| 638 |
+
right_wrist = pose_landmarks[16]
|
| 639 |
+
|
| 640 |
+
right_wrist_y = int(right_wrist.y * frame.shape[0])
|
| 641 |
+
|
| 642 |
+
head_top = face_landmarks[10]
|
| 643 |
+
head_below = face_landmarks[152]
|
| 644 |
+
|
| 645 |
+
nose_top = face_landmarks[197]
|
| 646 |
+
nose_bottom = face_landmarks[4]
|
| 647 |
+
nose_left = face_landmarks[49]
|
| 648 |
+
nose_right = face_landmarks[279]
|
| 649 |
+
|
| 650 |
+
nose_top_y = int(nose_top.y * frame.shape[0])
|
| 651 |
+
nose_bottom_y = int(nose_bottom.y * frame.shape[0])
|
| 652 |
+
nose_left_x = int(nose_left.x * frame.shape[1])
|
| 653 |
+
nose_right_x = int(nose_right.x * frame.shape[1])
|
| 654 |
+
|
| 655 |
+
head_top_y = int(head_top.y * frame.shape[0])
|
| 656 |
+
head_below_y = int(head_below.y * frame.shape[0])
|
| 657 |
+
|
| 658 |
+
mouth_lip_upper = face_landmarks[13]
|
| 659 |
+
mouth_lip_lower = face_landmarks[14]
|
| 660 |
+
|
| 661 |
+
bottom_lip = face_landmarks[18]
|
| 662 |
+
nose_center = face_landmarks[1]
|
| 663 |
+
|
| 664 |
+
right_ear_top = face_landmarks[21]
|
| 665 |
+
right_ear_bottom = face_landmarks[215]
|
| 666 |
+
|
| 667 |
+
lips_left = face_landmarks[287]
|
| 668 |
+
lips_right = face_landmarks[57]
|
| 669 |
+
|
| 670 |
+
bottom_lip_y = int(bottom_lip.y * frame.shape[0])
|
| 671 |
+
upper_nose_y = int(nose_center.y * frame.shape[0])
|
| 672 |
+
|
| 673 |
+
lips_left_x = int(lips_left.x * frame.shape[1])
|
| 674 |
+
lips_right_x = int(lips_right.x * frame.shape[1])
|
| 675 |
+
|
| 676 |
+
left_cheek = face_landmarks[323]
|
| 677 |
+
|
| 678 |
+
right_ear_top_y = int(right_ear_top.y * frame.shape[0])
|
| 679 |
+
right_ear_top_x = int(right_ear_top.x * frame.shape[1])
|
| 680 |
+
right_ear_bottom_x = int(right_ear_bottom.x * frame.shape[1])
|
| 681 |
+
right_ear_bottom_y = int(right_ear_bottom.y * frame.shape[0])
|
| 682 |
+
|
| 683 |
+
mouth_lip_upper_y = int(mouth_lip_upper.y * frame.shape[0])
|
| 684 |
+
mouth_lip_lower_y = int(mouth_lip_lower.y * frame.shape[0])
|
| 685 |
+
|
| 686 |
+
right_hand_tip_x = int(
|
| 687 |
+
right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].x * frame.shape[1])
|
| 688 |
+
right_hand_tip_y = int(
|
| 689 |
+
right_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].y * frame.shape[0])
|
| 690 |
+
|
| 691 |
+
thumb_tip = right_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP]
|
| 692 |
+
|
| 693 |
+
head_top_x = int(head_top.x * frame.shape[1])
|
| 694 |
+
right_wrist_x = int(right_wrist.x * frame.shape[1])
|
| 695 |
+
|
| 696 |
+
thumb_tip_y = int(thumb_tip.y * frame.shape[0])
|
| 697 |
+
thumb_tip_x = int(thumb_tip.x * frame.shape[1])
|
| 698 |
+
chin = face_landmarks[152]
|
| 699 |
+
chin_y = int(chin.y * frame.shape[0])
|
| 700 |
+
|
| 701 |
+
lips_distance = mouth_lip_lower_y - mouth_lip_upper_y
|
| 702 |
+
|
| 703 |
+
right_ear_hand_distance = head_top_x - right_wrist_x
|
| 704 |
+
|
| 705 |
+
right_hand_middle_finger_y = int(
|
| 706 |
+
right_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].y * frame.shape[0])
|
| 707 |
+
right_hand_middle_finger_x = int(
|
| 708 |
+
right_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].x * frame.shape[1])
|
| 709 |
+
right_hand_ring_finger_y = int(
|
| 710 |
+
right_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].y * frame.shape[0])
|
| 711 |
+
right_hand_ring_finger_x = int(
|
| 712 |
+
right_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].x * frame.shape[1])
|
| 713 |
+
right_hand_pinky_finger_y = int(
|
| 714 |
+
right_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].y * frame.shape[0])
|
| 715 |
+
right_hand_pinky_finger_x = int(
|
| 716 |
+
right_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].x * frame.shape[1])
|
| 717 |
+
|
| 718 |
+
left_cheek_x = int(left_cheek.x * frame.shape[1])
|
| 719 |
+
|
| 720 |
+
if ((right_hand_tip_y < right_hand_middle_finger_y) and (right_hand_tip_y < right_hand_ring_finger_y) and (right_hand_tip_y < right_hand_pinky_finger_y) and (right_hand_tip_y < thumb_tip_y) and (right_hand_tip_y > upper_nose_y) and (right_hand_tip_y < bottom_lip_y) and (right_hand_tip_x < lips_left_x) and (right_hand_tip_x > lips_right_x)):
|
| 721 |
+
cv2.putText(image, "Disagree with Spoken Word", (50, 50),
|
| 722 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 723 |
+
counter[0] += 1
|
| 724 |
+
elif ((right_hand_tip_y > right_ear_top_y) and (right_hand_tip_y < right_ear_bottom_y) and (right_hand_tip_x > (right_ear_top_x-40)) and (right_hand_tip_x < right_ear_top_x)):
|
| 725 |
+
cv2.putText(image, "Disagree what was heard", (50, 50),
|
| 726 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 727 |
+
counter[3] += 1
|
| 728 |
+
elif (lips_distance > 10):
|
| 729 |
+
cv2.putText(image, "Disbelief", (50, 50),
|
| 730 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 731 |
+
counter[4] += 1
|
| 732 |
+
elif ((right_hand_tip_y < nose_bottom_y) and (right_hand_tip_y > nose_top_y) and (right_hand_tip_x > nose_left_x) and (right_hand_tip_x < nose_right_x)):
|
| 733 |
+
cv2.putText(image, "Untruthful", (50, 50),
|
| 734 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 735 |
+
counter[5] += 1
|
| 736 |
+
elif ((right_wrist_y > head_top_y) and (right_wrist_y < head_below_y) and (right_ear_hand_distance < 100) and (head_text == "Looking Down")):
|
| 737 |
+
cv2.putText(image, "Embarrased, Got Caught", (50, 50),
|
| 738 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 739 |
+
counter[6] += 1
|
| 740 |
+
elif ((chin_y > thumb_tip_y) and (right_ear_x < thumb_tip_x) and (thumb_tip_y > cheek_y) and (thumb_tip_x < left_cheek_x) and (head_text == "Looking Up")) or ((chin_y > index_finger_tip_y) and (right_ear_x < index_finger_tip_x) and (index_finger_tip_y > cheek_y) and (index_finger_tip_x < left_cheek_x) and (head_text == "Looking Up")):
|
| 741 |
+
cv2.putText(image, "Positive evaluation low risk situation", (50, 50),
|
| 742 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 743 |
+
counter[9] += 1
|
| 744 |
+
else:
|
| 745 |
+
cv2.putText(image, "Neutral", (50, 50),
|
| 746 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 747 |
+
counter[7] += 1
|
| 748 |
+
|
| 749 |
+
elif results.face_landmarks and results.left_hand_landmarks and results.pose_landmarks:
|
| 750 |
+
face_landmarks = results.face_landmarks.landmark
|
| 751 |
+
left_hand_landmarks = results.left_hand_landmarks.landmark
|
| 752 |
+
pose_landmarks = results.pose_landmarks.landmark
|
| 753 |
+
|
| 754 |
+
for idx, lm in enumerate(face_landmarks):
|
| 755 |
+
if idx == 33 or idx == 263 or idx == 1 or idx == 61 or idx == 291 or idx == 199:
|
| 756 |
+
if idx == 1:
|
| 757 |
+
nose_2d = (lm.x * img_w, lm.y * img_h)
|
| 758 |
+
nose_3d = (lm.x * img_w, lm.y * img_h, lm.z * 3000)
|
| 759 |
+
|
| 760 |
+
x, y = int(lm.x * img_w), int(lm.y * img_h)
|
| 761 |
+
|
| 762 |
+
# Get the 2D Coordinates
|
| 763 |
+
face_2d.append([x, y])
|
| 764 |
+
|
| 765 |
+
# Get the 3D Coordinates
|
| 766 |
+
face_3d.append([x, y, lm.z])
|
| 767 |
+
|
| 768 |
+
# Convert it to the NumPy array
|
| 769 |
+
face_2d = np.array(face_2d, dtype=np.float64)
|
| 770 |
+
|
| 771 |
+
# Convert it to the NumPy array
|
| 772 |
+
face_3d = np.array(face_3d, dtype=np.float64)
|
| 773 |
+
|
| 774 |
+
# The camera matrix
|
| 775 |
+
focal_length = 1 * img_w
|
| 776 |
+
|
| 777 |
+
cam_matrix = np.array([[focal_length, 0, img_h / 2],
|
| 778 |
+
[0, focal_length, img_w / 2],
|
| 779 |
+
[0, 0, 1]])
|
| 780 |
+
|
| 781 |
+
# The distortion parameters
|
| 782 |
+
dist_matrix = np.zeros((4, 1), dtype=np.float64)
|
| 783 |
+
|
| 784 |
+
# Solve PnP
|
| 785 |
+
success, rot_vec, trans_vec = cv2.solvePnP(
|
| 786 |
+
face_3d, face_2d, cam_matrix, dist_matrix)
|
| 787 |
+
|
| 788 |
+
# Get rotational matrix
|
| 789 |
+
rmat, jac = cv2.Rodrigues(rot_vec)
|
| 790 |
+
|
| 791 |
+
# Get angles
|
| 792 |
+
angles, mtxR, mtxQ, Qx, Qy, Qz = cv2.RQDecomp3x3(rmat)
|
| 793 |
+
|
| 794 |
+
# Get the y rotation degree
|
| 795 |
+
x = angles[0] * 360
|
| 796 |
+
y = angles[1] * 360
|
| 797 |
+
z = angles[2] * 360
|
| 798 |
+
|
| 799 |
+
head_text = ""
|
| 800 |
+
|
| 801 |
+
# See where the user's head tilting
|
| 802 |
+
if y < -10:
|
| 803 |
+
head_text = "Looking Left"
|
| 804 |
+
elif y > 10:
|
| 805 |
+
head_text = "Looking Right"
|
| 806 |
+
elif x < -10:
|
| 807 |
+
head_text = "Looking Down"
|
| 808 |
+
elif x > 10:
|
| 809 |
+
head_text = "Looking Up"
|
| 810 |
+
else:
|
| 811 |
+
head_text = "Forward"
|
| 812 |
+
|
| 813 |
+
# Display the nose direction
|
| 814 |
+
nose_3d_projection, jacobian = cv2.projectPoints(
|
| 815 |
+
nose_3d, rot_vec, trans_vec, cam_matrix, dist_matrix)
|
| 816 |
+
|
| 817 |
+
p1 = (int(nose_2d[0]), int(nose_2d[1]))
|
| 818 |
+
p2 = (int(nose_2d[0] + y * 10), int(nose_2d[1] - x * 10))
|
| 819 |
+
|
| 820 |
+
# cv2.line(image, p1, p2, (255, 0, 0), 3)
|
| 821 |
+
|
| 822 |
+
# Add the text on the image
|
| 823 |
+
# cv2.putText(image, head_text, (20, 50), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 2)
|
| 824 |
+
# cv2.putText(image, "x: " + str(np.round(x,2)), (500, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 825 |
+
# cv2.putText(image, "y: " + str(np.round(y,2)), (500, 100), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 826 |
+
# cv2.putText(image, "z: " + str(np.round(z,2)), (500, 150), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
|
| 827 |
+
|
| 828 |
+
mesh_coords = landmarksDetection(frame, results, False)
|
| 829 |
+
|
| 830 |
+
thumb_tip = left_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP]
|
| 831 |
+
index_finger_tip = left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP]
|
| 832 |
+
left_cheek = face_landmarks[345]
|
| 833 |
+
left_ear = face_landmarks[376]
|
| 834 |
+
chin = face_landmarks[152]
|
| 835 |
+
left_cheek = face_landmarks[352]
|
| 836 |
+
|
| 837 |
+
thumb_tip_y = int(thumb_tip.y * frame.shape[0])
|
| 838 |
+
thumb_tip_x = int(thumb_tip.x * frame.shape[1])
|
| 839 |
+
index_finger_tip_y = int(index_finger_tip.y * frame.shape[0])
|
| 840 |
+
index_finger_tip_x = int(index_finger_tip.x * frame.shape[1])
|
| 841 |
+
cheek_y = int(left_cheek.y * frame.shape[0])
|
| 842 |
+
left_ear_x = int(left_ear.x * frame.shape[1])
|
| 843 |
+
chin_y = int(chin.y * frame.shape[0])
|
| 844 |
+
left_cheek_x = int(left_cheek.x * frame.shape[1])
|
| 845 |
+
|
| 846 |
+
left_wrist = pose_landmarks[15]
|
| 847 |
+
|
| 848 |
+
left_wrist_y = int(left_wrist.y * frame.shape[0])
|
| 849 |
+
|
| 850 |
+
head_top = face_landmarks[10]
|
| 851 |
+
head_below = face_landmarks[152]
|
| 852 |
+
|
| 853 |
+
nose_top = face_landmarks[197]
|
| 854 |
+
nose_bottom = face_landmarks[4]
|
| 855 |
+
nose_left = face_landmarks[49]
|
| 856 |
+
nose_right = face_landmarks[279]
|
| 857 |
+
|
| 858 |
+
nose_top_y = int(nose_top.y * frame.shape[0])
|
| 859 |
+
nose_bottom_y = int(nose_bottom.y * frame.shape[0])
|
| 860 |
+
nose_left_x = int(nose_left.x * frame.shape[1])
|
| 861 |
+
nose_right_x = int(nose_right.x * frame.shape[1])
|
| 862 |
+
|
| 863 |
+
head_top_y = int(head_top.y * frame.shape[0])
|
| 864 |
+
head_below_y = int(head_below.y * frame.shape[0])
|
| 865 |
+
|
| 866 |
+
mouth_lip_upper = face_landmarks[13]
|
| 867 |
+
mouth_lip_lower = face_landmarks[14]
|
| 868 |
+
|
| 869 |
+
bottom_lip = face_landmarks[18]
|
| 870 |
+
nose_center = face_landmarks[1]
|
| 871 |
+
|
| 872 |
+
left_ear_top = face_landmarks[251]
|
| 873 |
+
left_ear_bottom = face_landmarks[435]
|
| 874 |
+
|
| 875 |
+
lips_left = face_landmarks[287]
|
| 876 |
+
lips_right = face_landmarks[57]
|
| 877 |
+
|
| 878 |
+
bottom_lip_y = int(bottom_lip.y * frame.shape[0])
|
| 879 |
+
upper_nose_y = int(nose_center.y * frame.shape[0])
|
| 880 |
+
|
| 881 |
+
lips_left_x = int(lips_left.x * frame.shape[1])
|
| 882 |
+
lips_right_x = int(lips_right.x * frame.shape[1])
|
| 883 |
+
|
| 884 |
+
left_cheek = face_landmarks[323]
|
| 885 |
+
|
| 886 |
+
left_ear_top_y = int(left_ear_top.y * frame.shape[0])
|
| 887 |
+
left_ear_top_x = int(left_ear_top.x * frame.shape[1])
|
| 888 |
+
left_ear_bottom_x = int(left_ear_bottom.x * frame.shape[1])
|
| 889 |
+
left_ear_bottom_y = int(left_ear_bottom.y * frame.shape[0])
|
| 890 |
+
|
| 891 |
+
mouth_lip_upper_y = int(mouth_lip_upper.y * frame.shape[0])
|
| 892 |
+
mouth_lip_lower_y = int(mouth_lip_lower.y * frame.shape[0])
|
| 893 |
+
|
| 894 |
+
left_hand_tip_x = int(
|
| 895 |
+
left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].x * frame.shape[1])
|
| 896 |
+
left_hand_tip_y = int(
|
| 897 |
+
left_hand_landmarks[mp_holistic.HandLandmark.INDEX_FINGER_TIP].y * frame.shape[0])
|
| 898 |
+
|
| 899 |
+
thumb_tip = left_hand_landmarks[mp_holistic.HandLandmark.THUMB_TIP]
|
| 900 |
+
|
| 901 |
+
head_top_x = int(head_top.x * frame.shape[1])
|
| 902 |
+
left_wrist_x = int(left_wrist.x * frame.shape[1])
|
| 903 |
+
|
| 904 |
+
thumb_tip_y = int(thumb_tip.y * frame.shape[0])
|
| 905 |
+
thumb_tip_x = int(thumb_tip.x * frame.shape[1])
|
| 906 |
+
chin = face_landmarks[152]
|
| 907 |
+
chin_y = int(chin.y * frame.shape[0])
|
| 908 |
+
|
| 909 |
+
lips_distance = mouth_lip_lower_y - mouth_lip_upper_y
|
| 910 |
+
|
| 911 |
+
left_ear_hand_distance = left_wrist_x - head_top_x
|
| 912 |
+
|
| 913 |
+
left_hand_middle_finger_y = int(
|
| 914 |
+
left_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].y * frame.shape[0])
|
| 915 |
+
left_hand_middle_finger_x = int(
|
| 916 |
+
left_hand_landmarks[mp_holistic.HandLandmark.MIDDLE_FINGER_TIP].x * frame.shape[1])
|
| 917 |
+
left_hand_ring_finger_y = int(
|
| 918 |
+
left_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].y * frame.shape[0])
|
| 919 |
+
left_hand_ring_finger_x = int(
|
| 920 |
+
left_hand_landmarks[mp_holistic.HandLandmark.RING_FINGER_TIP].x * frame.shape[1])
|
| 921 |
+
left_hand_pinky_finger_y = int(
|
| 922 |
+
left_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].y * frame.shape[0])
|
| 923 |
+
left_hand_pinky_finger_x = int(
|
| 924 |
+
left_hand_landmarks[mp_holistic.HandLandmark.PINKY_TIP].x * frame.shape[1])
|
| 925 |
+
|
| 926 |
+
left_cheek_x = int(left_cheek.x * frame.shape[1])
|
| 927 |
+
|
| 928 |
+
if ((left_hand_tip_y < left_hand_middle_finger_y) and (left_hand_tip_y < left_hand_ring_finger_y) and (left_hand_tip_y < left_hand_pinky_finger_y) and (left_hand_tip_y < thumb_tip_y) and (left_hand_tip_y > upper_nose_y) and (left_hand_tip_y < bottom_lip_y) and (left_hand_tip_x < lips_left_x) and (left_hand_tip_x > lips_right_x)):
|
| 929 |
+
cv2.putText(image, "Disagree with Spoken Word", (50, 50),
|
| 930 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 931 |
+
counter[0] += 1
|
| 932 |
+
elif ((left_hand_tip_y > left_ear_top_y) and (left_hand_tip_y < left_ear_bottom_y) and (left_hand_tip_x < (left_ear_top_x+40)) and (left_hand_tip_x > left_ear_top_x)):
|
| 933 |
+
cv2.putText(image, "Disagree what was heard", (50, 50),
|
| 934 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 935 |
+
counter[3] += 1
|
| 936 |
+
elif (lips_distance > 10):
|
| 937 |
+
cv2.putText(image, "Disbelief", (50, 50),
|
| 938 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 939 |
+
counter[4] += 1
|
| 940 |
+
elif ((left_hand_tip_y < nose_bottom_y) and (left_hand_tip_y > nose_top_y) and (left_hand_tip_x > nose_left_x) and (left_hand_tip_x < nose_right_x)):
|
| 941 |
+
cv2.putText(image, "Untruthful", (50, 50),
|
| 942 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 943 |
+
counter[5] += 1
|
| 944 |
+
elif ((left_wrist_y > head_top_y) and (left_wrist_y < head_below_y) and (left_ear_hand_distance < 100) and (head_text == "Looking Down")):
|
| 945 |
+
cv2.putText(image, "Embarrased, Got Caught", (50, 50),
|
| 946 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 947 |
+
counter[6] += 1
|
| 948 |
+
elif ((chin_y > thumb_tip_y) and (left_ear_x > thumb_tip_x) and (thumb_tip_y > cheek_y) and (thumb_tip_x > left_cheek_x) and (head_text == "Looking Up")) or ((chin_y > index_finger_tip_y) and (left_ear_x > index_finger_tip_x) and (index_finger_tip_y > cheek_y) and (index_finger_tip_x > left_cheek_x) and (head_text == "Looking Up")):
|
| 949 |
+
cv2.putText(image, "Positive evaluation low risk situation", (50, 50),
|
| 950 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 951 |
+
counter[9] += 1
|
| 952 |
+
else:
|
| 953 |
+
cv2.putText(image, "Neutral", (50, 50),
|
| 954 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 955 |
+
counter[7] += 1
|
| 956 |
+
|
| 957 |
+
elif results.pose_landmarks and results.face_landmarks:
|
| 958 |
+
face_landmarks = results.face_landmarks.landmark
|
| 959 |
+
pose_landmarks = results.pose_landmarks.landmark
|
| 960 |
+
|
| 961 |
+
for idx, lm in enumerate(face_landmarks):
|
| 962 |
+
if idx == 33 or idx == 263 or idx == 1 or idx == 61 or idx == 291 or idx == 199:
|
| 963 |
+
if idx == 1:
|
| 964 |
+
nose_2d = (lm.x * img_w, lm.y * img_h)
|
| 965 |
+
nose_3d = (lm.x * img_w, lm.y * img_h, lm.z * 3000)
|
| 966 |
+
|
| 967 |
+
x, y = int(lm.x * img_w), int(lm.y * img_h)
|
| 968 |
+
|
| 969 |
+
# Get the 2D Coordinates
|
| 970 |
+
face_2d.append([x, y])
|
| 971 |
+
|
| 972 |
+
# Get the 3D Coordinates
|
| 973 |
+
face_3d.append([x, y, lm.z])
|
| 974 |
+
|
| 975 |
+
# Convert it to the NumPy array
|
| 976 |
+
face_2d = np.array(face_2d, dtype=np.float64)
|
| 977 |
+
|
| 978 |
+
# Convert it to the NumPy array
|
| 979 |
+
face_3d = np.array(face_3d, dtype=np.float64)
|
| 980 |
+
|
| 981 |
+
# The camera matrix
|
| 982 |
+
focal_length = 1 * img_w
|
| 983 |
+
|
| 984 |
+
cam_matrix = np.array([[focal_length, 0, img_h / 2],
|
| 985 |
+
[0, focal_length, img_w / 2],
|
| 986 |
+
[0, 0, 1]])
|
| 987 |
+
|
| 988 |
+
# The distortion parameters
|
| 989 |
+
dist_matrix = np.zeros((4, 1), dtype=np.float64)
|
| 990 |
+
|
| 991 |
+
# Solve PnP
|
| 992 |
+
success, rot_vec, trans_vec = cv2.solvePnP(
|
| 993 |
+
face_3d, face_2d, cam_matrix, dist_matrix)
|
| 994 |
+
|
| 995 |
+
# Get rotational matrix
|
| 996 |
+
rmat, jac = cv2.Rodrigues(rot_vec)
|
| 997 |
+
|
| 998 |
+
# Get angles
|
| 999 |
+
angles, mtxR, mtxQ, Qx, Qy, Qz = cv2.RQDecomp3x3(rmat)
|
| 1000 |
+
|
| 1001 |
+
# Get the y rotation degree
|
| 1002 |
+
x = angles[0] * 360
|
| 1003 |
+
y = angles[1] * 360
|
| 1004 |
+
z = angles[2] * 360
|
| 1005 |
+
|
| 1006 |
+
head_text = ""
|
| 1007 |
+
|
| 1008 |
+
# See where the user's head tilting
|
| 1009 |
+
if y < -10:
|
| 1010 |
+
head_text = "Looking Left"
|
| 1011 |
+
elif y > 10:
|
| 1012 |
+
head_text = "Looking Right"
|
| 1013 |
+
elif x < -10:
|
| 1014 |
+
head_text = "Looking Down"
|
| 1015 |
+
elif x > 10:
|
| 1016 |
+
head_text = "Looking Up"
|
| 1017 |
+
else:
|
| 1018 |
+
head_text = "Forward"
|
| 1019 |
+
|
| 1020 |
+
# Display the nose direction
|
| 1021 |
+
nose_3d_projection, jacobian = cv2.projectPoints(
|
| 1022 |
+
nose_3d, rot_vec, trans_vec, cam_matrix, dist_matrix)
|
| 1023 |
+
|
| 1024 |
+
p1 = (int(nose_2d[0]), int(nose_2d[1]))
|
| 1025 |
+
p2 = (int(nose_2d[0] + y * 10), int(nose_2d[1] - x * 10))
|
| 1026 |
+
|
| 1027 |
+
mesh_coords = landmarksDetection(frame, results, False)
|
| 1028 |
+
|
| 1029 |
+
right_wrist = pose_landmarks[16]
|
| 1030 |
+
|
| 1031 |
+
right_wrist_x = int(right_wrist.x * frame.shape[1])
|
| 1032 |
+
right_wrist_y = int(right_wrist.y * frame.shape[0])
|
| 1033 |
+
|
| 1034 |
+
head_top = face_landmarks[10]
|
| 1035 |
+
head_below = face_landmarks[152]
|
| 1036 |
+
|
| 1037 |
+
head_top_y = int(head_top.y * frame.shape[0])
|
| 1038 |
+
head_below_y = int(head_below.y * frame.shape[0])
|
| 1039 |
+
|
| 1040 |
+
head_top_x = int(head_top.x * frame.shape[1])
|
| 1041 |
+
|
| 1042 |
+
right_ear_hand_distance = head_top_x - right_wrist_x
|
| 1043 |
+
|
| 1044 |
+
ratio = blinkRatio(frame, mesh_coords, RIGHT_EYE, LEFT_EYE)
|
| 1045 |
+
# cv.putText(frame, f'ratio {ratio}', (100, 100), FONTS, 1.0, utils.GREEN, 2)
|
| 1046 |
+
|
| 1047 |
+
if ratio > 5.5:
|
| 1048 |
+
CEF_COUNTER += 1
|
| 1049 |
+
# cv.putText(frame, 'Blink', (200, 50), FONTS, 1.3, utils.PINK, 2)
|
| 1050 |
+
pass
|
| 1051 |
+
else:
|
| 1052 |
+
if CEF_COUNTER > CLOSED_EYES_FRAME:
|
| 1053 |
+
TOTAL_BLINKS += 1
|
| 1054 |
+
CEF_COUNTER = 0
|
| 1055 |
+
# # cv.putText(frame, f'Total Blinks: {TOTAL_BLINKS}', (100, 150), FONTS, 0.6, utils.GREEN, 2)
|
| 1056 |
+
# Blink Detector Counter Completed
|
| 1057 |
+
right_coords = [mesh_coords[p] for p in RIGHT_EYE]
|
| 1058 |
+
left_coords = [mesh_coords[p] for p in LEFT_EYE]
|
| 1059 |
+
crop_right, crop_left = eyesExtractor(
|
| 1060 |
+
frame, right_coords, left_coords)
|
| 1061 |
+
|
| 1062 |
+
eye_position = positionEstimator(crop_right)
|
| 1063 |
+
eye_position_left = positionEstimator(crop_left)
|
| 1064 |
+
|
| 1065 |
+
mouth_lip_upper = face_landmarks[13]
|
| 1066 |
+
mouth_lip_lower = face_landmarks[14]
|
| 1067 |
+
|
| 1068 |
+
right_eye_brow = face_landmarks[105]
|
| 1069 |
+
left_eye_brow = face_landmarks[334]
|
| 1070 |
+
|
| 1071 |
+
right_eye_brow_upper = int(right_eye_brow.y * frame.shape[0])
|
| 1072 |
+
left_eye_brow_upper = int(left_eye_brow.y * frame.shape[0])
|
| 1073 |
+
|
| 1074 |
+
distance_y_eye_brows = right_eye_brow_upper - left_eye_brow_upper
|
| 1075 |
+
# print(distance_y_eye_brows)
|
| 1076 |
+
|
| 1077 |
+
mouth_lip_upper_y = int(mouth_lip_upper.y * frame.shape[0])
|
| 1078 |
+
mouth_lip_lower_y = int(mouth_lip_lower.y * frame.shape[0])
|
| 1079 |
+
|
| 1080 |
+
lips_distance = mouth_lip_lower_y - mouth_lip_upper_y
|
| 1081 |
+
|
| 1082 |
+
frames_list.enqueue(x)
|
| 1083 |
+
frames_list.enqueue(y)
|
| 1084 |
+
|
| 1085 |
+
if ((right_wrist_y > head_top_y) and (right_wrist_y < head_below_y) and (right_ear_hand_distance < 100) and (head_text == "Looking Down")):
|
| 1086 |
+
cv2.putText(image, "Embarrased, Got Caught", (50, 50),
|
| 1087 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1088 |
+
counter[6] += 1
|
| 1089 |
+
elif (lips_distance > 10):
|
| 1090 |
+
cv2.putText(image, "Disbelief", (50, 50),
|
| 1091 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1092 |
+
counter[4] += 1
|
| 1093 |
+
elif (head_text == "Looking Up" and ((eye_position == "LEFT" and eye_position_left == "LEFT") or (eye_position == "RIGHT" and eye_position_left == "RIGHT"))):
|
| 1094 |
+
cv2.putText(image, "Person Recalling Something", (50, 50),
|
| 1095 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1096 |
+
counter[17] += 1
|
| 1097 |
+
elif((left_eye_brow_upper < right_eye_brow_upper) and (distance_y_eye_brows > 4 and distance_y_eye_brows < 10)):
|
| 1098 |
+
cv2.putText(image, "Anger, Dislike, Skeptical", (50, 50),
|
| 1099 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1100 |
+
counter[18] += 1
|
| 1101 |
+
elif (ratio > 5.5):
|
| 1102 |
+
cv2.putText(image, "Doesn't want to see, eye block", (50, 50),
|
| 1103 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1104 |
+
counter[11] += 1
|
| 1105 |
+
elif (((eye_position == "Closed" and eye_position_left == "CENTER") or (eye_position_left == "Closed" and eye_position == "CENTER")) and lips_distance > 50):
|
| 1106 |
+
cv2.putText(image, "Approval", (50, 50),
|
| 1107 |
+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1108 |
+
counter[16] += 1
|
| 1109 |
+
elif((eye_position == "RIGHT" and eye_position_left == "RIGHT") or (eye_position == "LEFT" and eye_position_left == "LEFT")):
|
| 1110 |
+
cv2.putText(image, "Hostility, skeptical", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1111 |
+
counter[19] += 1
|
| 1112 |
+
else:
|
| 1113 |
+
cv2.putText(image, "Disagree with Spoken Word", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1114 |
+
counter[7] += 1
|
| 1115 |
+
# if(len(frames_list.get_all_values()) == 80):
|
| 1116 |
+
# input_data = np.array(frames_list.get_all_values())
|
| 1117 |
+
# input_data = input_data.reshape((40, 2))
|
| 1118 |
+
# predicted_class = predict_label(np.expand_dims(input_data, axis=0).astype(np.float32))
|
| 1119 |
+
# if(predicted_class[0] == 3):
|
| 1120 |
+
# cv2.putText(image, "Head Shake Slow", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1121 |
+
# counter[12] += 1
|
| 1122 |
+
# elif(predicted_class[0] == 2):
|
| 1123 |
+
# cv2.putText(image, "Head Shake Fast", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1124 |
+
# counter[13] += 1
|
| 1125 |
+
# elif(predicted_class[0] == 1):
|
| 1126 |
+
# cv2.putText(image, "Head Nod Slow", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1127 |
+
# counter[14] += 1
|
| 1128 |
+
# elif(predicted_class[0] == 0):
|
| 1129 |
+
# cv2.putText(image, "Head Nod Fast", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA)
|
| 1130 |
+
# counter[15] += 1
|
| 1131 |
+
# else:
|
| 1132 |
+
# cv2.putText(image, "Neutral", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
|
| 1133 |
+
# counter[7] += 1
|
| 1134 |
+
# else:
|
| 1135 |
+
# cv2.putText(image, "Neutral", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv2.LINE_AA)
|
| 1136 |
+
# counter[7] += 1
|
| 1137 |
+
del results
|
| 1138 |
+
end_time = time.time()
|
| 1139 |
+
timer_count = end_time - start_time
|
| 1140 |
+
if((int(timer_count/60) > our_time and not nervous) or (int(timer_count) <= 60 and TOTAL_BLINKS >= 15)):
|
| 1141 |
+
our_time = int(timer_count/60)
|
| 1142 |
+
print("Sunny")
|
| 1143 |
+
if(TOTAL_BLINKS >= 15):
|
| 1144 |
+
print("Arsooo")
|
| 1145 |
+
nervous = True
|
| 1146 |
+
variables.nerv_val = TOTAL_BLINKS
|
| 1147 |
+
variables.nerv_bool = True
|
| 1148 |
+
|
| 1149 |
+
pos_val = f"""
|
| 1150 |
+
Disagree with Spoken Word: {(counter[0]/full_counter * 100)}%\n
|
| 1151 |
+
Wants Her Knowledge to be Recognized Now: {(counter[8]/full_counter * 100)}%\n
|
| 1152 |
+
Reobserve feeling Uncomfortable: {(counter[1]/full_counter * 100)}%\n
|
| 1153 |
+
Positive Evaluation Low Risk Situation: {(counter[9]/full_counter * 100)}%\n
|
| 1154 |
+
Annoyed: {(counter[2]/full_counter * 100)}%\n
|
| 1155 |
+
Disagree what was heard: {(counter[3]/full_counter * 100)}%\n
|
| 1156 |
+
Disbelief: {(counter[4]/full_counter * 100)}%\n
|
| 1157 |
+
Untruthful: {(counter[5]/full_counter * 100)}%\n
|
| 1158 |
+
Embarrased Got Caught: {(counter[6]/full_counter * 100)}%\n
|
| 1159 |
+
Doesn't want to see, Eye Block: {(counter[11]/full_counter * 100)}%\n
|
| 1160 |
+
Person Recalling Something: {(counter[17]/full_counter * 100)}%\n
|
| 1161 |
+
Approval: {(counter[16]/full_counter * 100)}%\n
|
| 1162 |
+
Anger, Dislike, Skeptical: {(counter[18]/full_counter * 100)}%\n
|
| 1163 |
+
Hostility, Skeptical: {(counter[19]/full_counter * 100)}%\n
|
| 1164 |
+
Neutral: {(counter[7]/full_counter * 100)}%\n
|
| 1165 |
+
"""
|
| 1166 |
+
self.reporter = True
|
| 1167 |
+
variables.my_variable += 10
|
| 1168 |
+
variables.my_report = pos_val
|
| 1169 |
+
|
| 1170 |
+
return av.VideoFrame.from_ndarray(image, format='bgr24')
|
| 1171 |
+
|
| 1172 |
+
ctx = webrtc_streamer(key="key",
|
| 1173 |
+
video_processor_factory=VideoProcessor,
|
| 1174 |
+
rtc_configuration={
|
| 1175 |
+
"iceServers": get_ice_servers(),
|
| 1176 |
+
"iceTransportPolicy": "relay",
|
| 1177 |
+
},
|
| 1178 |
+
media_stream_constraints={"video": True, "audio": False},
|
| 1179 |
+
# async_processing=True
|
| 1180 |
+
)
|
| 1181 |
+
|
| 1182 |
+
if(ctx.video_transformer):
|
| 1183 |
+
variables.my_variable = 10
|
| 1184 |
+
variables.my_report = ""
|
| 1185 |
+
variables.nerv_bool = False
|
| 1186 |
+
variables.nerv_val = 0
|
| 1187 |
+
elif(not ctx.video_transformer and variables.my_variable > 10):
|
| 1188 |
+
# print(variables.my_report)
|
| 1189 |
+
if(variables.nerv_bool):
|
| 1190 |
+
variables.my_report += f"Person was Nervous and Blinked {variables.nerv_val} times in 1 Minute"
|
| 1191 |
+
st.write(variables.my_report)
|
| 1192 |
+
variables.my_variable = 10
|
| 1193 |
+
variables.my_report = ""
|
| 1194 |
+
variables.nerv_bool = False
|
| 1195 |
+
variables.nerv_val = 0
|
| 1196 |
+
# del frames_list
|
| 1197 |
+
else:
|
| 1198 |
+
variables.my_variable = 10
|
| 1199 |
+
variables.my_report = ""
|
| 1200 |
+
variables.nerv_bool = False
|
| 1201 |
+
variables.nerv_val = 0
|
| 1202 |
+
st.write(variables.my_report)
|
| 1203 |
+
# del frames_list
|