andy-phung

Untitled

Feb 13th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.00 KB | None | 0 0
  1. import sys
  2. import numpy as np
  3. import cv2
  4. from imutils import face_utils
  5. import imutils
  6. import dlib
  7. import PySimpleGUI as sg
  8. import gspread
  9. from oauth2client.service_account import ServiceAccountCredentials
  10. import time
  11. import pandas as pd
  12. import ast
  13. import random
  14. import tensorflow as tf
  15. from tensorflow import keras
  16. from tensorflow.keras import layers
  17. import tensorflow_datasets as tfds
  18. from statsmodels.tsa.arima_model import ARIMA
  19. import datetime
  20. import matplotlib.pyplot as plt
  21. import matplotlib
  22. import pyimgur
  23. import os
  24.  
  25. data_list = []
  26.  
  27. scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  28. creds = ServiceAccountCredentials.from_json_keyfile_name('Resync-12a9f4471898.json', scope)
  29. client = gspread.authorize(creds)
  30. sheet = client.open("Daily Resync Survey Results").sheet1
  31.  
  32. sg.theme('LightPurple') # Add a touch of color
  33. # All the stuff inside your window.
  34. layout = [[ sg.Column([[sg.Text('On a scale of 1-4, how effective do you believe Resync is in reducing your symptoms right now?'), sg.InputText()],
  35. [sg.Text('On a scale of 1-4, how helpful are the 2-week projections of your improvement?'), sg.InputText()],
  36. [sg.Text('On a scale of 1-4, how difficult is it to set up/use Resync?'), sg.InputText()],
  37. [sg.Text('1 (Not at all) to 4 (Strongly agree): I look forward to waking up every morning.'), sg.InputText()],
  38. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel cheerful and full of energy.'), sg.InputText()],
  39. [sg.Text('1 (Not at all) to 4 (Strongly agree): I find joy in the simple things of life.'), sg.InputText()],
  40. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am often in a good mood during these past two weeks.'), sg.InputText()],
  41. [sg.Text('1 (Not at all) to 4 (Strongly agree): I tend to work on things to my fullest.'), sg.InputText()],
  42. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am energized by my surroundings.'), sg.InputText()],
  43. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel happy talking to my loved ones.'), sg.InputText()],
  44. [sg.Text('1 (Not at all) to 4 (Strongly agree): I get motivated and excited easily.'), sg.InputText()],
  45. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel content with my current life.'), sg.InputText()],
  46. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am feeling happy these days.'), sg.InputText()],
  47. [sg.Text('1 (Not at all) to 4 (Strongly agree): I do not look forward to waking up every morning.'), sg.InputText()],
  48. [sg.Text('1 (Not at all) to 4 (Strongly agree): I cannot find joy in the simple things of life.'), sg.InputText()],
  49. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am often feeling sad these past two weeks.'), sg.InputText()],
  50. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often lack the energy to do simple things these past two weeks.'), sg.InputText()],
  51. [sg.Text('1 (Not at all) to 4 (Strongly agree): I have often lost motivation these past two weeks.'), sg.InputText()],
  52. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often put on a fake smile for others.'), sg.InputText()],
  53. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often put on a fake smile for myself.'), sg.InputText()],
  54. [sg.Text('1 (Not at all) to 4 (Strongly agree): Talking with others drains my energy.'), sg.InputText()],
  55. [sg.Text('1 (Not at all) to 4 (Strongly agree): I carry out my tasks to get by with my day and life, to only exist.'), sg.InputText()],
  56. [sg.Text('1 (Not at all) to 4 (Strongly agree): Everything feels numb and repetitive. '), sg.InputText()],
  57. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am often worried about the future. '), sg.InputText()],
  58. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel overwhelmed with my life.'), sg.InputText()],
  59. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often wake up in a cold sweat at night.'), sg.InputText()],
  60. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel nervous when talking with others.'), sg.InputText()],
  61. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often get this irrational sense of anxiety.'), sg.InputText()],
  62. [sg.Text('1 (Not at all) to 4 (Strongly agree): I tend to imagine the worst possible outcome.'), sg.InputText()],
  63. [sg.Text('1 (Not at all) to 4 (Strongly agree): I stop myself before I get my hopes up.'), sg.InputText()],
  64. [sg.Text('1 (Not at all) to 4 (Strongly agree): I feel anxious being in my environment.'), sg.InputText()],
  65. [sg.Text('1 (Not at all) to 4 (Strongly agree): I tend to stay away from others out of fear/rejection.'), sg.InputText()],
  66. [sg.Text('1 (Not at all) to 4 (Strongly agree): I think I often have bad luck/cause incidents.'), sg.InputText()],
  67. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often get angry.'), sg.InputText()],
  68. [sg.Text('1 (Not at all) to 4 (Strongly agree): I am often bothered by the little inconveniences.'), sg.InputText()],
  69. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often raise my voice towards others in an aggressive manner.'), sg.InputText()],
  70. [sg.Text('1 (Not at all) to 4 (Strongly agree): When angered, I cannot keep my emotions in check.'), sg.InputText()],
  71. [sg.Text('1 (Not at all) to 4 (Strongly agree): I have been feeling angered these past two weeks.'), sg.InputText()],
  72. [sg.Text('1 (Not at all) to 4 (Strongly agree): Other people have been telling me I have been aggressive/angry these past two weeks.'), sg.InputText()],
  73. [sg.Text('1 (Not at all) to 4 (Strongly agree): People often piss me off.'), sg.InputText()],
  74. [sg.Text('1 (Not at all) to 4 (Strongly agree): I can get very angry when thinking about negative thoughts/things that upset me.'), sg.InputText()],
  75. [sg.Text('1 (Not at all) to 4 (Strongly agree): I get angry when someone completely ignores me; e.g. thoughts, feelings, existence, etc. '), sg.InputText()],
  76. [sg.Text('1 (Not at all) to 4 (Strongly agree): I often imagine scenarios of getting revenge on a person that made me angry; e.g. through verbal and/or physical actions.'), sg.InputText()],
  77. [sg.Button('Ok'), sg.Button('Cancel')]], key='-COL1-', scrollable=True) ]]
  78.  
  79. # Create the Window
  80. window = sg.Window('Daily Resync Survey!', layout)
  81.  
  82. while True:
  83. event, values = window.read()
  84. if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
  85. break
  86. if event == 'Ok':
  87. response = [values[0], values[1], values[2]]
  88. row = 1
  89. while(sheet.cell(row, 1).value != ''): # originally sheet.cell(row, 1).value == ' '
  90. row += 1
  91. time.sleep(1)
  92. sheet.insert_row(response, row)
  93. break
  94.  
  95. window.close()
  96.  
  97.  
  98. def rect_to_bb(rect):
  99. # take a bounding predicted by dlib and convert it
  100. # to the format (x, y, w, h) as we would normally do
  101. # with OpenCV
  102. x = rect.left()
  103. y = rect.top()
  104. w = rect.right() - x
  105. h = rect.bottom() - y
  106. # return a tuple of (x, y, w, h)
  107. return (x, y, w, h)
  108.  
  109. def shape_to_np(shape, dtype="int"):
  110. # initialize the list of (x, y)-coordinates
  111. coords = np.zeros((68, 2), dtype=dtype)
  112. # loop over the 68 facial landmarks and convert them
  113. # to a 2-tuple of (x, y)-coordinates
  114. for i in range(0, 68):
  115. coords[i] = (shape.part(i).x, shape.part(i).y)
  116. # return the list of (x, y)-coordinates
  117. return coords
  118.  
  119. # initialize dlib's face detector (HOG-based) and then create
  120. # the facial landmark predictor
  121. detector = dlib.get_frontal_face_detector()
  122. predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
  123.  
  124. counter = 0
  125. iterations = 0
  126. already_calibrated = False
  127. cap = cv2.VideoCapture(0)
  128. while(True):
  129. # Capture frame-by-frame
  130. ret, frame = cap.read()
  131.  
  132. # Our operations on the frame come here
  133. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  134. image = gray
  135. rects = detector(gray, 1)
  136. # loop over the face detections
  137. for (i, rect) in enumerate(rects):
  138. # determine the facial landmarks for the face region, then
  139. # convert the facial landmark (x, y)-coordinates to a NumPy
  140. # array
  141. shape = predictor(gray, rect)
  142. shape = face_utils.shape_to_np(shape) # SHAPE IS A NUMPY ARRAY; YOU CAN SIMPLY INDEX TO GET THE COORDS THAT YOU NEED
  143. data = str(int(shape[20][1])) + ", " + str(int(shape[25][1])) + ", " + str(int(shape[38][1])) + ", " + str(int(shape[39][1])) + ", " + str(int(shape[41][1])) + ", " + str(int(shape[40][1])) + ", " + str(int(shape[43][1])) + ", " + str(int(shape[44][1])) + ", " + str(int(shape[47][1])) + ", " + str(int(shape[46][1])) + ", " + str(int(shape[49][1])) + ", " + str(int(shape[55][1])) + "\n"
  144. data_list.append(data)
  145. counter += 1
  146.  
  147. # convert dlib's rectangle to a OpenCV-style bounding box
  148. # [i.e., (x, y, w, h)], then draw the face bounding box
  149. (x, y, w, h) = face_utils.rect_to_bb(rect)
  150. cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
  151. # show the face number
  152. cv2.putText(image, "Face #{}".format(i + 1), (x - 10, y - 10),
  153. cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
  154. # loop over the (x, y)-coordinates for the facial landmarks
  155. # and draw them on the image
  156. for (x, y) in shape:
  157. cv2.circle(image, (x, y), 1, (0, 0, 255), -1)
  158. print(counter)
  159. if(counter > 120):
  160. scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  161. creds = ServiceAccountCredentials.from_json_keyfile_name('Resync-12a9f4471898.json', scope)
  162. client = gspread.authorize(creds)
  163. sheet = client.open("Resync Database").sheet1
  164.  
  165. # each element of s (containing the most relevant facial landmarks) is separated by 120 "ticks" (approximately 24 seconds in total) in the script
  166. s = data_list
  167. #s = ['98, 99, 141, 151, 157, 156, 137, 137, 151, 152, 282, 303\n', '251, 256, 278, 283, 286, 286, 279, 279, 285, 286, 357, 371\n', '251, 256, 279, 283, 286, 285, 279, 280, 284, 285, 357, 372\n', '250, 257, 278, 282, 285, 285, 279, 280, 285, 285, 357, 372\n', '251, 257, 279, 282, 285, 285, 280, 280, 284, 285, 356, 372\n', '251, 257, 280, 284, 287, 286, 279, 280, 285, 285, 357, 372\n', '250, 256, 279, 283, 287, 286, 279, 280, 285, 286, 357, 372\n', '251, 257, 278, 282, 285, 285, 278, 279, 284, 285, 357, 372\n', '251, 258, 278, 282, 285, 284, 280, 280, 285, 286, 357, 372\n', '250, 258, 276, 280, 283, 283, 279, 280, 284, 285, 357, 373\n', '252, 258, 280, 284, 287, 286, 281, 281, 286, 286, 358, 373\n', '251, 257, 279, 283, 286, 285, 279, 280, 285, 285, 357, 371\n', '254, 258, 281, 285, 288, 287, 281, 281, 286, 287, 357, 373\n', '253, 257, 281, 285, 288, 287, 280, 281, 285, 286, 357, 373\n', '252, 258, 280, 284, 287, 286, 280, 280, 285, 286, 358, 372\n', '254, 257, 280, 285, 288, 287, 280, 280, 286, 286, 358, 373\n', '253, 258, 280, 284, 287, 287, 280, 281, 286, 287, 358, 374\n', '252, 259, 279, 283, 286, 286, 280, 281, 286, 287, 358, 373\n', '252, 257, 278, 284, 286, 286, 279, 279, 286, 286, 358, 374\n', '250, 258, 279, 282, 286, 285, 280, 281, 285, 286, 358, 374\n', '255, 257, 281, 285, 289, 287, 281, 281, 286, 286, 358, 374\n']
  168. # convert all inner lists (string representation) in s to actual lists
  169.  
  170. s = [i.replace('\n', '') for i in s]
  171. s = [i.replace(',', '') for i in s]
  172. s = [i.split() for i in s]
  173. s = [[int(j) for j in i] for i in s]
  174.  
  175. if(not already_calibrated):
  176. calibration = True
  177. else:
  178. calibration = False
  179.  
  180. # preprocessing and feature extraction (max, min, peak-to-peak)
  181.  
  182. eyebrows = [[a[0] for a in s], [a[1] for a in s]]
  183. left_eye = [[a[2] for a in s], [a[3] for a in s], [a[4] for a in s], [a[5] for a in s]]
  184. right_eye = [[a[6] for a in s], [a[7] for a in s], [a[8] for a in s], [a[9] for a in s]]
  185. mouth_corners = [[a[10] for a in s], [a[11] for a in s]]
  186. # wait do you need to normalize the heights
  187.  
  188. # conversion to pandas dataframes
  189. eyebrows = [pd.DataFrame({"y": l}) for l in eyebrows]
  190. left_eye = [pd.DataFrame({"y": l}) for l in left_eye]
  191. right_eye = [pd.DataFrame({"y": l}) for l in right_eye]
  192. mouth_corners = [pd.DataFrame({"y": l}) for l in mouth_corners]
  193.  
  194. # max
  195. eyebrows_max = [df.max() for df in eyebrows]
  196. left_eye_max = [df.max() for df in left_eye]
  197. right_eye_max = [df.max() for df in right_eye]
  198. mouth_corners_max = [df.max() for df in mouth_corners]
  199.  
  200. # min
  201. eyebrows_min = [df.min() for df in eyebrows]
  202. left_eye_min = [df.min() for df in left_eye]
  203. right_eye_min = [df.min() for df in right_eye]
  204. mouth_corners_min = [df.min() for df in mouth_corners]
  205.  
  206. # peak-to-peak
  207. eyebrows_peak = [max_value - eyebrows_min[index] for index, max_value in enumerate(eyebrows_max)]
  208. left_eye_peak = [max_value - left_eye_min[index] for index, max_value in enumerate(left_eye_max)]
  209. right_eye_peak = [max_value - right_eye_min[index] for index, max_value in enumerate(right_eye_max)]
  210. mouth_corners_peak = [max_value - mouth_corners_min[index] for index, max_value in enumerate(mouth_corners_max)]
  211. print(int(mouth_corners_peak[0]))
  212. # machine/deep learning classifier trained with labels that the client generates from an emotion evaluation test;
  213. # the one-shot/few-shot learning part is just data augmentation and/or regularization
  214. batch_size = 1
  215. epochs = 150
  216. characteristic_dist = np.asarray([14.0, 35.0, 22.0, 20.0])
  217.  
  218. scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
  219. creds = ServiceAccountCredentials.from_json_keyfile_name('Resync-12a9f4471898.json', scope)
  220. client = gspread.authorize(creds)
  221. sheet = client.open("Resync Database").sheet1
  222. print(calibration)
  223. # model.fit() doesn't erase progress
  224. if(calibration):
  225. # format inputs: they'll just be all of the values in the dataframes generated above
  226. x = [int(eyebrows_max[0]), int(eyebrows_max[1]), int(left_eye_max[0]), int(left_eye_max[1]), int(left_eye_max[2]), int(left_eye_max[3]), int(right_eye_max[0]), int(right_eye_max[1]), int(right_eye_max[2]), int(right_eye_max[3]), int(left_eye_max[0]), int(left_eye_max[1]), int(left_eye_max[2]), int(mouth_corners_max[0]), int(mouth_corners_max[1])]
  227. x.extend([int(eyebrows_min[0]), int(eyebrows_min[1]), int(left_eye_min[0]), int(left_eye_min[1]), int(left_eye_min[2]), int(left_eye_min[3]), int(right_eye_min[0]), int(right_eye_min[1]), int(right_eye_min[2]), int(right_eye_min[3]), int(left_eye_min[0]), int(left_eye_min[1]), int(left_eye_min[2]), int(mouth_corners_min[0]), int(mouth_corners_min[1])])
  228. x.extend([int(eyebrows_peak[0]), int(eyebrows_peak[1]), int(left_eye_peak[0]), int(left_eye_peak[1]), int(left_eye_peak[2]), int(left_eye_peak[3]), int(right_eye_peak[0]), int(right_eye_peak[1]), int(right_eye_peak[2]), int(right_eye_peak[3]), int(left_eye_peak[0]), int(left_eye_peak[1]), int(left_eye_peak[2]), int(mouth_corners_peak[0]), int(mouth_corners_peak[1])])
  229. x = np.asarray(x)
  230. X = np.asarray([x])
  231. values = list(values.values())
  232. values = [int(i) for i in values]
  233. y = [a_i - b_i for a_i, b_i in zip(characteristic_dist, [sum(values[3:13]), sum(values[13:23]), sum(values[23:33]), sum(values[33:43])])]
  234. idx = y.index(max(y))
  235. y = [0.0]*4
  236. y[idx] = 1.0
  237. y = np.asarray(y)
  238. Y = np.asarray([y])
  239. # load the model from last time (h5) (the model should be defined elsewhere, saved as an h5, and put in the same directory)
  240. model = keras.models.load_model("resync.h5")
  241. model.fit(X, Y, batch_size=batch_size, epochs=epochs)
  242. model.save("resync.h5")
  243. already_calibrated = True
  244. counter = 0
  245. else:
  246. current_time = datetime.datetime.now()
  247. # format inputs: they'll just be all of the values in the dataframes generated above
  248. x = [int(eyebrows_max[0]), int(eyebrows_max[1]), int(left_eye_max[0]), int(left_eye_max[1]), int(left_eye_max[2]), int(left_eye_max[3]), int(right_eye_max[0]), int(right_eye_max[1]), int(right_eye_max[2]), int(right_eye_max[3]), int(left_eye_max[0]), int(left_eye_max[1]), int(left_eye_max[2]), int(mouth_corners_max[0]), int(mouth_corners_max[1])]
  249. x.extend([int(eyebrows_min[0]), int(eyebrows_min[1]), int(left_eye_min[0]), int(left_eye_min[1]), int(left_eye_min[2]), int(left_eye_min[3]), int(right_eye_min[0]), int(right_eye_min[1]), int(right_eye_min[2]), int(right_eye_min[3]), int(left_eye_min[0]), int(left_eye_min[1]), int(left_eye_min[2]), int(mouth_corners_min[0]), int(mouth_corners_min[1])])
  250. x.extend([int(eyebrows_peak[0]), int(eyebrows_peak[1]), int(left_eye_peak[0]), int(left_eye_peak[1]), int(left_eye_peak[2]), int(left_eye_peak[3]), int(right_eye_peak[0]), int(right_eye_peak[1]), int(right_eye_peak[2]), int(right_eye_peak[3]), int(left_eye_peak[0]), int(left_eye_peak[1]), int(left_eye_peak[2]), int(mouth_corners_peak[0]), int(mouth_corners_peak[1])])
  251. x = np.asarray(x)
  252. X = np.asarray([x])
  253. # load the model from last time (h5) (the model should be defined elsewhere, saved as an h5, and put in the same directory)
  254. model = keras.models.load_model("resync.h5")
  255.  
  256. # REAL-TIME METRICS
  257. preds = model.predict(X)
  258. general_metric = np.average((characteristic_dist - preds[0])) # this is the other
  259. um_preds = preds.copy()
  260. preds = str(preds)
  261. general_metric = str(general_metric)
  262. preds = preds.replace("[[", "")
  263. preds = preds.replace("]]", "")
  264. #print(preds) # wait isn't this just the output of softmax
  265. #print(general_metric) # wait what does this actually indicate
  266.  
  267. # GRAPHS
  268. # doesn't have to be restricted to the past two weeks
  269. # host on imgur or smth
  270.  
  271. row = int(sheet.cell(1, 7).value)
  272. general_metrics = []
  273. predictions = []
  274. timestamps = []
  275. for idx in range(2, row):
  276. general_metrics.append(float(list(sheet.row_values(idx))[1]))
  277. timestamps.append(list(sheet.row_values(idx))[0])
  278. general_metrics = pd.Series(general_metrics)
  279. timestamps = pd.Series(timestamps)
  280. table = {"General Metric" : general_metrics, "Time" : timestamps}
  281. data = pd.DataFrame(table)
  282.  
  283. fig, ax = plt.subplots()
  284. fig.autofmt_xdate()
  285. plt.gcf().subplots_adjust(bottom=0.35, left = 0.35)
  286. plt.plot_date([i for i in list(timestamps) if i != "Time"], [i for i in list(general_metrics) if i != "General Severity Metric"], xdate=True)
  287. plt.close(fig)
  288. cwd = os.getcwd()
  289. fig.savefig(cwd + '\\' + str(timestamps[0]).replace("-", "").replace(":","") + ".png") # temp path
  290.  
  291. CLIENT_ID = "9d912e738dfe437" # client_secret: 81d5d9435ad9a6ebf6c76bdc1149d171a7321ae0
  292. im = pyimgur.Imgur(CLIENT_ID)
  293. uploaded_image = im.upload_image(cwd + '\\' + str(timestamps[0]).replace("-", "").replace(":","") + ".png", title="Uploaded with PyImgur")
  294. link = uploaded_image.link
  295. #print(link)
  296.  
  297. # LONG-TERM METRICS
  298. arima_model = ARIMA(data["General Metric"], order=(1,1,0))
  299. arima_model_fit = arima_model.fit(disp=1)
  300. fig = arima_model_fit.plot_predict(1, 100)
  301. plt.close(fig)
  302. fig.savefig(cwd + '\\' + str(timestamps[0]).replace("-", "").replace(":","") + ".png") # temp path
  303. im = pyimgur.Imgur(CLIENT_ID)
  304. uploaded_image = im.upload_image(cwd + '\\' + str(timestamps[0]).replace("-", "").replace(":","") + ".png", title="Uploaded with PyImgur")
  305. link2 = uploaded_image.link
  306. #print(link2)
  307.  
  308.  
  309. # BIOFEEDBACK DATA
  310. characteristic_dist = characteristic_dist.astype('float32')
  311. um_preds[0] = um_preds[0].astype('float32')
  312. elementwise_diff = np.subtract(characteristic_dist, um_preds[0])
  313. links = {
  314. 0 : 'https://open.spotify.com/user/macaronlover8/playlist/7Bcu7I60Ir0jQ6IjXMZflc?si=DgITEw72RsKPncUOkAZyfw',
  315. 1 : 'https://open.spotify.com/user/macaronlover8/playlist/7Bcu7I60Ir0jQ6IjXMZflc?si=DgITEw72RsKPncUOkAZyfw',
  316. 2 : 'https://open.spotify.com/user/macaronlover8/playlist/7Bcu7I60Ir0jQ6IjXMZflc?si=DgITEw72RsKPncUOkAZyfw',
  317. 3 : 'https://open.spotify.com/user/macaronlover8/playlist/7Bcu7I60Ir0jQ6IjXMZflc?si=DgITEw72RsKPncUOkAZyfw'
  318. }
  319. biofeedback_data = links[np.argmax(elementwise_diff)] # placeholder
  320. #print(biofeedback_data)
  321.  
  322. # DATABASE
  323. # -> rt metrics, long-term metrics/graphs, history graphs, music biofeedback data
  324. payload = [str(current_time), general_metric, preds, link2, link, biofeedback_data]
  325. sheet.insert_row(payload, row)
  326. sheet.update_cell(1, 7, int(sheet.cell(1, 7).value) + 1)
  327. counter = 0
  328.  
  329. #cv2.imshow("Output", image)
  330.  
  331. if cv2.waitKey(1) & 0xFF == ord('q'):
  332. break
  333.  
  334.  
  335. # When everything done, release the capture
  336. cap.release()
  337. cv2.destroyAllWindows()
  338.  
  339. # dlib facial landmarks used for this: [20, 25] (eyebrows), [38, 39, 41, 40] (left eye), [43, 44, 47, 46] (right eye), [49, 55] (corners of mouth)
  340. #^you'll just get the vertical height of those
  341. # command to run this script in the nedc-2021-webcam folder is "python main.py --shape-predictor shape_predictor_68_face_landmarks.dat"
  342. # <class '_dlib_pybind11.shape_predictor'>
  343.  
  344. # added simple survey with pysimplegui that outputs to a google spreadsheet: https://docs.google.com/spreadsheets/d/12HRJZJdJlNRn8BM2s3bJbABpVg9C8Q9D2ETvXjnl1cg/edit#gid=0
  345.  
Advertisement
Add Comment
Please, Sign In to add comment